95
96
Document.TextReplaced += HandleSkipCharsOnReplace;
97
Document.TextReplaced += delegate(object sender, DocumentChangeEventArgs args) {
98
if (Extension != null) {
100
Extension.TextChanged (args.Offset, args.Offset + Math.Max (args.RemovalLength, args.InsertionLength));
101
} catch (Exception ex) {
102
ReportExtensionError (ex);
107
98
UpdateEditMode ();
108
99
this.DoPopupMenu = ShowPopup;
162
void UnregisterAdjustments ()
164
if (cachedHAdjustment != null)
165
cachedHAdjustment.ValueChanged -= HAdjustment_ValueChanged;
166
if (cachedVAdjustment != null)
167
cachedVAdjustment.ValueChanged -= VAdjustment_ValueChanged;
168
cachedHAdjustment = null;
169
cachedVAdjustment = null;
171
172
protected override void OnDestroyed ()
174
UnregisterAdjustments ();
173
176
ExtensionContext = null;
175
178
base.OnDestroyed ();
182
185
void OnTooltipProviderChanged (object s, ExtensionNodeEventArgs a)
184
ITooltipProvider provider;
187
TooltipProvider provider;
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);
203
206
protected override void OptionsChanged (object sender, EventArgs args)
205
if (view.Control != null) {
208
if (view != null && view.Control != null) {
206
209
if (!Options.ShowFoldMargin)
207
210
this.Document.ClearFoldSegments ();
233
236
bool ExtensionKeyPress (Gdk.Key key, uint ch, Gdk.ModifierType state)
238
isInKeyStroke = true;
236
240
return Extension.KeyPress (key, (char)ch, state);
237
241
} catch (Exception ex) {
238
242
ReportExtensionError (ex);
244
isInKeyStroke = false;
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 ();
403
var oldMode = Caret.IsInInsertMode;
397
404
if (skipChar != null) {
405
Caret.IsInInsertMode = false;
399
406
skipChars.Remove (skipChar);
401
if (Extension != null) {
402
if (ExtensionKeyPress (key, ch, state))
403
result = base.OnIMProcessedKeyPressEvent (key, ch, state);
404
if (returnBetweenBraces)
408
if (Extension != null) {
409
if (ExtensionKeyPress (key, ch, state))
407
410
result = base.OnIMProcessedKeyPressEvent (key, ch, state);
408
if (returnBetweenBraces)
411
if (returnBetweenBraces)
414
result = base.OnIMProcessedKeyPressEvent (key, ch, state);
415
if (returnBetweenBraces)
418
if (skipChar != null) {
419
Caret.IsInInsertMode = oldMode;
412
422
if (insertMatchingBracket) {
413
423
GetTextEditorData ().EnsureCaretIsNotVirtual ();
414
424
int offset = Caret.Offset;
557
567
void ShowPopup (Gdk.EventButton evt)
559
// Fire event that will close an open outo complete window
560
569
view.FireCompletionContextChanged ();
570
CompletionWindowManager.HideWindow ();
571
ParameterInformationWindowManager.HideWindow (null, view);
562
573
const string menuPath = "/MonoDevelop/SourceEditor2/ContextMenu/Editor";
563
574
var ctx = ExtensionContext ?? AddinManager.AddinEngine;
631
642
var result = template.InsertTemplateContents (document);
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);
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 ();
661
protected override void HAdjustmentValueChanged ()
663
base.HAdjustmentValueChanged ();
656
protected override void OnScrollAdjustmentsSet()
658
UnregisterAdjustments ();
659
if (HAdjustment != null) {
660
cachedHAdjustment = HAdjustment;
661
HAdjustment.ValueChanged += HAdjustment_ValueChanged;
663
if (VAdjustment != null) {
664
cachedVAdjustment = VAdjustment;
665
VAdjustment.ValueChanged += VAdjustment_ValueChanged;
669
void VAdjustment_ValueChanged (object sender, EventArgs e)
671
CompletionWindowManager.HideWindow ();
672
ParameterInformationWindowManager.HideWindow (null, view);
675
void HAdjustment_ValueChanged (object sender, EventArgs e)
664
677
if (!isInKeyStroke) {
665
678
CompletionWindowManager.HideWindow ();
666
679
ParameterInformationWindowManager.HideWindow (null, view);
681
CompletionWindowManager.RepositionWindow ();
682
ParameterInformationWindowManager.RepositionWindow (null, view);
670
protected override void VAdjustmentValueChanged ()
672
base.VAdjustmentValueChanged ();
673
CompletionWindowManager.HideWindow ();
674
ParameterInformationWindowManager.HideWindow (null, view);
680
688
#region Key bindings
983
991
StartCaretPulseAnimation ();
986
[CommandHandler (MonoDevelop.SourceEditor.SourceEditorCommands.ToggleCodeFocus)]
987
internal void OnToggleCodeFocus ()
989
foldMarkerMargin.IsInCodeFocusMode = !foldMarkerMargin.IsInCodeFocusMode;
992
994
[CommandHandler (MonoDevelop.Ide.Commands.TextEditorCommands.TransposeCharacters)]
993
995
internal void TransposeCharacters ()