~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeFormatting/CodeFormattingCommands.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
                        if (formatter == null)
61
61
                                return;
62
62
                        using (var undo = doc.Editor.OpenUndoGroup ()) {
63
 
                                var loc = doc.Editor.Caret.Location;
64
 
                                var text = formatter.FormatText (doc.Project != null ? doc.Project.Policies : null, doc.Editor.Text);
65
 
                                if (text != null) {
66
 
                                        doc.Editor.Replace (0, doc.Editor.Length, text);
67
 
                                        doc.Editor.Caret.Location = loc;
68
 
                                }
 
63
                                formatter.OnTheFlyFormat (doc, 0, doc.Editor.Length);
69
64
                        }
70
65
                }
71
66
        }
78
73
                                string mt = DesktopService.GetMimeTypeForUri (IdeApp.Workbench.ActiveDocument.FileName);
79
74
                                var formatter = CodeFormatterService.GetFormatter (mt);
80
75
                                if (formatter != null && !formatter.IsDefault) {
81
 
                                        info.Enabled = IdeApp.Workbench.ActiveDocument.Editor.IsSomethingSelected;
 
76
                                        info.Enabled = true;
82
77
                                        return;
83
78
                                }
84
79
                        }
92
87
                                return;
93
88
                        string mt = DesktopService.GetMimeTypeForUri (doc.FileName);
94
89
                        var formatter = CodeFormatterService.GetFormatter (mt);
95
 
                        if (formatter == null || !doc.Editor.IsSomethingSelected)
 
90
                        if (formatter == null)
96
91
                                return;
97
 
                        var selection = doc.Editor.SelectionRange;
 
92
                        Mono.TextEditor.TextSegment selection;
 
93
                        var editor = doc.Editor;
 
94
                        if (editor.IsSomethingSelected) {
 
95
                                selection = editor.SelectionRange;
 
96
                        } else {
 
97
                                selection = editor.GetLine (editor.Caret.Line).Segment;
 
98
                        }
98
99
                        
99
 
                        using (var undo = doc.Editor.OpenUndoGroup ()) {
100
 
                                var version = doc.Editor.Version;
 
100
                        using (var undo = editor.OpenUndoGroup ()) {
 
101
                                var version = editor.Version;
101
102
 
102
103
                                if (formatter.SupportsOnTheFlyFormatting) {
103
104
                                        formatter.OnTheFlyFormat (doc, selection.Offset, selection.EndOffset);
104
105
                                } else {
105
106
                                        var pol = doc.Project != null ? doc.Project.Policies : null;
106
 
                                        string text = formatter.FormatText (pol, doc.Editor.Text, selection.Offset, selection.EndOffset);
 
107
                                        string text = formatter.FormatText (pol, editor.Text, selection.Offset, selection.EndOffset);
107
108
                                        if (text != null) {
108
 
                                                doc.Editor.Replace (selection.Offset, selection.Length, text);
 
109
                                                editor.Replace (selection.Offset, selection.Length, text);
109
110
                                        }
110
111
                                }
111
112
 
112
 
                                int newOffset = version.MoveOffsetTo (doc.Editor.Version, selection.Offset);
113
 
                                int newEndOffset = version.MoveOffsetTo (doc.Editor.Version, selection.EndOffset);
114
 
                                
115
 
                                doc.Editor.SetSelection (newOffset, newEndOffset);
116
 
 
 
113
                                if (editor.IsSomethingSelected) { 
 
114
                                        int newOffset = version.MoveOffsetTo (editor.Version, selection.Offset);
 
115
                                        int newEndOffset = version.MoveOffsetTo (editor.Version, selection.EndOffset);
 
116
                                        editor.SetSelection (newOffset, newEndOffset);
 
117
                                }
117
118
                        }
118
119
                }
119
120
        }