diff options
author | David Karlaš <david.karlas@xamarin.com> | 2015-07-08 22:51:47 +0300 |
---|---|---|
committer | David Karlaš <david.karlas@xamarin.com> | 2015-07-08 22:51:47 +0300 |
commit | 59e14b9ecfdbf635d62f5f36f9f6dace35bcd1e3 (patch) | |
tree | 97cb7cf01458cac63d0fa6910ba61a4fdc61d585 /main/src/addins/MonoDevelop.SourceEditor2 | |
parent | ee5a1947e5b0abcc1d4f215bb2a71793aa439648 (diff) |
Bug 30103 - Formatting doesn't trigger on save for xaml or xml files
Diffstat (limited to 'main/src/addins/MonoDevelop.SourceEditor2')
-rw-r--r-- | main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs index 7855e35f00..5cfd2f7cb7 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorView.cs @@ -55,7 +55,8 @@ using System.Text; using Mono.Addins; using MonoDevelop.Components; using Mono.TextEditor.Utils; - +using MonoDevelop.Projects.Policies;
+
namespace MonoDevelop.SourceEditor { public class SourceEditorView : AbstractViewContent, IExtensibleTextEditor, IBookmarkBuffer, IClipboardHandler, @@ -656,10 +657,20 @@ namespace MonoDevelop.SourceEditor if (PropertyService.Get ("AutoFormatDocumentOnSave", false)) { try { var formatter = CodeFormatterService.GetFormatter (Document.MimeType); - if (formatter != null && formatter.SupportsOnTheFlyFormatting) { - using (var undo = TextEditor.OpenUndoGroup ()) { - formatter.OnTheFlyFormat (WorkbenchWindow.Document, 0, Document.TextLength); - wasEdited = false; + if (formatter != null) { + var document = WorkbenchWindow.Document; + if (formatter.SupportsOnTheFlyFormatting) { + using (var undo = TextEditor.OpenUndoGroup ()) { + formatter.OnTheFlyFormat (document, 0, Document.TextLength); + wasEdited = false; + } + } else { + var text = document.Editor.Text; + var policies = document.Project != null ? document.Project.Policies : PolicyService.DefaultPolicies; + string formattedText = formatter.FormatText (policies, text); + if (formattedText != null && formattedText != text) { + document.Editor.Replace (0, text.Length, formattedText); + } } } } catch (Exception e) { |