protected virtual void OnReloadHighlighting(object sender, EventArgs e) { if (this.Document.HighlightingStrategy != null) { try { this.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(this.Document.HighlightingStrategy.Name); } catch (HighlightingDefinitionInvalidException highlightingDefinitionInvalidException1) { HighlightingDefinitionInvalidException highlightingDefinitionInvalidException = highlightingDefinitionInvalidException1; MessageBox.Show(highlightingDefinitionInvalidException.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } this.OptionsChanged(); } }
public void LoadFile(string fileName, Stream stream, bool autoLoadHighlighting, bool autodetectEncoding) { if (stream == null) { throw new ArgumentNullException("stream"); } this.BeginUpdate(); this.document.TextContent = string.Empty; this.document.UndoStack.ClearAll(); this.document.BookmarkManager.Clear(); if (autoLoadHighlighting) { try { this.document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(fileName); } catch (HighlightingDefinitionInvalidException highlightingDefinitionInvalidException1) { HighlightingDefinitionInvalidException highlightingDefinitionInvalidException = highlightingDefinitionInvalidException1; MessageBox.Show(highlightingDefinitionInvalidException.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } if (!autodetectEncoding) { using (StreamReader streamReader = new StreamReader(fileName, this.Encoding)) { this.Document.TextContent = streamReader.ReadToEnd(); } } else { System.Text.Encoding encoding = this.Encoding; this.Document.TextContent = FileReader.ReadFileContent(stream, ref encoding); this.Encoding = encoding; } this.FileName = fileName; this.Document.UpdateQueue.Clear(); this.EndUpdate(); this.OptionsChanged(); this.Refresh(); }