public MarkdownEditorViewModel(WorkspaceItemViewModel item) : base(item) { var theme = Theme.Get("Markdown"); folding = new MarkdownFoldingStrategy(); colorizer = new MarkdownHighlightingColorizer(theme); blockRenderer = new BlockBackgroundRenderer(theme); issueRenderer = new IssueBackgroundRenderer(theme); }
/// <remarks> /// Loads a file from the specified stream. /// </remarks> /// <param name="fileName">The name of the file to open. Used to find the correct highlighting strategy /// if autoLoadHighlighting is active, and sets the filename property to this value.</param> /// <param name="stream">The stream to actually load the file content from.</param> /// <param name="autoLoadHighlighting">Automatically load the highlighting for the file</param> /// <param name="autodetectEncoding">Automatically detect file encoding and set Encoding property to the detected encoding.</param> public void LoadFile(string fileName, Stream stream, bool autoLoadHighlighting, bool autodetectEncoding) { BeginUpdate(); _document.TextContent = string.Empty; _document.UndoStack.ClearAll(); _document.BookmarkManager.Clear(); if (autoLoadHighlighting) { try { _document.HighlightingStrategy = HighlightingManager.Instance.FindHighlighterForFile(fileName); // TODOsyntax this doesn't belong here. I did it because it needed a file/home. IFoldingStrategy fs = null; if (_document.HighlightingStrategy != null) { switch (_document.HighlightingStrategy.Folding) { case "Code": fs = new CodeFoldingStrategy(); break; case "CSharp": fs = new CSharpFoldingStrategy(); break; case "Markdown": fs = new MarkdownFoldingStrategy(); break; case "Xml": fs = new XmlFoldingStrategy(); break; } } _document.FoldingManager.FoldingStrategy = fs; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (autodetectEncoding) { Encoding encoding = Encoding; Document.TextContent = Util.FileReader.ReadFileContent(stream, encoding); Encoding = encoding; } else { using (StreamReader reader = new StreamReader(fileName, Encoding)) { string s = reader.ReadToEnd(); Document.TextContent = s; // TODO2*** 50Mb takes 6 seconds... } } FileName = fileName; Document.UpdateQueue.Clear(); EndUpdate(); OptionsChanged(); Refresh(); }