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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/ExtensibleTextEditor.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:
54
54
                
55
55
                SourceEditorView view;
56
56
                ExtensionContext extensionContext;
 
57
                Adjustment cachedHAdjustment, cachedVAdjustment;
57
58
                
58
59
                public ITextEditorExtension Extension {
59
60
                        get;
94
95
                        
95
96
                        Document.TextReplaced += HandleSkipCharsOnReplace;
96
97
                        
97
 
                        Document.TextReplaced += delegate(object sender, DocumentChangeEventArgs args) {
98
 
                                if (Extension != null) {
99
 
                                        try {
100
 
                                                Extension.TextChanged (args.Offset, args.Offset + Math.Max (args.RemovalLength, args.InsertionLength));
101
 
                                        } catch (Exception ex) {
102
 
                                                ReportExtensionError (ex);
103
 
                                        }
104
 
                                }
105
 
                        };
106
 
                        
107
98
                        UpdateEditMode ();
108
99
                        this.DoPopupMenu = ShowPopup;
109
100
                }
168
159
                        }
169
160
                }
170
161
 
 
162
                void UnregisterAdjustments ()
 
163
                {
 
164
                        if (cachedHAdjustment != null)
 
165
                                cachedHAdjustment.ValueChanged -= HAdjustment_ValueChanged;
 
166
                        if (cachedVAdjustment != null)
 
167
                                cachedVAdjustment.ValueChanged -= VAdjustment_ValueChanged;
 
168
                        cachedHAdjustment = null;
 
169
                        cachedVAdjustment = null;
 
170
                }
 
171
 
171
172
                protected override void OnDestroyed ()
172
173
                {
 
174
                        UnregisterAdjustments ();
 
175
 
173
176
                        ExtensionContext = null;
174
177
                        view = null;
175
178
                        base.OnDestroyed ();
181
184
                
182
185
                void OnTooltipProviderChanged (object s, ExtensionNodeEventArgs a)
183
186
                {
184
 
                        ITooltipProvider provider;
 
187
                        TooltipProvider provider;
185
188
                        try {
186
 
                                provider = (ITooltipProvider) a.ExtensionObject;
 
189
                                provider = (TooltipProvider) a.ExtensionObject;
187
190
                        } catch (Exception e) {
188
191
                                LoggingService.LogError ("Can't create tooltip provider:"+ a.ExtensionNode, e);
189
192
                                return;
202
205
                
203
206
                protected override void OptionsChanged (object sender, EventArgs args)
204
207
                {
205
 
                        if (view.Control != null) {
 
208
                        if (view != null && view.Control != null) {
206
209
                                if (!Options.ShowFoldMargin)
207
210
                                        this.Document.ClearFoldSegments ();
208
211
                        }
232
235
                
233
236
                bool ExtensionKeyPress (Gdk.Key key, uint ch, Gdk.ModifierType state)
234
237
                {
 
238
                        isInKeyStroke = true;
235
239
                        try {
236
240
                                return Extension.KeyPress (key, (char)ch, state);
237
241
                        } catch (Exception ex) {
238
242
                                ReportExtensionError (ex);
 
243
                        } finally {
 
244
                                isInKeyStroke = false;
239
245
                        }
240
246
                        return false;
241
247
                }
363
369
                        char insertionChar = '\0';
364
370
                        bool insertMatchingBracket = false;
365
371
                        IDisposable undoGroup = null;
366
 
                        if (skipChar == null && Options.AutoInsertMatchingBracket && braceIndex >= 0) {
 
372
                        if (skipChar == null && Options.AutoInsertMatchingBracket && braceIndex >= 0 && !IsSomethingSelected) {
367
373
                                if (!inStringOrComment) {
368
374
                                        char closingBrace = closingBrackets [braceIndex];
369
375
                                        char openingBrace = openBrackets [braceIndex];
394
400
                        if (insertMatchingBracket)
395
401
                                undoGroup = Document.OpenUndoGroup ();
396
402
 
 
403
                        var oldMode = Caret.IsInInsertMode;
397
404
                        if (skipChar != null) {
398
 
                                Caret.Offset++;
 
405
                                Caret.IsInInsertMode = false;
399
406
                                skipChars.Remove (skipChar);
400
 
                        } else {
401
 
                                if (Extension != null) {
402
 
                                        if (ExtensionKeyPress (key, ch, state)) 
403
 
                                                result = base.OnIMProcessedKeyPressEvent (key, ch, state);
404
 
                                        if (returnBetweenBraces)
405
 
                                                HitReturn ();
406
 
                                } else {
 
407
                        }
 
408
                        if (Extension != null) {
 
409
                                if (ExtensionKeyPress (key, ch, state)) 
407
410
                                        result = base.OnIMProcessedKeyPressEvent (key, ch, state);
408
 
                                        if (returnBetweenBraces)
409
 
                                                HitReturn ();
410
 
                                }
411
 
                        }
 
411
                                if (returnBetweenBraces)
 
412
                                        HitReturn ();
 
413
                        } else {
 
414
                                result = base.OnIMProcessedKeyPressEvent (key, ch, state);
 
415
                                if (returnBetweenBraces)
 
416
                                        HitReturn ();
 
417
                        }
 
418
                        if (skipChar != null) {
 
419
                                Caret.IsInInsertMode = oldMode;
 
420
                        }
 
421
 
412
422
                        if (insertMatchingBracket) {
413
423
                                GetTextEditorData ().EnsureCaretIsNotVirtual ();
414
424
                                int offset = Caret.Offset;
556
566
                
557
567
                void ShowPopup (Gdk.EventButton evt)
558
568
                {
559
 
                        // Fire event that will close an open outo complete window
560
569
                        view.FireCompletionContextChanged ();
 
570
                        CompletionWindowManager.HideWindow ();
 
571
                        ParameterInformationWindowManager.HideWindow (null, view);
561
572
                        HideTooltip ();
562
573
                        const string menuPath = "/MonoDevelop/SourceEditor2/ContextMenu/Editor";
563
574
                        var ctx = ExtensionContext ?? AddinManager.AddinEngine;
631
642
                                var result = template.InsertTemplateContents (document);
632
643
 
633
644
                                var links = result.TextLinks;
634
 
                                if (PropertyService.Get ("OnTheFlyFormatting", true)) {
635
 
                                        var prettyPrinter = CodeFormatterService.GetFormatter (Document.MimeType);
636
 
                                        if (prettyPrinter != null) {
637
 
                                                int endOffset = result.InsertPosition + result.Code.Length;
638
 
                                                //                                              string oldText = Document.GetTextAt (result.InsertPosition, result.Code.Length);
639
 
                                                //                                              var policies = document.Project != null ? document.Project.Policies : null;
640
 
                                                var oldVersion = Document.Version;
641
 
                                                prettyPrinter.OnTheFlyFormat (document, result.InsertPosition, endOffset);
642
 
                                                foreach (var textLink in links) {
643
 
                                                        for (int i = 0; i < textLink.Links.Count; i++) {
644
 
                                                                var segment = textLink.Links [i];
645
 
                                                                var translatedOffset = oldVersion.MoveOffsetTo (Document.Version, result.InsertPosition + segment.Offset) - result.InsertPosition;
646
 
                                                                textLink.Links [i] = new TextSegment (translatedOffset, segment.Length);
647
 
                                                        }
648
 
                                                }
649
 
                                        }
650
 
                                }
651
645
 
652
646
                                var tle = new TextLinkEditMode (this, result.InsertPosition, links);
 
647
                                tle.TextLinkMode = TextLinkMode.General;
653
648
                                if (tle.ShouldStartTextLinkMode) {
654
649
                                        tle.OldMode = CurrentMode;
655
650
                                        tle.StartMode ();
658
653
                        }
659
654
                }
660
655
 
661
 
                protected override void HAdjustmentValueChanged ()
662
 
                {
663
 
                        base.HAdjustmentValueChanged ();
 
656
                protected override void OnScrollAdjustmentsSet()
 
657
                {
 
658
                        UnregisterAdjustments ();
 
659
                        if (HAdjustment != null) {
 
660
                                cachedHAdjustment = HAdjustment;
 
661
                                HAdjustment.ValueChanged += HAdjustment_ValueChanged;
 
662
                        }
 
663
                        if (VAdjustment != null) {
 
664
                                cachedVAdjustment = VAdjustment;
 
665
                                VAdjustment.ValueChanged += VAdjustment_ValueChanged;
 
666
                        }
 
667
                }
 
668
 
 
669
                void VAdjustment_ValueChanged (object sender, EventArgs e)
 
670
                {
 
671
                        CompletionWindowManager.HideWindow ();
 
672
                        ParameterInformationWindowManager.HideWindow (null, view);
 
673
                }
 
674
 
 
675
                void HAdjustment_ValueChanged (object sender, EventArgs e)
 
676
                {
664
677
                        if (!isInKeyStroke) {
665
678
                                CompletionWindowManager.HideWindow ();
666
679
                                ParameterInformationWindowManager.HideWindow (null, view);
 
680
                        } else {
 
681
                                CompletionWindowManager.RepositionWindow ();
 
682
                                ParameterInformationWindowManager.RepositionWindow (null, view);
667
683
                        }
668
684
                }
669
685
                
670
 
                protected override void VAdjustmentValueChanged ()
671
 
                {
672
 
                        base.VAdjustmentValueChanged ();
673
 
                        CompletionWindowManager.HideWindow ();
674
 
                        ParameterInformationWindowManager.HideWindow (null, view);
675
 
                }
676
 
                
677
 
                
678
686
#endregion
679
687
                
680
688
#region Key bindings
983
991
                        StartCaretPulseAnimation ();
984
992
                }
985
993
                
986
 
                [CommandHandler (MonoDevelop.SourceEditor.SourceEditorCommands.ToggleCodeFocus)]
987
 
                internal void OnToggleCodeFocus ()
988
 
                {
989
 
                        foldMarkerMargin.IsInCodeFocusMode = !foldMarkerMargin.IsInCodeFocusMode;
990
 
                }
991
 
                
992
994
                [CommandHandler (MonoDevelop.Ide.Commands.TextEditorCommands.TransposeCharacters)]
993
995
                internal void TransposeCharacters ()
994
996
                {