bool ShowFixesMenu(Widget parent, Gdk.Rectangle evt, CodeFixMenu entrySet) { if (parent == null || parent.GdkWindow == null) { Editor.SuppressTooltips = false; return(true); } try { parent.GrabFocus(); int x, y; x = evt.X; y = evt.Y; // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event Gdk.Pointer.Ungrab(Gtk.Global.CurrentEventTime); var menu = CreateContextMenu(entrySet); RefactoringPreviewTooltipWindow.HidePreviewTooltip(); menu.Show(parent, x, y, () => { Editor.SuppressTooltips = false; RefactoringPreviewTooltipWindow.HidePreviewTooltip(); FixesMenuClosed?.Invoke(this, EventArgs.Empty); }, true); } catch (Exception ex) { LoggingService.LogError("Error while context menu popup.", ex); } return(true); }
public override void Dispose() { CancelQuickFixTimer(); RefactoringPreviewTooltipWindow.HidePreviewTooltip(); Editor.CaretPositionChanged -= HandleCaretPositionChanged; DocumentContext.DocumentParsed -= HandleDocumentDocumentParsed; Editor.TextChanged -= Editor_TextChanged; Editor.BeginAtomicUndoOperation -= Editor_BeginAtomicUndoOperation; Editor.EndAtomicUndoOperation -= Editor_EndAtomicUndoOperation; RemoveWidget(); base.Dispose(); }
ContextMenu CreateContextMenu(CodeFixMenu entrySet) { var menu = new ContextMenu(); foreach (var item in entrySet.Items) { if (item == CodeFixMenuEntry.Separator) { menu.Items.Add(new SeparatorContextMenuItem()); continue; } var menuItem = new ContextMenuItem(item.Label); menuItem.Context = item.Action; if (item.Action == null) { if (!(item is CodeFixMenu itemAsMenu) || itemAsMenu.Items.Count <= 0) { menuItem.Sensitive = false; } } var subMenu = item as CodeFixMenu; if (subMenu != null) { menuItem.SubMenu = CreateContextMenu(subMenu); menuItem.Selected += delegate { RefactoringPreviewTooltipWindow.HidePreviewTooltip(); }; menuItem.Deselected += delegate { RefactoringPreviewTooltipWindow.HidePreviewTooltip(); }; } else { menuItem.Clicked += (sender, e) => ((System.Action)((ContextMenuItem)sender).Context)(); menuItem.Selected += (sender, e) => { RefactoringPreviewTooltipWindow.HidePreviewTooltip(); if (item.ShowPreviewTooltip != null) { item.ShowPreviewTooltip(e); } }; menuItem.Deselected += delegate { RefactoringPreviewTooltipWindow.HidePreviewTooltip(); }; } menu.Items.Add(menuItem); } menu.Closed += delegate { RefactoringPreviewTooltipWindow.HidePreviewTooltip(); }; return(menu); }