protected void ShowCompletion(ICompletionDataList completionList, int triggerWordLength, char keyChar) { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWidget != null && CurrentCompletionContext == null) { CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext; if (triggerWordLength > 0 && triggerWordLength < Editor.CaretOffset) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength); CurrentCompletionContext.TriggerWordLength = triggerWordLength; } if (completionList != null) { CompletionWindowManager.ShowWindow(this, keyChar, completionList, CompletionWidget, CurrentCompletionContext); } else { CurrentCompletionContext = null; } } autoHideCompletionWindow = autoHideParameterWindow = true; }
public virtual async void RunCompletionCommand() { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.Wnd.ToggleCategoryMode(); return; } ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; completionList = await CodeCompletionCommand(CurrentCompletionContext); if (completionList == null || !CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext)) { CurrentCompletionContext = null; } }
public virtual async Task TriggerCompletion(CompletionTriggerReason reason) { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.Wnd.ToggleCategoryMode(); return; } Editor.EnsureCaretIsNotVirtual(); ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; completionList = await HandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo (reason)); if (completionList.TriggerWordStart >= 0) { CurrentCompletionContext.TriggerOffset = completionList.TriggerWordStart; CurrentCompletionContext.TriggerWordLength = completionList.TriggerWordLength; } if (completionList == null || !CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext)) { CurrentCompletionContext = null; } }
public virtual async Task TriggerCompletion(CompletionTriggerReason reason) { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.ToggleCategoryMode(); return; } Editor.EnsureCaretIsNotVirtual(); ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } completionTokenSrc.Cancel(); completionTokenSrc = new CancellationTokenSource(); var token = completionTokenSrc.Token; CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; var timer = CurrentCompletionContext.BeginTiming(); bool failure = false; try { completionList = await DoHandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo (reason), token); if (completionList != null && completionList.TriggerWordStart >= 0) { CurrentCompletionContext.TriggerOffset = completionList.TriggerWordStart; CurrentCompletionContext.TriggerWordLength = completionList.TriggerWordLength; } if (completionList == null || !CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext)) { CurrentCompletionContext = null; } } catch (Exception) { failure = true; throw; } finally { timer.End(); if (failure) { completionStats.OnFailure(timer.Duration); } else { completionStats.OnSuccess(timer.Duration); } } }
protected override void OnDestroyed() { IdeApp.Preferences.CustomOutputPadFont.Changed -= OnCustomOutputPadFontChanged; CompletionWindowManager.WindowClosed -= OnCompletionWindowClosed; CompletionWindowManager.HideWindow(); TextView.FocusOutEvent -= TextView_FocusOutEvent; base.OnDestroyed(); }
protected void OnCompletionContextChanged(object o, EventArgs a) { if (autoHideCompletionWindow) { CompletionWindowManager.HideWindow(); ParameterInformationWindowManager.HideWindow(this, CompletionWidget); } }
internal protected virtual void HandlePositionChanged(object sender, EventArgs e) { if (!IsActiveExtension()) { return; } CompletionWindowManager.UpdateCursorPosition(); }
void HAdjustment_ValueChanged(object sender, EventArgs e) { if (!isInKeyStroke) { CompletionWindowManager.HideWindow(); ParameterInformationWindowManager.HideWindow(null, view); } }
protected override void HAdjustmentValueChanged() { base.HAdjustmentValueChanged(); if (!isInKeyStroke) { CompletionWindowManager.HideWindow(); ParameterInformationWindowManager.HideWindow(); } }
void DoReSmartIndent(int cursor) { SafeUpdateIndentEngine(cursor); if (stateTracker.LineBeganInsideVerbatimString || stateTracker.LineBeganInsideMultiLineComment) { return; } var line = Editor.GetLineByOffset(cursor); // Get context to the end of the line w/o changing the main engine's state var curTracker = stateTracker.Clone(); try { for (int max = cursor; max < line.EndOffset; max++) { curTracker.Push(Editor.GetCharAt(max)); } } catch (Exception e) { LoggingService.LogError("Exception during indentation", e); } int pos = line.Offset; string curIndent = line.GetIndentation(Editor); int nlwsp = curIndent.Length; int offset = cursor > pos + nlwsp ? cursor - (pos + nlwsp) : 0; if (!stateTracker.LineBeganInsideMultiLineComment || (nlwsp < line.LengthIncludingDelimiter && Editor.GetCharAt(line.Offset + nlwsp) == '*')) { // Possibly replace the indent string newIndent = curTracker.ThisLineIndent; int newIndentLength = newIndent.Length; if (newIndent != curIndent) { if (CompletionWindowManager.IsVisible) { if (pos < CompletionWindowManager.CodeCompletionContext.TriggerOffset) { CompletionWindowManager.CodeCompletionContext.TriggerOffset -= nlwsp; } } Editor.ReplaceText(pos, nlwsp, newIndent); newIndentLength = newIndent.Length; CompletionWindowManager.HideWindow(); } pos += newIndentLength; } else { pos += curIndent.Length; } pos += offset; Editor.FixVirtualIndentation(); }
public void TestProjectionCompletion() { var editor = TextEditorFactory.CreateNewEditor(); var options = new CustomEditorOptions(editor.Options); options.EditorTheme = "Tango"; editor.Options = options; editor.Text = "12345678901234567890"; var projectedDocument = TextEditorFactory.CreateNewDocument( new StringTextSource("__12__34__56__78__90"), "a" ); var segments = new List <ProjectedSegment> (); for (int i = 0; i < 5; i++) { segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2)); } var projection = new Projection.Projection(projectedDocument, segments); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; var originalContext = new Document(tww); var projectedEditor = projection.CreateProjectedEditor(originalContext); TestCompletionExtension orignalExtension; editor.SetExtensionChain(originalContext, new [] { orignalExtension = new TestCompletionExtension(editor) { CompletionWidget = new EmptyCompletionWidget(editor) } }); TestCompletionExtension projectedExtension; projectedEditor.SetExtensionChain(originalContext, new [] { projectedExtension = new TestCompletionExtension(editor) { CompletionWidget = new EmptyCompletionWidget(projectedEditor) } }); editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None); editor.CaretOffset = 1; var service = new CommandManager(); service.LoadCommands("/MonoDevelop/Ide/Commands"); service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter); Assert.IsFalse(orignalExtension.CompletionRun); Assert.IsTrue(projectedExtension.CompletionRun); editor.CaretOffset = 15; CompletionWindowManager.HideWindow(); service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter); Assert.IsTrue(orignalExtension.CompletionRun); }
public void InsertTemplate(object obj, EventArgs args) { ICompletionDataList completionList = new CompletionDataList(); completionList = ShowCodeTemplatesCommand(); currentCompletionContext = widget.CreateCodeCompletionContext(); //this.editor.Caret.Offset CompletionWindowManager.IsTemplateModes = true; CompletionWindowManager.ShowWindow((char)0, completionList, widget, currentCompletionContext, OnCompletionWindowClosed); editor.GrabFocus(); }
void TextView_FocusOutEvent(object o, Gtk.FocusOutEventArgs args) { // On Windows code completion popup stays TopMost also when switching to other apps // but on Mac code completion window hides and shows when focus goes out and back in // so no need to hide it on Mac for better UX if (MonoDevelop.Core.Platform.IsWindows) { CompletionWindowManager.HideWindow(); } }
void OnEditKeyRelease(object sender, EventArgs e) { if (keyHandled) { return; } CompletionWindowManager.PostProcessKeyEvent(KeyDescriptor.FromGtk(key, keyChar, modifier)); PopupCompletion((Entry)sender); }
void OnEndEditing() { editing = false; editEntry.KeyPressEvent -= OnEditKeyPress; CompletionWindowManager.HideWindow(); currentCompletionData = null; if (EndEditing != null) { EndEditing(this, EventArgs.Empty); } }
void HandleOnTheFlyFormatting(KeyDescriptor descriptor) { if (descriptor.KeyChar == '{') { return; } SafeUpdateIndentEngine(Editor.CaretOffset); bool skipFormatting = stateTracker.IsInsideOrdinaryCommentOrString; if (!skipFormatting && !(stateTracker.IsInsideComment || stateTracker.IsInsideString)) { if (DocumentContext.ParsedDocument == null || DocumentContext.ParsedDocument.GetAst <SemanticModel> () == null) { return; } var document = DocumentContext.AnalysisDocument; if (document == null) { return; } if (!skipFormatting && service.SupportsFormattingOnTypedCharacter(document, descriptor.KeyChar)) { var caretPosition = Editor.CaretOffset; var token = CSharpEditorFormattingService.GetTokenBeforeTheCaretAsync(document, caretPosition, default(CancellationToken)).Result; if (token.IsMissing || !service.ValidSingleOrMultiCharactersTokenKind(descriptor.KeyChar, token.Kind()) || token.IsKind(SyntaxKind.EndOfFileToken) || token.IsKind(SyntaxKind.None)) { return; } if (CSharpEditorFormattingService.TokenShouldNotFormatOnTypeChar(token)) { return; } using (var undo = Editor.OpenUndoGroup()) { if (OnTheFlyFormatting && Editor != null && Editor.EditMode == EditMode.Edit) { var oldVersion = Editor.Version; OnTheFlyFormatter.FormatStatmentAt(Editor, DocumentContext, Editor.CaretLocation, optionSet: optionSet); if (oldVersion.CompareAge(Editor.Version) != 0) { CompletionWindowManager.HideWindow(); } } } } } if (OnTheFlyFormatting && descriptor.SpecialKey == SpecialKey.Return) { try { FormatOnReturn(); } catch (Exception e) { LoggingService.LogError("Exception while formatting", e); } } }
protected void OnCompletionContextChanged(object o, EventArgs a) { if (autoHideCompletionWindow) { CompletionWindowManager.HideWindow(); } if (autoHideParameterWindow) { ParameterInformationWindowManager.HideWindow(this, CompletionWidget); } ParameterInformationWindowManager.UpdateCursorPosition(this, CompletionWidget); }
void OnEditKeyRelease(object sender, Gtk.KeyReleaseEventArgs args) { UpdateTokenBeginMarker(); if (keyHandled) { return; } CompletionWindowManager.PostProcessKeyEvent(KeyDescriptor.FromGtk(key, keyChar, modifier)); PopupCompletion(); }
void DoReSmartIndent(int cursor) { if (stateTracker.Engine.LineBeganInsideVerbatimString || stateTracker.Engine.LineBeganInsideMultiLineComment) { return; } DocumentLine line = textEditorData.Document.GetLineByOffset(cursor); // stateTracker.UpdateEngine (line.Offset); // Get context to the end of the line w/o changing the main engine's state var ctx = (CSharpIndentEngine)stateTracker.Engine.Clone(); for (int max = cursor; max < line.EndOffset; max++) { ctx.Push(textEditorData.Document.GetCharAt(max)); } int pos = line.Offset; string curIndent = line.GetIndentation(textEditorData.Document); int nlwsp = curIndent.Length; int offset = cursor > pos + nlwsp ? cursor - (pos + nlwsp) : 0; if (!stateTracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < line.LengthIncludingDelimiter && textEditorData.Document.GetCharAt(line.Offset + nlwsp) == '*')) { // Possibly replace the indent string newIndent = ctx.ThisLineIndent; int newIndentLength = newIndent.Length; if (newIndent != curIndent) { if (CompletionWindowManager.IsVisible) { if (pos < CompletionWindowManager.CodeCompletionContext.TriggerOffset) { CompletionWindowManager.CodeCompletionContext.TriggerOffset -= nlwsp; } } newIndentLength = textEditorData.Replace(pos, nlwsp, newIndent); textEditorData.Document.CommitLineUpdate(textEditorData.Caret.Line); // Engine state is now invalid stateTracker.ResetEngineToPosition(pos); CompletionWindowManager.HideWindow(); } pos += newIndentLength; } else { pos += curIndent.Length; } pos += offset; textEditorData.FixVirtualIndentation(); }
public virtual async Task TriggerCompletion(CompletionTriggerReason reason) { if (Editor.SelectionMode == SelectionMode.Block) { return; } if (CompletionWindowManager.IsVisible) { CompletionWindowManager.ToggleCategoryMode(); return; } Editor.EnsureCaretIsNotVirtual(); ICompletionDataList completionList = null; int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } completionTokenSrc.Cancel(); completionTokenSrc = new CancellationTokenSource(); var token = completionTokenSrc.Token; CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(cpos); CurrentCompletionContext.TriggerWordLength = wlen; var metadata = new Dictionary <string, string> (); metadata ["Result"] = "Success"; try { Counters.ProcessCodeCompletion.BeginTiming(metadata); completionList = await DoHandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo (reason), token); if (completionList != null && completionList.TriggerWordStart >= 0) { CurrentCompletionContext.TriggerOffset = completionList.TriggerWordStart; CurrentCompletionContext.TriggerWordLength = completionList.TriggerWordLength; } if (completionList == null || !CompletionWindowManager.ShowWindow(this, (char)0, completionList, CompletionWidget, CurrentCompletionContext)) { CurrentCompletionContext = null; } } catch (Exception) { metadata ["Result"] = "Failure"; throw; } finally { Counters.ProcessCodeCompletion.EndTiming(); } }
void OnEditKeyRelease(object sender, EventArgs e) { if (keyHandled) { return; } string text = ctx == null ? entry.Text : entry.Text.Substring(Math.Max(0, Math.Min(ctx.TriggerOffset, entry.Text.Length))); CompletionWindowManager.UpdateWordSelection(text); CompletionWindowManager.PostProcessKeyEvent(key, keyChar, modifier); PopupCompletion((Entry)sender); }
void HandleKeyReleaseEvent(object o, Gtk.KeyReleaseEventArgs args) { if (keyHandled) { return; } string text = ctx == null ? Text : Text.Substring(Math.Max(0, Math.Min(ctx.TriggerOffset, Text.Length))); CompletionWindowManager.UpdateWordSelection(text); CompletionWindowManager.PostProcessKeyEvent(KeyDescriptor.FromGtk(key, keyChar, modifier)); PopupCompletion(); }
void ShowPopup(Gdk.EventButton evt) { view.FireCompletionContextChanged(); CompletionWindowManager.HideWindow(); ParameterInformationWindowManager.HideWindow(null, view); HideTooltip(); if (string.IsNullOrEmpty(menuPath)) { return; } var ctx = view.WorkbenchWindow?.ExtensionContext ?? AddinManager.AddinEngine; CommandEntrySet cset = IdeApp.CommandService.CreateCommandEntrySet(ctx, menuPath); if (Platform.IsMac) { if (evt == null) { int x, y; var pt = LocationToPoint(this.Caret.Location); TranslateCoordinates(Toplevel, pt.X, pt.Y, out x, out y); IdeApp.CommandService.ShowContextMenu(this, x, y, cset, this); } else { IdeApp.CommandService.ShowContextMenu(this, evt, cset, this); } } else { Gtk.Menu menu = IdeApp.CommandService.CreateMenu(cset); var imMenu = CreateInputMethodMenuItem(GettextCatalog.GetString("_Input Methods")); if (imMenu != null) { menu.Append(new SeparatorMenuItem()); menu.Append(imMenu); } menu.Hidden += HandleMenuHidden; if (evt != null) { GtkWorkarounds.ShowContextMenu(menu, this, evt); } else { var pt = LocationToPoint(this.Caret.Location); GtkWorkarounds.ShowContextMenu(menu, this, (int)pt.X, (int)pt.Y); } } }
void PopupCompletion() { char c = (char)Gdk.Keyval.ToUnicode(keyValue); if (ctx == null) { ctx = ((ICompletionWidget)this).CreateCodeCompletionContext(0); CompletionWindowManager.ShowWindow(null, c, list, this, ctx); if (CompletionContextChanged != null) { CompletionContextChanged(this, EventArgs.Empty); } } }
public void ShowCompletion(ICompletionDataList completionList) { CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset); int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Editor.CaretOffset; wlen = 0; } CurrentCompletionContext.TriggerOffset = cpos; CurrentCompletionContext.TriggerWordLength = wlen; CompletionWindowManager.ShowWindow(this, '\0', completionList, CompletionWidget, CurrentCompletionContext); }
public void ShowCompletion(ICompletionDataList completionList) { currentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Document.Editor.Caret.Offset); int cpos, wlen; if (!GetCompletionCommandOffset(out cpos, out wlen)) { cpos = Document.Editor.Caret.Offset; wlen = 0; } currentCompletionContext.TriggerOffset = cpos; currentCompletionContext.TriggerWordLength = wlen; CompletionWindowManager.ShowWindow('\0', completionList, CompletionWidget, currentCompletionContext, OnCompletionWindowClosed); }
public override void Dispose() { if (!disposed) { CompletionWindowManager.HideWindow(); ParameterInformationWindowManager.HideWindow(this, CompletionWidget); disposed = true; CompletionWindowManager.WindowClosed -= HandleWindowClosed; if (CompletionWidget != null) { CompletionWidget.CompletionContextChanged -= OnCompletionContextChanged; } } base.Dispose(); }
internal protected virtual void OnCompletionContextChanged(object o, EventArgs a) { if (!IsActiveExtension()) { return; } if (autoHideCompletionWindow) { CompletionWindowManager.HideWindow(); } if (autoHideParameterWindow) { ParameterInformationWindowManager.HideWindow(this, CompletionWidget); } ParameterInformationWindowManager.UpdateCursorPosition(this, CompletionWidget); }
public override void Dispose() { if (!disposed) { completionTokenSrc.Cancel(); parameterHintingSrc.Cancel(); CompletionWindowManager.HideWindow(); ParameterInformationWindowManager.HideWindow(this, CompletionWidget); disposed = true; Editor.FocusLost -= HandleFocusOutEvent; // document.Editor.Paste -= HandlePaste; Deinitialize(); } base.Dispose(); }
void HandleKeyPressEvent(object o, KeyEventArgs args) { keyHandled = false; keyChar = CharFromKey(args.Key); modifier = args.Modifiers; key = args.Key; if ((args.Key == Key.Down || args.Key == Key.Up)) { keyChar = '\0'; } if (list != null) { args.Handled = keyHandled = CompletionWindowManager.PreProcessKeyEvent(KeyDescriptor.FromXwt(key, keyChar, modifier)); } }