Beispiel #1
0
 private void ShowContextMenu(IChartDrawable primitive, UserControl control, MouseEventArgs e)
 {
     #if GTK
     GtkWorkarounds.ShowContextMenu(InitContextMenu(primitive), control, e.GdkEventButton, Gdk.Rectangle.Zero);
     #else
     InitContextMenu(primitive).Show(control, e.Location);
     #endif
 }
Beispiel #2
0
        bool ShowFixesMenu(Gtk.Widget parent, Gdk.Rectangle evt, FixMenuDescriptor entrySet)
        {
                        #if MAC
            parent.GrabFocus();
            int x, y;
            x = (int)evt.X;
            y = (int)evt.Y;

            Gtk.Application.Invoke(delegate {
                // 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      = CreateNSMenu(entrySet);
                menu.Delegate = new ClosingMenuDelegate(document.Editor);
                var nsview    = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent);
                var toplevel  = parent.Toplevel as Gtk.Window;
                int trans_x, trans_y;
                parent.TranslateCoordinates(toplevel, (int)x, (int)y, out trans_x, out trans_y);

                // Window coordinates in gtk are the same for cocoa, with the exception of the Y coordinate, that has to be flipped.
                var pt = new CoreGraphics.CGPoint((float)trans_x, (float)trans_y);
                int w, h;
                toplevel.GetSize(out w, out h);
                pt.Y = h - pt.Y;

                var tmp_event = AppKit.NSEvent.MouseEvent(AppKit.NSEventType.LeftMouseDown,
                                                          pt,
                                                          0, 0,
                                                          MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel).WindowNumber,
                                                          null, 0, 0, 0);

                AppKit.NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
            });
                        #else
            var menu = CreateGtkMenu(entrySet);
            menu.Events |= Gdk.EventMask.AllEventsMask;
            menu.SelectFirst(true);

            menu.Hidden += delegate {
                document.Editor.SuppressTooltips = false;
            };
            menu.ShowAll();
            menu.SelectFirst(true);
            menu.MotionNotifyEvent += (o, args) => {
                if (args.Event.Window == Editor.Parent.TextArea.GdkWindow)
                {
                    StartMenuCloseTimer();
                }
                else
                {
                    CancelMenuCloseTimer();
                }
            };

            GtkWorkarounds.ShowContextMenu(menu, parent, null, evt);
                        #endif
            return(true);
        }
Beispiel #3
0
        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);
                }
            }
        }
Beispiel #4
0
        void ShowPopup(EventButton evt)
        {
            CommandEntrySet cset = IdeApp.CommandService.CreateCommandEntrySet("/MonoDevelop/VersionControl/BlameView/ContextMenu");

            Gtk.Menu menu = IdeApp.CommandService.CreateMenu(cset);
            menu.Destroyed += delegate {
                this.QueueDraw();
            };

            if (evt != null)
            {
                GtkWorkarounds.ShowContextMenu(menu, this, evt);
            }
            else
            {
                var pt = editor.LocationToPoint(editor.Caret.Location);
                GtkWorkarounds.ShowContextMenu(menu, editor, new Gdk.Rectangle(pt.X, pt.Y, 1, (int)editor.LineHeight));
            }
        }
        void ShowPopup(Gdk.EventButton evt)
        {
            view.FireCompletionContextChanged();
            CompletionWindowManager.HideWindow();
            ParameterInformationWindowManager.HideWindow(null, view);
            HideTooltip();
            const string menuPath = "/MonoDevelop/SourceEditor2/ContextMenu/Editor";
            var          ctx      = ExtensionContext ?? AddinManager.AddinEngine;

            CommandEntrySet cset = IdeApp.CommandService.CreateCommandEntrySet(ctx, menuPath);

            if (Platform.IsMac)
            {
                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, new Gdk.Rectangle(pt.X, pt.Y, 1, (int)LineHeight));
                }
            }
        }
        protected override bool OnButtonReleaseEvent(EventButton evnt)
        {
            bool result;

            if (evnt.Button == 3u)
            {
                base.IsFocus = true;
                this._contentMenu.ShowAll();
                GtkWorkarounds.ShowContextMenu(this._contentMenu, this, evnt);
                if (this.resourceFile == null || this.resourceFile.IsDefault)
                {
                    this._contentMenu.Children.ForEach(delegate(Gtk.Widget w)
                    {
                        (w as Gtk.MenuItem).Sensitive = false;
                    });
                    this._contentMenu.Children[3].Sensitive = true;
                }
                else
                {
                    this._contentMenu.Children.ForEach(delegate(Gtk.Widget w)
                    {
                        (w as Gtk.MenuItem).Sensitive = true;
                    });
                }
                result = true;
            }
            else
            {
                if (this.IsDoubleClick(evnt, 1u))
                {
                    this.SelectFile();
                }
                result = base.OnButtonReleaseEvent(evnt);
            }
            return(result);
        }
 protected override bool OnButtonReleaseEvent(EventButton evnt)
 {
     if ((int)evnt.Button == 3)
     {
         this.IsFocus = true;
         this._contentMenu.ShowAll();
         GtkWorkarounds.ShowContextMenu(this._contentMenu, (Gtk.Widget) this, evnt);
         if (this.resourceFile == null || this.resourceFile.IsDefault)
         {
             ((IEnumerable <Gtk.Widget>) this._contentMenu.Children).ForEach <Gtk.Widget>((System.Action <Gtk.Widget>)(w => (w as Gtk.MenuItem).Sensitive = false));
             this._contentMenu.Children[3].Sensitive = true;
         }
         else
         {
             ((IEnumerable <Gtk.Widget>) this._contentMenu.Children).ForEach <Gtk.Widget>((System.Action <Gtk.Widget>)(w => (w as Gtk.MenuItem).Sensitive = true));
         }
         return(true);
     }
     if (this.IsDoubleClick(evnt, 1U))
     {
         this.SelectFile();
     }
     return(base.OnButtonReleaseEvent(evnt));
 }
        void PopupQuickFixMenu(Gdk.EventButton evt, Action <Gtk.Menu> menuAction)
        {
            var menu = new Gtk.Menu();

            menu.Events |= Gdk.EventMask.AllEventsMask;
            Gtk.Menu      fixMenu = menu;
            ResolveResult resolveResult;

            ICSharpCode.NRefactory.CSharp.AstNode node;
            int items = 0;

            if (ResolveCommandHandler.ResolveAt(document, out resolveResult, out node))
            {
                var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces(
                    document,
                    node,
                    ref resolveResult
                    );

                bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
                if (addUsing)
                {
                    foreach (var t in possibleNamespaces.Where(tp => tp.IsAccessibleWithGlobalUsing))
                    {
                        string ns        = t.Namespace;
                        var    reference = t.Reference;
                        var    menuItem  = new Gtk.MenuItem(string.Format("using {0};", ns));
                        menuItem.Activated += delegate {
                            new ResolveCommandHandler.AddImport(document, resolveResult, ns, reference, true, node).Run();
                            if (reference != null)
                            {
                                document.Project.Items.Add(reference);
                            }
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                        items++;
                    }
                }

                bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
                if (resolveDirect)
                {
                    foreach (var t in possibleNamespaces)
                    {
                        string ns        = t.Namespace;
                        var    reference = t.Reference;
                        var    menuItem  = new Gtk.MenuItem(GettextCatalog.GetString("{0}", ns + "." + document.Editor.GetTextBetween(node.StartLocation, node.EndLocation)));
                        menuItem.Activated += delegate {
                            new ResolveCommandHandler.AddImport(document, resolveResult, ns, reference, false, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                        items++;
                    }
                }
                if (menu.Children.Any() && fixes.Any())
                {
                    fixMenu = new Gtk.Menu();
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Quick Fixes"));
                    menuItem.Submenu = fixMenu;
                    menu.Add(menuItem);
                    items++;
                }
            }

            PopulateFixes(fixMenu, ref items);
            if (items == 0)
            {
                menu.Destroy();
                return;
            }
            document.Editor.SuppressTooltips = true;
            document.Editor.Parent.HideTooltip();
            if (menuAction != null)
            {
                menuAction(menu);
            }
            menu.ShowAll();
            menu.SelectFirst(true);
            menuPushed   = true;
            menu.Hidden += delegate {
                document.Editor.SuppressTooltips = false;
            };
            menu.Destroyed += delegate {
                menuPushed = false;
                Hide();
            };
            var container = document.Editor.Parent;
            var child     = (TextEditor.EditorContainerChild)container [this];

            Gdk.Rectangle rect;

/*			if (child != null) {
 *                              rect = new Gdk.Rectangle (child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0);
 *                      } else {*/
            var p = container.LocationToPoint(loc);

            rect = new Gdk.Rectangle(p.X + container.Allocation.X, p.Y + (int)document.Editor.LineHeight + container.Allocation.Y, 0, 0);
            //}
            GtkWorkarounds.ShowContextMenu(menu, document.Editor.Parent, null, rect);
        }
        void PopupQuickFixMenu(Gdk.EventButton evt, Action <Gtk.Menu> menuAction)
        {
            var menu = new Gtk.Menu();

            menu.Events |= Gdk.EventMask.AllEventsMask;
            Gtk.Menu      fixMenu = menu;
            ResolveResult resolveResult;

            ICSharpCode.NRefactory.CSharp.AstNode node;
            int items = 0;

            if (ResolveCommandHandler.ResolveAt(document, out resolveResult, out node))
            {
                var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces(
                    document,
                    node,
                    ref resolveResult
                    );

                foreach (var t in possibleNamespaces.Where(tp => tp.OnlyAddReference))
                {
                    var menuItem = new Gtk.MenuItem(t.GetImportText());
                    menuItem.Activated += delegate {
                        new ResolveCommandHandler.AddImport(document, resolveResult, null, t.Reference, true, node).Run();
                        menu.Destroy();
                    };
                    menu.Add(menuItem);
                    items++;
                }

                bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
                if (addUsing)
                {
                    foreach (var t in possibleNamespaces.Where(tp => tp.IsAccessibleWithGlobalUsing))
                    {
                        string ns        = t.Namespace;
                        var    reference = t.Reference;
                        var    menuItem  = new Gtk.MenuItem(t.GetImportText());
                        menuItem.Activated += delegate {
                            new ResolveCommandHandler.AddImport(document, resolveResult, ns, reference, true, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                        items++;
                    }
                }

                bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
                if (resolveDirect)
                {
                    foreach (var t in possibleNamespaces)
                    {
                        string ns        = t.Namespace;
                        var    reference = t.Reference;
                        var    menuItem  = new Gtk.MenuItem(t.GetInsertNamespaceText(document.Editor.GetTextBetween(node.StartLocation, node.EndLocation)));
                        menuItem.Activated += delegate {
                            new ResolveCommandHandler.AddImport(document, resolveResult, ns, reference, false, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                        items++;
                    }
                }

                if (menu.Children.Any() && Fixes.Any())
                {
                    fixMenu = new Gtk.Menu();
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Quick Fixes"));
                    menuItem.Submenu = fixMenu;
                    menu.Add(menuItem);
                    items++;
                }
            }

            PopulateFixes(fixMenu, ref items);
            if (items == 0)
            {
                menu.Destroy();
                return;
            }
            document.Editor.SuppressTooltips = true;
            document.Editor.Parent.HideTooltip();
            if (menuAction != null)
            {
                menuAction(menu);
            }
            menu.ShowAll();
            menu.SelectFirst(true);
            menu.Hidden += delegate {
                document.Editor.SuppressTooltips = false;
            };
            var container = document.Editor.Parent;

            var p    = container.LocationToPoint(currentSmartTagBegin);
            var rect = new Gdk.Rectangle(
                p.X + container.Allocation.X,
                p.Y + (int)document.Editor.LineHeight + container.Allocation.Y, 0, 0);

            GtkWorkarounds.ShowContextMenu(menu, document.Editor.Parent, null, rect);
        }
            public override void InformMousePress(TextEditor editor, Margin margin, MarginMouseEventArgs args)
            {
                if (!(margin is ActionMargin))
                {
                    return;
                }
                if (menu != null)
                {
                    menu.Destroy();
                }
                var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode();

                menu = new Menu();
                if (unitTest.IsFixture)
                {
                    var menuItem = new MenuItem("_Run All");
                    menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, false).Run;
                    menu.Add(menuItem);
                    if (debugModeSet != null)
                    {
                        menuItem            = new MenuItem("_Debug All");
                        menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, true).Run;
                        menu.Add(menuItem);
                    }
                    menuItem            = new MenuItem("_Select in Test Pad");
                    menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, true).Select;
                    menu.Add(menuItem);
                }
                else
                {
                    if (unitTest.TestCases.Count == 0)
                    {
                        var menuItem = new MenuItem("_Run");
                        menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, false).Run;
                        menu.Add(menuItem);
                        if (debugModeSet != null)
                        {
                            menuItem            = new MenuItem("_Debug");
                            menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, true).Run;
                            menu.Add(menuItem);
                        }
                        menuItem            = new MenuItem("_Select in Test Pad");
                        menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, true).Select;
                        menu.Add(menuItem);
                    }
                    else
                    {
                        var menuItem = new MenuItem("_Run All");
                        menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, false).Run;
                        menu.Add(menuItem);
                        if (debugModeSet != null)
                        {
                            menuItem            = new MenuItem("_Debug All");
                            menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier, true).Run;
                            menu.Add(menuItem);
                        }
                        menu.Add(new SeparatorMenuItem());
                        foreach (var id in unitTest.TestCases)
                        {
                            var submenu = new Menu();
                            menuItem            = new MenuItem("_Run");
                            menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier + id, false).Run;
                            submenu.Add(menuItem);
                            if (debugModeSet != null)
                            {
                                menuItem            = new MenuItem("_Debug");
                                menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier + id, true).Run;
                                submenu.Add(menuItem);
                            }

                            var    label   = "Test" + id;
                            string tooltip = null;
                            var    test    = NUnitService.Instance.SearchTestById(unitTest.UnitTestIdentifier + id);
                            if (test != null)
                            {
                                var result = test.GetLastResult();
                                if (result != null && result.IsFailure)
                                {
                                    tooltip = result.Message;
                                    label  += "!";
                                }
                            }

                            menuItem            = new MenuItem("_Select in Test Pad");
                            menuItem.Activated += new TestRunner(doc, unitTest.UnitTestIdentifier + id, true).Select;
                            submenu.Add(menuItem);


                            var subMenuItem = new MenuItem(label);
                            if (!string.IsNullOrEmpty(tooltip))
                            {
                                subMenuItem.TooltipText = tooltip;
                            }
                            subMenuItem.Submenu = submenu;
                            menu.Add(subMenuItem);
                        }
                    }
                }
                menu.ShowAll();
                editor.TextArea.ResetMouseState();
                GtkWorkarounds.ShowContextMenu(menu, editor, new Gdk.Rectangle((int)args.X, (int)args.Y, 1, 1));
            }
Beispiel #11
0
        void PopupQuickFixMenu(Gdk.EventButton evt)
        {
            var menu = new Gtk.Menu();

            Gtk.Menu      fixMenu = menu;
            ResolveResult resolveResult;

            ICSharpCode.NRefactory.CSharp.AstNode node;
            if (ResolveCommandHandler.ResolveAt(document, out resolveResult, out node))
            {
                var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces(
                    document,
                    node,
                    resolveResult
                    );

                bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
                if (addUsing)
                {
                    foreach (string ns_ in possibleNamespaces)
                    {
                        string ns       = ns_;
                        var    menuItem = new Gtk.MenuItem(string.Format("using {0};", ns));
                        menuItem.Activated += delegate {
                            new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport(document, resolveResult, ns, true, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                    }
                }

                bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
                if (resolveDirect)
                {
                    foreach (string ns in possibleNamespaces)
                    {
                        var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("{0}", ns + "." + document.Editor.GetTextBetween(node.StartLocation, node.EndLocation)));
                        menuItem.Activated += delegate {
                            new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport(document, resolveResult, ns, false, node).Run();
                            menu.Destroy();
                        };
                        menu.Add(menuItem);
                    }
                }
                if (menu.Children.Any() && fixes.Any())
                {
                    fixMenu = new Gtk.Menu();
                    var menuItem = new Gtk.MenuItem(GettextCatalog.GetString("Quick Fixes"));
                    menuItem.Submenu = fixMenu;
                    menu.Add(menuItem);
                }
            }

            PopulateFixes(fixMenu);

            menu.ShowAll();
            menu.SelectFirst(true);
            menuPushed      = true;
            menu.Destroyed += delegate {
                menuPushed = false;
                Hide();
            };
            var container = (TextEditorContainer)document.Editor.Parent.Parent;
            var child     = (TextEditorContainer.EditorContainerChild)container [this];

            GtkWorkarounds.ShowContextMenu(menu, document.Editor.Parent, null, new Gdk.Rectangle(child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0));
        }