From 0e8b990fce70b2dd2ccbf0533c5bae32c5cdd90d Mon Sep 17 00:00:00 2001 From: Sandy Armstrong Date: Wed, 17 Sep 2014 11:03:00 -0700 Subject: [PATCH] [SourceEditor2] Allow subclasses to modify loaded/saved text Hypothetically, a subclass of SourceEditorView might want to store metadata in a hidden header area of the file. Overriding ProcessLoadText gives the subclass an opportunity to extract said metadata, and ensure that the text loaded into the Document excludes it. Similarly, ProcessSaveText would allow this subclass to inject updated metadata into the file text just before the write occurs. --- .../MonoDevelop.SourceEditor/SourceEditorView.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs index d301d929f53..3990a458e31 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs @@ -614,6 +614,11 @@ void DisposeErrorMarkers () messageBubbleCache = null; } } + + protected virtual string ProcessSaveText (string text) + { + return text; + } public override void Save (string fileName) { @@ -694,7 +699,7 @@ public void Save (string fileName, Encoding encoding) try { var writeEncoding = encoding; var writeBom = hadBom; - var writeText = Document.Text; + var writeText = ProcessSaveText (Document.Text); if (writeEncoding == null) { if (this.encoding != null) { writeEncoding = this.encoding; @@ -821,6 +826,11 @@ void IEncodedTextContent.Load (string fileName, Encoding loadEncoding) Load (fileName, loadEncoding); } + protected virtual string ProcessLoadText (string text) + { + return text; + } + public void Load (string fileName, Encoding loadEncoding, bool reload = false) { // Handle the "reload" case. @@ -848,6 +858,7 @@ public void Load (string fileName, Encoding loadEncoding, bool reload = false) encoding = loadEncoding; text = TextFileUtility.ReadAllText (fileName, loadEncoding, out hadBom); } + text = ProcessLoadText (text); if (reload) { Document.Replace (0, Document.TextLength, text); Document.DiffTracker.Reset ();