private void DocumentEditor_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { if (FileChanged == false) { FileChanged = true; } Semagsoft.HyperlinkHelper helper = new Semagsoft.HyperlinkHelper(); helper.SubscribeToAllHyperlinks(Document); WordCount = GetWordCount(); }
public void LoadDocument(string filename) { System.IO.FileInfo f = new System.IO.FileInfo(filename); TextRange tr = new TextRange(Document.ContentStart, Document.ContentEnd); System.IO.FileStream fs = null; bool isreadonlyfile = false; if (f.IsReadOnly) { isreadonlyfile = true; } if (f.Extension.ToLower() == ".xamlpackage") { TextRange t = new TextRange(Document.ContentStart, Document.ContentEnd); System.IO.FileStream file = new System.IO.FileStream(filename, System.IO.FileMode.Open); t.Load(file, System.Windows.DataFormats.XamlPackage); file.Close(); } else if (f.Extension.ToLower() == ".xaml") { fs = System.IO.File.Open(f.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); FlowDocument content = System.Windows.Markup.XamlReader.Load(fs) as FlowDocument; Thickness thi = content.PagePadding; try { int leftmargin = thi.Left; int topmargin = thi.Top; int rightmargin = thi.Right; int bottommargin = thi.Bottom; SetPageMargins(new Thickness(leftmargin, topmargin, rightmargin, bottommargin)); } catch (Exception ex) { SetPageMargins(new Thickness(0, 0, 0, 0)); } Document = content; } else if (f.Extension.ToLower() == ".docx") { OpenXMLtoFlowDocument converter = new OpenXMLtoFlowDocument(f.FullName); FlowDocument content = converter.Convert(); Document = content; converter.Close(); //ElseIf f.Extension.ToLower = ".odt" Then // fs.Close() // fs = Nothing // Dim converter As New OpenDocumenttoFlowDocument // Document = converter.Convert(f.FullName) } else if (f.Extension.ToLower() == ".html" || f.Extension.ToLower() == ".htm") { try { FlowDocument content = System.Windows.Markup.XamlReader.Parse(HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(Document.Editor.My.Computer.FileSystem.ReadAllText(filename), true)) as FlowDocument; Document = content; } catch (Exception ex) { MessageBoxDialog m = new MessageBoxDialog("Error loading html document", "Error", null, null); m.MessageImage.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Common/error32.png")); m.Owner = Document.Editor.My.Windows.MainWindow; m.ShowDialog(); } } else if (f.Extension.ToLower() == ".rtf") { if (isreadonlyfile) { fs = System.IO.File.Open(f.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); } else { fs = System.IO.File.Open(f.FullName, System.IO.FileMode.Open); } tr.Load(fs, System.Windows.DataFormats.Rtf); } else { if (isreadonlyfile) { fs = System.IO.File.Open(f.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); } else { fs = System.IO.File.Open(f.FullName, System.IO.FileMode.Open); } tr.Load(fs, System.Windows.DataFormats.Text); } if (fs != null) { fs.Close(); fs = null; } if (f.IsReadOnly) { IsReadOnly = true; } DocumentName = filename; Semagsoft.HyperlinkHelper helper = new Semagsoft.HyperlinkHelper(); helper.SubscribeToAllHyperlinks(Document); //Dim helper2 As New Semagsoft.ImageHelper //helper2.AddImageResizers(Me) //p.SetDocumentTitle(f.Name) FileChanged = false; }