Generalized plaintext-to-FlowDocument methods.

This commit is contained in:
morkt 2015-05-16 17:12:50 +04:00
parent 8cd51ae896
commit cb870c592a

View File

@ -40,7 +40,7 @@ namespace GARbro.GUI
public AboutBox()
{
InitializeComponent();
LicenseTabText.Document = GetLicenseDoc();
LicenseTabText.Document = GetResourceDoc ("GARbro.GUI.LICENSE");
}
private void Button_Click(object sender, RoutedEventArgs e)
@ -50,13 +50,22 @@ namespace GARbro.GUI
#region License text backend
static FlowDocument GetLicenseDoc ()
static FlowDocument GetResourceDoc (string resource)
{
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream ("GARbro.GUI.LICENSE"))
using (var stream = assembly.GetManifestResourceStream (resource))
{
if (null == stream)
return new FlowDocument();
return ReadPlainText (stream);
}
}
/// <summary>
/// Read plain text from stream and return it as FlowDocument.
/// </summary>
static FlowDocument ReadPlainText (Stream stream)
{
using (var reader = new StreamReader (stream))
{
var doc = new FlowDocument();
@ -85,7 +94,6 @@ namespace GARbro.GUI
return doc;
}
}
}
#endregion