コード例 #1
0
        public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            parent.GrabFocus();

            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 nsview   = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent);
                var toplevel = parent.Toplevel as Gtk.Window;

                var nswindow       = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel);
                var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight();
                var pt             = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarHeight - 12);

                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   nswindow.WindowNumber,
                                                   null, 0, 0, 0);

                NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
            });
        }
コード例 #2
0
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            NSTableViewDataSource ds = (NSTableViewDataSource)this.DataSource;
            NSMenu menu = new NSMenu();

            if (SelectedRow >= (nint)0)
            {
                if (ds is AttributesEntryListView)
                {
                    VMDirSchemaAttributeEntryNode node = (ds as AttributesEntryListView).Entries[(int)SelectedRow];
                    NSMenuItem properties = new NSMenuItem(VMDirSchemaConstants.VMDIRSCHEMA_PROPERTIES, node.ShowProperties);
                    menu.AddItem(properties);
                }
                else if (ds is ObjectClassesListView)
                {
                    VMDirSchemaClassEntryNode node = (ds as ObjectClassesListView).Entries[(int)SelectedRow];
                    NSMenuItem properties          = new NSMenuItem(VMDirSchemaConstants.VMDIRSCHEMA_PROPERTIES, node.ShowProperties);
                    menu.AddItem(properties);
                }
                else
                {
                    //do nothing
                }
            }
            NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
            return(base.MenuForEvent(theEvent));
        }
コード例 #3
0
        void IWindow.ShowColorSelector(Color[] options)
        {
            if (changeColorNSEvent == null)
            {
                return;
            }
            var menu = new NSMenu();

            foreach (var opt in options)
            {
                var item    = new NSMenuItem();
                var imgSize = new CoreGraphics.CGSize(50, 12);
                var img     = new NSImage(imgSize);
                img.LockFocus();
                using (var path = NSBezierPath.FromRect(
                           new CoreGraphics.CGRect(0, 0, imgSize.Width, imgSize.Height)))
                    using (var cl = opt.ToNSColor()) {
                        cl.SetFill();
                        path.Fill();
                    }
                img.UnlockFocus();
                item.Image  = img;
                item.Title  = "";
                item.Action = new Selector("OnColorMenuItemClicked:");
                item.Target = this;
                item.Tag    = unchecked ((int)opt.ToUnsignedArgb());
                menu.AddItem(item);
            }
            NSMenu.PopUpContextMenu(menu, changeColorNSEvent, changeColorLinkLabel);
        }
コード例 #4
0
        partial void SettingsButtonClick(NSObject sender)
        {
            launch.State  = (NSUserDefaults.StandardUserDefaults.BoolForKey("LaunchLogin")) ? NSCellStateValue.On : NSCellStateValue.Off;
            artwork.State = (NSUserDefaults.StandardUserDefaults.BoolForKey("BackgroundArtwork")) ? NSCellStateValue.On : NSCellStateValue.Off;

            NSMenu.PopUpContextMenu(settingsMenu, NSApplication.SharedApplication.CurrentEvent, sender as NSView);
        }
コード例 #5
0
ファイル: VMDirTableView.cs プロジェクト: wfu8/lightwave
        //Handle right click event for the TableView
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            NSMenu menu = new NSMenu();

            NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
            return(base.MenuForEvent(theEvent));
        }
コード例 #6
0
        public void Popup()
        {
            Refresh();
            var evt = NSApplication.SharedApplication.CurrentEvent;

            NSMenu.PopUpContextMenu(NativeMenu, evt, CommonWindow.Current.NSGameView);
        }
コード例 #7
0
ファイル: MacPlatform.cs プロジェクト: pzsysa/monodevelop
        public override bool ShowContextMenu(CommandManager commandManager, Gtk.Widget widget, double x, double y, CommandEntrySet entrySet, object initialCommandTarget = null)
        {
            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     = new MDMenu(commandManager, entrySet, CommandSource.ContextMenu, initialCommandTarget);
                var nsview   = MacInterop.GtkQuartz.GetView(widget);
                var toplevel = widget.Toplevel as Gtk.Window;
                int trans_x, trans_y;
                widget.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 PointF((float)trans_x, (float)trans_y);
                int w, h;
                toplevel.GetSize(out w, out h);
                pt.Y = h - pt.Y;

                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   MacInterop.GtkQuartz.GetWindow(toplevel).WindowNumber,
                                                   null, 0, 0, 0);

                NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
            });

            return(true);
        }
コード例 #8
0
        public static void ShowContextMenu(NSView parent, int x, int y, NSMenu menu, bool selectFirstItem = false)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            var pt = parent.ConvertPointToView(new CoreGraphics.CGPoint(x, y), null);

            if (selectFirstItem)
            {
                menu.PopUpMenu(menu.ItemAt(0), pt, parent);
            }
            else
            {
                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   parent.Window.WindowNumber,
                                                   null, 0, 0, 0);
                NSMenu.PopUpContextMenu(menu, tmp_event, parent);
            }
        }
コード例 #9
0
        //Handle right click event for the TableView
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            CGPoint pt = this.ConvertPointFromView(theEvent.LocationInWindow, null);

            _selectedRow = this.GetRow(pt);
            NSTableViewDataSource ds = (NSTableViewDataSource)this.DataSource;
            NSMenu menu = new NSMenu();

            if (_selectedRow >= (nint)0)
            {
                if (ds is NodesListView)
                {
                    DirectoryNode node = ((ds as NodesListView).Entries [(int)_selectedRow] as DirectoryNode);
                    if (node != null)
                    {
                        if (node.NodeType == DirectoryNode.DirectoryNodeType.User)
                        {
                            NSMenuItem ResetPassword = new NSMenuItem("Set Password", node.RestUserPassword);
                            menu.AddItem(ResetPassword);
                            NSMenuItem delete = new NSMenuItem("Delete", node.Delete);
                            menu.AddItem(delete);
                            NSMenuItem Properties = new NSMenuItem("Properties", node.ViewProperties);
                            menu.AddItem(Properties);
                        }
                        else if (node.NodeType == DirectoryNode.DirectoryNodeType.Groups)
                        {
                            NSMenuItem addUser = new NSMenuItem("Add user to group", node.AddUserToGroup);
                            menu.AddItem(addUser);
                        }
                    }
                }
            }
            NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
            return(base.MenuForEvent(theEvent));
        }
コード例 #10
0
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            CGPoint pt = this.ConvertPointFromView(theEvent.LocationInWindow, null);

            selectedRow = this.GetRow(pt);
            NSTableViewDataSource ds = (NSTableViewDataSource)this.DataSource;
            NSMenu menu = new NSMenu();

            if (selectedRow >= (nint)0)
            {
                if (ds is ZoneDetailsListView)
                {
                    VMDNSZoneEntryNode zone       = (ds as ZoneDetailsListView).Entries[(int)SelectedRow] as VMDNSZoneEntryNode;
                    NSMenuItem         properties = new NSMenuItem(VMDNSConstants.ZONE_PROPERTIES, zone.OnClickZoneProperties);
                    menu.AddItem(properties);
                }
                else if (ds is DnsRecordListView)
                {
                    VMDNSZoneEntryNode zoneNode = (ds as DnsRecordListView).ZoneNode;
                    if (zoneNode != null)
                    {
                        VmDnsRecord record     = (ds as DnsRecordListView).Entries[(int)selectedRow];
                        NSMenuItem  properties = new NSMenuItem(VMDNSConstants.RECORD_PROPERTIES, (sender, e) => zoneNode.ShowRecordProperties(sender, e, record));
                        menu.AddItem(properties);
                        NSMenuItem deleteRecord = new NSMenuItem(VMDNSConstants.RECORD_DELETE, (sender, e) => zoneNode.DeleteRecord(sender, e, record));
                        menu.AddItem(deleteRecord);
                    }
                }
            }
            NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
            return(base.MenuForEvent(theEvent));
        }
コード例 #11
0
        private void PopUpContextMenu()
        {
            if (this.popUpContextMenu == null)
            {
                this.popUpContextMenu = new NSMenu();

                if (this.viewModel.TargetPlatform.SupportsCustomExpressions)
                {
                    var mi = new NSMenuItem(Properties.Resources.CustomExpressionEllipsis)
                    {
                        AttributedTitle = new Foundation.NSAttributedString(
                            Properties.Resources.CustomExpressionEllipsis,
                            new CoreText.CTStringAttributes {
                            Font = new CoreText.CTFont(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
                        })
                    };

                    mi.Activated += OnCustomExpression;

                    this.popUpContextMenu.AddItem(mi);
                    this.popUpContextMenu.AddItem(NSMenuItem.SeparatorItem);
                }

                if (this.viewModel.SupportsResources)
                {
                    this.popUpContextMenu.AddItem(NSMenuItem.SeparatorItem);

                    var mi2 = new NSMenuItem(Properties.Resources.ResourceEllipsis)
                    {
                        AttributedTitle = new Foundation.NSAttributedString(
                            Properties.Resources.ResourceEllipsis,
                            new CoreText.CTStringAttributes {
                            Font = new CoreText.CTFont(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
                        })
                    };

                    mi2.Activated += OnResourceRequested;
                    this.popUpContextMenu.AddItem(mi2);
                }

                this.popUpContextMenu.AddItem(NSMenuItem.SeparatorItem);

                // TODO If we add more menu items consider making the Label/Command a dictionary that we can iterate over to populate everything.
                this.popUpContextMenu.AddItem(new CommandMenuItem(Properties.Resources.Reset, viewModel.ClearValueCommand)
                {
                    AttributedTitle = new Foundation.NSAttributedString(
                        Properties.Resources.Reset,
                        new CoreText.CTStringAttributes {
                        Font = new CoreText.CTFont(PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
                    })
                });
            }

            var menuOrigin = this.Superview.ConvertPointToView(new CGPoint(Frame.Location.X - 1, Frame.Location.Y + Frame.Size.Height + 4), null);

            var popupMenuEvent = NSEvent.MouseEvent(NSEventType.LeftMouseDown, menuOrigin, (NSEventModifierMask)0x100, 0, this.Window.WindowNumber, this.Window.GraphicsContext, 0, 1, 1);

            NSMenu.PopUpContextMenu(popUpContextMenu, popupMenuEvent, this);
        }
コード例 #12
0
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            CGPoint pt = this.ConvertPointFromView(theEvent.LocationInWindow, null);

            _selectedRow = this.GetRow(pt);
            NSTableViewDataSource ds = (NSTableViewDataSource)this.DataSource;
            NSMenu menu = new NSMenu();

            if (_selectedRow >= (nint)0)
            {
                if (ds is NodesListView)
                {
                    string data = (ds as NodesListView).Entries [(int)_selectedRow].DisplayName;
                    switch (data)
                    {
                    case "Private Entities":
                        NSMenuItem addPrivateEntity = new NSMenuItem("Add Private Entity", ((ds as NodesListView).Entries [(int)_selectedRow] as VecsPrivateKeysNode).AddPrivateKeyHandler);
                        menu.AddItem(addPrivateEntity);
                        break;

                    case "Secret Keys":
                        NSMenuItem createCertificate = new NSMenuItem("Add Secret Key", ((ds as NodesListView).Entries [(int)_selectedRow] as VecsSecretKeysNode).AddSecretKey);
                        menu.AddItem(createCertificate);
                        break;

                    case "Trusted Certs":
                        NSMenuItem createSigningRequest = new NSMenuItem("Create Certificate", ((ds as NodesListView).Entries [(int)_selectedRow] as VecsTrustedCertsNode).AddCertificate);
                        menu.AddItem(createSigningRequest);
                        break;

                    default:
                        break;
                    }
                }
                else if (ds is CertificateDetailsListView)
                {
                    CertificateDetailsListView lw = ds as CertificateDetailsListView;
                    CertDTO    cert     = lw.Entries [(int)_selectedRow];
                    NSMenuItem showCert = new NSMenuItem("Show Certificate", (object sender, EventArgs e) => CertificateService.DisplayX509Certificate2(this, cert.Cert));
                    menu.AddItem(showCert);
                    NSMenuItem deleteEntry = new NSMenuItem("Delete", (object sender, EventArgs e) => {
                        UIErrorHelper.CheckedExec(delegate() {
                            if (UIErrorHelper.ConfirmDeleteOperation("Are you sure?") == true)
                            {
                                using (var session = new VecsStoreSession(lw.ServerDto.VecsClient, lw.Store, "")) {
                                    session.DeleteCertificate(cert.Alias);
                                }
                                lw.Entries.Remove(cert);
                                UIErrorHelper.ShowAlert("", "Successfully deleted the entry.");
                                NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadServerData", this);
                            }
                        });
                    });
                    menu.AddItem(deleteEntry);
                }
                NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
            }
            return(base.MenuForEvent(theEvent));
        }
コード例 #13
0
        public void Popup()
        {
            // Repaint windows since some actions (e.g. selecting a widget) should be taken before showing the context menu.
            UpdateAndRenderAllWindows();
            Refresh();
            var evt = NSApplication.SharedApplication.CurrentEvent;

            NSMenu.PopUpContextMenu(NativeMenu, evt, CommonWindow.Current.NSGameView);
        }
コード例 #14
0
        partial void clickActionButton(NSObject sender)
        {
            var currEvent = NSApplication.SharedApplication.CurrentEvent;

            if (currEvent != null)
            {
                NSMenu.PopUpContextMenu(configurationMenu, currEvent, this.View);
            }
        }
コード例 #15
0
        public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu, bool selectFirstItem = false)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            parent.GrabFocus();

            Gtk.Application.Invoke((o, args) => {
                // 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 nsview   = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent);
                var toplevel = parent.Toplevel as Gtk.Window;

                var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel);

                int titleBarOffset;
                if (toplevel.TypeHint == Gdk.WindowTypeHint.Toolbar && toplevel.Type == Gtk.WindowType.Toplevel && toplevel.Decorated == false)
                {
                    // Undecorated toplevel toolbars are used for auto-hide pad windows. Don't add a titlebar offset for them.
                    titleBarOffset = 0;
                }
                else if (MonoDevelop.Ide.DesktopService.GetIsFullscreen(toplevel))
                {
                    titleBarOffset = 0;
                }
                else
                {
                    titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight() + 12;
                }

                parent.TranslateCoordinates(parent.Toplevel, x, y, out x, out y);

                if (selectFirstItem)
                {
                    var pt          = new CoreGraphics.CGPoint(x, y);
                    lastOpenPositon = pt;
                    menu.PopUpMenu(menu.ItemAt(0), pt, nsview);
                }
                else
                {
                    var pt          = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarOffset);
                    lastOpenPositon = pt;
                    var tmp_event   = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                         pt,
                                                         0, 0,
                                                         nswindow.WindowNumber,
                                                         null, 0, 0, 0);
                    NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
                }
            });
        }
コード例 #16
0
        public override void RightMouseUp(NSEvent theEvent)
        {
            var menu = Microsoft.Maui.Controls.Compatibility.Element.GetMenu(Element);

            if (menu != null && NativeView != null)
            {
                NSMenu.PopUpContextMenu(menu.ToNSMenu(), theEvent, NativeView);
            }

            base.RightMouseUp(theEvent);
        }
コード例 #17
0
        public override void RightMouseUp(NSEvent theEvent)
        {
            var menu = Xamarin.Forms.Element.GetMenu(Element);

            if (menu != null && NativeView != null)
            {
                NSMenu.PopUpContextMenu(menu.ToNSMenu(), theEvent, NativeView);
            }

            base.RightMouseUp(theEvent);
        }
コード例 #18
0
ファイル: OutlineView.cs プロジェクト: muaazsalagar/lightwave
        //Right click menu event for the outlineview.
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            int row = (int)this.SelectedRow;

            if (row >= (nint)0)
            {
                NSObject obj = this.ItemAtRow(row);
                if (obj != null)
                {
                    NSMenu menu = new NSMenu();
                    if (obj is DirectoryNode)
                    {
                        DirectoryNode node = obj as DirectoryNode;

                        NSMenuItem search = new NSMenuItem("Search", node.Search);
                        menu.AddItem(search);
                        NSMenuItem fetchNextPage = new NSMenuItem("Fetch Next Page", node.FetchNextPage);
                        menu.AddItem(fetchNextPage);
                        NSMenuItem refresh = new NSMenuItem("Refresh", node.RefreshNode);
                        menu.AddItem(refresh);
                        NSMenuItem delete = new NSMenuItem("Delete", node.Delete);
                        menu.AddItem(delete);

                        if (node.ObjectClass.Contains(VMDirConstants.USER_OC))
                        {
                            menu.AddItem(NSMenuItem.SeparatorItem);
                            NSMenuItem addUsertoGroup = new NSMenuItem("Add to a Group", node.AddUserToGroup);
                            menu.AddItem(addUsertoGroup);
                            NSMenuItem resetPassword = new NSMenuItem("Reset Password", node.RestUserPassword);
                            menu.AddItem(resetPassword);
                            NSMenuItem verifyUserPassword = new NSMenuItem("Verify Password", node.VerifyUserPassword);
                            menu.AddItem(verifyUserPassword);
                        }
                        else if (node.ObjectClass.Contains(VMDirConstants.GROUP_OC))
                        {
                            menu.AddItem(NSMenuItem.SeparatorItem);
                            NSMenuItem addGrouptoGroup = new NSMenuItem("Add to a Group", node.AddUserToGroup);
                            menu.AddItem(addGrouptoGroup);
                        }
                        menu.AddItem(NSMenuItem.SeparatorItem);
                        NSMenuItem addUser = new NSMenuItem("Add User", node.AddUser);
                        menu.AddItem(addUser);
                        NSMenuItem addGroup = new NSMenuItem("Add Group", node.AddGroup);
                        menu.AddItem(addGroup);
                        NSMenuItem add = new NSMenuItem("Add Object", node.Add);
                        menu.AddItem(add);
                    }
                    NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
                }
            }
            return(base.MenuForEvent(theEvent));
        }
コード例 #19
0
        public void Popup()
        {
            var evt = NSApplication.SharedApplication.CurrentEvent;

            if (evt != null)
            {
                NSMenu.PopUpContextMenu(this, evt, evt.Window.ContentView);
            }
            else if (MainWindow?.ContentView != null)
            {
                Popup(MainWindow.ContentView, MainWindow.MouseLocationOutsideOfEventStream);
            }
        }
コード例 #20
0
ファイル: OutlineView.cs プロジェクト: syeduguri/lightwave
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            CGPoint pt  = this.ConvertPointFromView(theEvent.LocationInWindow, null);
            nint    row = this.GetRow(pt);

            if (row >= (nint)0)
            {
                NSObject obj = this.ItemAtRow(row);
                if (obj != null)
                {
                    NSMenu menu = new NSMenu();
                    if (obj is VecsStoresNode)
                    {
                        VecsStoresNode node        = obj as VecsStoresNode;
                        NSMenuItem     createStore = new NSMenuItem("Create Store", node.CreateStore);
                        menu.AddItem(createStore);
                    }
                    else if (obj is VecsPrivateKeysNode)
                    {
                        VecsPrivateKeysNode node       = obj as VecsPrivateKeysNode;
                        NSMenuItem          addPrivate = new NSMenuItem("Add Private Key", node.AddPrivateKeyHandler);
                        menu.AddItem(addPrivate);
                    }
                    else if (obj is VecsSecretKeysNode)
                    {
                        VecsSecretKeysNode node      = obj as VecsSecretKeysNode;
                        NSMenuItem         addSecret = new NSMenuItem("Add  Secret Key", node.AddSecretKey);
                        menu.AddItem(addSecret);
                    }
                    else if (obj is VecsTrustedCertsNode)
                    {
                        VecsTrustedCertsNode node = obj as VecsTrustedCertsNode;
                        NSMenuItem           createCertificate = new NSMenuItem("Add Certificate", node.AddCertificate);
                        menu.AddItem(createCertificate);
                    }
                    else if (obj is VecsStoreNode)
                    {
                        VecsStoreNode node        = obj as VecsStoreNode;
                        NSMenuItem    deleteStore = new NSMenuItem("Delete Store", node.DeleteStore);
                        //disable delete option for the following three certstores.
                        if (node.StoreName.Equals("MACHINE_SSL_CERT") || node.StoreName.Equals("TRUSTED_ROOTS") || node.StoreName.Equals("TRUSTED_ROOT_CRLS"))
                        {
                            deleteStore.Hidden = true;
                        }
                        menu.AddItem(deleteStore);
                    }
                    NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
                }
            }
            return(base.MenuForEvent(theEvent));
        }
コード例 #21
0
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            CGPoint pt  = this.ConvertPointToView(theEvent.LocationInWindow, null);
            nint    row = this.GetRow(pt);

            if (row >= (nint)0)
            {
                NSObject obj = this.ItemAtRow((int)row);
                if (obj != null)
                {
                    NSMenu menu = new NSMenu();
                    if (obj is VMCAServerNode)
                    {
                        VMCAServerNode serverNode = obj as VMCAServerNode;
                        if (serverNode.IsLoggedIn)
                        {
                            NSMenuItem getVersion = new NSMenuItem("Get Server Version", serverNode.GetServerVersion);
                            menu.AddItem(getVersion);
                            NSMenuItem showRoot = new NSMenuItem("Show Root Certificate", serverNode.ShowRootCertificate);
                            menu.AddItem(showRoot);
                            NSMenuItem addCert = new NSMenuItem("Add Root Certificate", serverNode.AddRootCertificate);
                            menu.AddItem(addCert);
                        }
                    }
                    else if (obj is VMCAKeyPairNode)
                    {
                        VMCAKeyPairNode node          = obj as VMCAKeyPairNode;
                        NSMenuItem      createKeyPair = new NSMenuItem("Create KeyPair", node.CreateKeyPair);
                        menu.AddItem(createKeyPair);
                    }
                    else if (obj is VMCACSRNode)
                    {
                        VMCACSRNode node = obj as VMCACSRNode;
                        NSMenuItem  createSigningRequest = new NSMenuItem("Create Signing Request", node.HandleSigningRequest);
                        menu.AddItem(createSigningRequest);
                    }
                    else if (obj is VMCAPersonalCertificatesNode)
                    {
                        VMCAPersonalCertificatesNode node = obj as VMCAPersonalCertificatesNode;
                        NSMenuItem createCertificate      = new NSMenuItem("Create Self Signed Certificate", node.CreateCertificate);
                        menu.AddItem(createCertificate);
                        NSMenuItem createCASingedCertificate = new NSMenuItem("Create CA Signed Certificate", node.CreateCASignedCertificate);
                        menu.AddItem(createCASingedCertificate);
                    }
                    NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
                }
            }
            return(base.MenuForEvent(theEvent));
        }
コード例 #22
0
        public static void ShowContextMenu(Gtk.Widget parent, Gdk.EventButton evt, NSMenu menu)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            parent.GrabFocus();
            int x, y;

            if (evt != null)
            {
                x = (int)evt.X;
                y = (int)evt.Y;
            }
            else
            {
                Gdk.ModifierType mod;
                parent.GdkWindow.GetPointer(out x, out y, out mod);

                var titleBarHeight = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight();
                y -= titleBarHeight;
            }

            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 nsview   = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent);
                var toplevel = parent.Toplevel as Gtk.Window;

                var screenPoint = NSEvent.CurrentMouseLocation;
                var screenRect  = new CoreGraphics.CGRect(screenPoint.X, screenPoint.Y, 0, 0);
                var nswindow    = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel);
                var rect        = nswindow.ConvertRectFromScreen(screenRect);
                var pt          = rect.Location;

                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   nswindow.WindowNumber,
                                                   null, 0, 0, 0);

                NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
            });
        }
コード例 #23
0
ファイル: DNSOutlineView.cs プロジェクト: wfu8/lightwave
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            CGPoint pt  = this.ConvertPointFromView(theEvent.LocationInWindow, null);
            nint    row = this.GetRow(pt);

            if (row >= (nint)0)
            {
                NSObject obj = this.ItemAtRow(row);
                if (obj != null)
                {
                    NSMenu menu = new NSMenu();
                    if (obj is VMDNSZoneEntryNode)
                    {
                        var        node       = obj as VMDNSZoneEntryNode;
                        NSMenuItem properties = new NSMenuItem(VMDNSConstants.ZONE_PROPERTIES, node.OnClickZoneProperties);
                        menu.AddItem(properties);
                        NSMenuItem deleteZone = new NSMenuItem(VMDNSConstants.ZONE_DELETE, node.DeleteZone);
                        menu.AddItem(deleteZone);
                        menu.AddItem(NSMenuItem.SeparatorItem);
                        NSMenuItem addRecord = new NSMenuItem(VMDNSConstants.RECORD_ADD, node.AddRecord);
                        menu.AddItem(addRecord);
                    }
                    else if (obj is VMDNSForwardZonesNode)
                    {
                        var        node     = obj as VMDNSForwardZonesNode;
                        NSMenuItem addZones = new NSMenuItem(VMDNSConstants.ZONE_ADD_FORWARD, node.AddForwardZone);
                        menu.AddItem(addZones);
                    }
                    else if (obj is VMDNSReverseZonesNode)
                    {
                        var        node     = obj as VMDNSReverseZonesNode;
                        NSMenuItem addZones = new NSMenuItem(VMDNSConstants.ZONE_ADD_REVERSE, node.AddReverseZone);
                        menu.AddItem(addZones);
                    }
                    else if (obj is VMDNSRootScopeNode)
                    {
                        var        node         = (obj as VMDNSRootScopeNode).ServerNode;
                        NSMenuItem serverConfig = new NSMenuItem(VMDNSConstants.SERVER_CONFIG, node.ViewServerConfiguration);
                        menu.AddItem(serverConfig);
                        menu.AddItem(NSMenuItem.SeparatorItem);
                        NSMenuItem refresh = new NSMenuItem(VMDNSConstants.REFRESH, node.Refresh);
                        menu.AddItem(refresh);
                    }

                    NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
                }
            }
            return(base.MenuForEvent(theEvent));
        }
コード例 #24
0
 public void Popup(IWindow window, Vector2 position, float minimumWidth, ICommand command)
 {
     Refresh();
     if (NSApplication.SharedApplication.ModalWindow != null)
     {
         // Fixme: When a container dialog is running in the modal mode, showing the menu with PopUpMenu() causes all menu items are disabled.
         // So, use PopUpContextMenu() instead as a workaround.
         var evt = NSApplication.SharedApplication.CurrentEvent;
         NSMenu.PopUpContextMenu(NativeMenu, evt, CommonWindow.Current.NSGameView);
     }
     else
     {
         NativeMenu.MinimumWidth = minimumWidth;
         NSMenuItem item = command == null ? null : items.Find(i => i.Command == command).NativeMenuItem;
         NativeMenu.PopUpMenu(item, new CoreGraphics.CGPoint(position.X, window.ClientSize.Y - position.Y), window.NSGameView);
     }
 }
コード例 #25
0
ファイル: OutlineView.cs プロジェクト: syeduguri/lightwave
        //Right click menu event for the outlineview.
        public override NSMenu MenuForEvent(NSEvent theEvent)
        {
            int row = (int)this.SelectedRow;

            if (row >= (nint)0)
            {
                NSObject obj = this.ItemAtRow(row);
                if (obj != null)
                {
                    NSMenu menu = new NSMenu();
                    if (obj is DirectoryNode)
                    {
                        DirectoryNode node = obj as DirectoryNode;
                        if (node.NodeType == DirectoryNode.DirectoryNodeType.User)
                        {
                            NSMenuItem addUsertoGroup = new NSMenuItem("Add to a Group", node.AddUserToGroup);
                            menu.AddItem(addUsertoGroup);
                            NSMenuItem resetPassword = new NSMenuItem("Set Password", node.RestUserPassword);
                            menu.AddItem(resetPassword);
                        }
                        else if (node.NodeType == DirectoryNode.DirectoryNodeType.Groups)
                        {
                            NSMenuItem addGrouptoGroup = new NSMenuItem("Add to a Group", node.AddUserToGroup);
                            menu.AddItem(addGrouptoGroup);
                        }
                        else
                        {
                            NSMenuItem addUser = new NSMenuItem("Add User", node.AddUser);
                            menu.AddItem(addUser);
                            NSMenuItem addGroup = new NSMenuItem("Add Group", node.AddGroup);
                            menu.AddItem(addGroup);
                            NSMenuItem add = new NSMenuItem("Add Object", node.Add);
                            menu.AddItem(add);
                        }
                        NSMenuItem delete = new NSMenuItem("Delete", node.Delete);
                        menu.AddItem(delete);
                        NSMenuItem properties = new NSMenuItem("Properties", node.ViewProperties);
                        menu.AddItem(properties);
                        NSMenuItem refresh = new NSMenuItem("Refresh", node.RefreshNode);
                        menu.AddItem(refresh);
                    }
                    NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView);
                }
            }
            return(base.MenuForEvent(theEvent));
        }
コード例 #26
0
ファイル: CellNSView.cs プロジェクト: terrajobst/maui
        void HandleContextActions(NSEvent theEvent)
        {
            var contextActionCell   = this.Element as Cell;
            var contextActionsCount = contextActionCell.ContextActions.Count;

            if (contextActionsCount > 0)
            {
                NSMenu menu = new NSMenu();
                for (int i = 0; i < contextActionsCount; i++)
                {
                    var contextAction = contextActionCell.ContextActions[i];
                    var nsMenuItem    = contextAction.ToNSMenuItem(i);
                    menu.AddItem(nsMenuItem);
                }

                NSMenu.PopUpContextMenu(menu, theEvent, this);
            }
        }
コード例 #27
0
        void HandleContextActions(NSEvent theEvent)
        {
            var contextActionCell   = (Superview as INativeElementView).Element as Cell;
            var contextActionsCount = contextActionCell.ContextActions.Count;

            if (contextActionsCount > 0)
            {
                NSMenu menu = new NSMenu();
                for (int i = 0; i < contextActionsCount; i++)
                {
                    var contextAction = contextActionCell.ContextActions[i];
                    var nsMenuItem    = GetNSMenuItem(i, contextAction);
                    menu.AddItem(nsMenuItem);
                }

                NSMenu.PopUpContextMenu(menu, theEvent, this);
            }
        }
コード例 #28
0
        public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            parent.GrabFocus();

            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 nsview   = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent);
                var toplevel = parent.Toplevel as Gtk.Window;

                var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel);

                int titleBarOffset;
                if (toplevel.TypeHint == Gdk.WindowTypeHint.Toolbar && toplevel.Type == Gtk.WindowType.Toplevel && toplevel.Decorated == false)
                {
                    // Undecorated toplevel toolbars are used for auto-hide pad windows. Don't add a titlebar offset for them.
                    titleBarOffset = 0;
                }
                else
                {
                    titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight() + 12;
                }

                var pt = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarOffset);

                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   nswindow.WindowNumber,
                                                   null, 0, 0, 0);

                NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
            });
        }
コード例 #29
0
        public static void ShowContextMenu(NSView parent, int x, int y, NSMenu menu, bool selectFirstItem = false)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            var pt = parent.ConvertPointToView(new CoreGraphics.CGPoint(x, y), null);

            if (selectFirstItem)
            {
                menu.PopUpMenu(menu.ItemAt(0), pt, parent);
            }
            else
            {
                var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                   pt,
                                                   0, 0,
                                                   parent.Window.WindowNumber,
                                                   null, 0, 0, 0);

                // the following lines are here to dianose & fix VSTS 1026106 - we were getting
                // a SigSegv from here and it is likely caused by NSEvent being null, however
                // it's worth leaving Debug checks in just to be on the safe side
                if (tmp_event == null)
                {
                    // since this is often called outside of a try/catch loop, we'll just
                    // log an error and not throw the exception
                    LoggingService.LogInternalError(new ArgumentNullException(nameof(tmp_event)));
                    return;
                }

                System.Diagnostics.Debug.Assert(parent != null, "Parent was modified (set to null) during execution.");
                System.Diagnostics.Debug.Assert(menu != null, "Menu was modified (set to null) during execution.");

                NSMenu.PopUpContextMenu(menu, tmp_event, parent);
            }
        }
コード例 #30
0
        public void Show(Control relativeTo, PointF?location)
        {
            var view = relativeTo?.GetContainerView();

            if (location != null || view == null)
            {
                CGPoint cglocation;
                if (view != null && location != null)
                {
                    cglocation = location.Value.ToNS();
                    if (!view.IsFlipped)
                    {
                        cglocation.Y = view.Frame.Height - cglocation.Y;
                    }
                }
                else
                {
                    cglocation = (location ?? Mouse.Position).ToNS();
                    var origin = NSScreen.Screens[0].Frame.Bottom;
                    cglocation.Y = origin - cglocation.Y;
                }

                Control.PopUpMenu(null, cglocation, view);
            }
            else
            {
                NSEvent nsevent = NSApplication.SharedApplication.CurrentEvent;
                if (nsevent == null)
                {
                    var keyWindow     = NSApplication.SharedApplication.KeyWindow;
                    var mouseLocation = NSEvent.CurrentMouseLocation;
                    mouseLocation = keyWindow.ConvertScreenToBase(mouseLocation);

                    var time         = DateTime.Now.ToOADate();
                    var windowNumber = keyWindow.WindowNumber;

                    nsevent = NSEvent.MouseEvent(NSEventType.RightMouseDown, mouseLocation, 0, time, windowNumber, null, 0, 0, 0.1f);
                }

                NSMenu.PopUpContextMenu(Control, nsevent, view);
            }
        }