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); menu.PopUpMenu(menu.ItemAt(0), pt, nsview); } else { 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); } }); }
int FindMeInParent(NSMenu parent) { for (int n = 0; n < parent.Count; n++) { if (parent.ItemAt(n) == this) { return(n); } } return(-1); }
protected override void SetupMainAppMenu(NSMenu nativeMenu) { base.SetupMainAppMenu(nativeMenu); // reorder menu items - it can be needed if we add submenus as they are added after simple items var appMenu = nativeMenu.ItemAt(0); var testMenuItem = appMenu.Submenu.Items.Last(); appMenu.Submenu.RemoveItem(testMenuItem); appMenu.Submenu.InsertItem(testMenuItem, 0); }
void SetHelpMenuEnable(bool isEnable) { NSMenu sysmenu = NSApplication.SharedApplication.MainMenu; NSMenuItem subMenuItem = sysmenu.ItemAt(5); NSMenu subMenu = subMenuItem.Submenu; subMenu.AutoEnablesItems = false; //FAQ NSMenuItem subItem = subMenu.ItemAt(0); subItem.Enabled = isEnable; //ContactUs subItem = subMenu.ItemAt(1); subItem.Enabled = isEnable; //other subItem = subMenu.ItemAt(2); subItem.Hidden = true; }
void SetViewFontMenuEnable(bool isEnable, bool isHide) { NSMenu sysmenu = NSApplication.SharedApplication.MainMenu; // NSMenuItem subMenuItem = sysmenu.ItemAt(3); NSMenu subMenu = subMenuItem.Submenu; subMenu.AutoEnablesItems = false; //actual size NSMenuItem subItem = subMenu.ItemAt(0); subItem.Enabled = isEnable; //Console.WriteLine ("title:{0}:{1}",subItem.Title, subItem.Enabled); //zoom text in subItem = subMenu.ItemAt(1); subItem.Enabled = isMaxFontSize == true?false:isEnable; //zoom text out subItem = subMenu.ItemAt(2); subItem.Enabled = isMiniFontSize == true?false:isEnable; //orgnize publications subItem = subMenu.ItemAt(4); bool isItemEnable = false; if (isHide) { isItemEnable = false; } else { isItemEnable = !isEnable; } subItem.Enabled = isItemEnable; }
void SetLogOutMenuHide(bool isHidden) { NSMenu sysmenu = NSApplication.SharedApplication.MainMenu; sysmenu.AutoEnablesItems = false; // NSMenuItem subMenuItem = sysmenu.ItemAt(0); NSMenu subMenu = subMenuItem.Submenu; //Log Out LNRed NSMenuItem subItem = subMenu.ItemAt(4); subItem.Hidden = isHidden; subItem.Enabled = !isHidden; }
void Update(NSMenu menu, NSMenuItem parentItem, IEditor editor) { for (nint i = 0, n = menu.Count; i < n; i++) { var item = menu.ItemAt(i); if (item.HasSubmenu) { Update(item.Submenu, item, editor); item.Hidden = !HasVisibleMenuItems(item, true); } else { (item as XIEditorMenuItem)?.Bind(editor); } } }
/* * private void SetEditMenuStatus () * { * NSUserDefaults.StandardUserDefaults.SetBool (true, "NSDisabledStartDictationMenuItem"); * NSUserDefaults.StandardUserDefaults.SetBool (true, "NSDisabledEmojiSymbolsMenuItem"); * } */ void SetFileMenuEnable(bool isEnable) { NSMenu sysmenu = NSApplication.SharedApplication.MainMenu; //file menu NSMenuItem subMenuItem = sysmenu.ItemAt(1); NSMenu subMenu = subMenuItem.Submenu; subMenu.AutoEnablesItems = false; //New NSMenuItem subItem = subMenu.ItemAt(0); subItem.Enabled = isEnable; //Open subItem = subMenu.ItemAt(1); subItem.Enabled = isEnable; //Open Recent subItem = subMenu.ItemAt(2); subItem.Enabled = isEnable; //Close subItem = subMenu.ItemAt(4); subItem.Enabled = isEnable; subItem = subMenu.ItemAt(5); subItem.Enabled = isEnable; //Save as PDF - Document subItem = subMenu.ItemAt(6); //Console.WriteLine ("title:{0}",subItem.Title); //subItem.Hidden = !isEnable; subItem.Enabled = isEnable; //Page Setup... subItem = subMenu.ItemAt(9); subItem.Enabled = isEnable; //Page Print... subItem = subMenu.ItemAt(10); subItem.Enabled = isEnable; }
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); } }
void SetEditMenuStatus() { NSMenu sysmenu = NSApplication.SharedApplication.MainMenu; //Edit menu NSMenuItem subMenuItem = sysmenu.ItemAt(2); NSMenu subMenu = subMenuItem.Submenu; NSMenuItem [] itemArray = subMenu.ItemArray(); for (int i = 0; i < itemArray.Length; i++) { //Console.WriteLine ("{0}",itemArray [i].Title); if (itemArray [i].Title == "Start Dictation…") { itemArray [i].Hidden = true; } if (itemArray [i].Title == "Emoji & Symbols") { itemArray [i].Hidden = true; } } }
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 (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 if (MonoDevelop.Ide.DesktopService.GetIsFullscreen (toplevel)) { titleBarOffset = 0; } else { titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight () + 12; } if (selectFirstItem) { var pt = new CoreGraphics.CGPoint (x, y); menu.PopUpMenu (menu.ItemAt (0), pt, nsview); } else { 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); } }); }
public override void DidFinishLaunching(NSNotification notification) { // Handle CMD-Q NSMenu mainMenu = NSApplication.SharedApplication.MainMenu = new NSMenu("Exception marshaling"); mainMenu.AddItem("Sub", new ObjCRuntime.Selector("sub"), "S"); var subMenu = new NSMenu("Sub"); var quit = new NSMenuItem("Quit", (sender, e) => { NSApplication.SharedApplication.Terminate(this); }); quit.Enabled = true; quit.KeyEquivalent = "q"; quit.KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask; subMenu.AddItem(quit); mainMenu.AutoEnablesItems = false; mainMenu.SetSubmenu(subMenu, mainMenu.ItemAt(0)); // Create main window and its UI window = new NSWindow(new CGRect(0, 0, 500, 500), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable, NSBackingStore.Buffered, true); window.Title = "Exception marshaling"; var protoCell = new NSButtonCell(); protoCell.SetButtonType(NSButtonType.Radio); var cellSize = new CGSize(300, 25); var boxSize = new CGSize(300, 400); var managedBox = new NSBox(new CGRect(new CGPoint(0, 0), boxSize)); var objectiveCBox = new NSBox(new CGRect(new CGPoint(managedBox.Frame.Right, managedBox.Frame.Y), boxSize)); var throwManagedException = new NSButton(new CGRect((boxSize.Width - 200) / 2, 0, 200, cellSize.Height)); throwManagedException.Title = "Throw managed exception"; var marshalManagedModeMatrix = new NSMatrix(new CGRect(0, 0, managedBox.Frame.Width, cellSize.Height * 6 + 10), NSMatrixMode.Radio, protoCell, 6, 1); marshalManagedModeMatrix.Cells [0].Title = "None"; marshalManagedModeMatrix.Cells [1].Title = "Default"; marshalManagedModeMatrix.Cells [2].Title = "Unwind native code"; marshalManagedModeMatrix.Cells [3].Title = "Throw Objective-C exception"; marshalManagedModeMatrix.Cells [4].Title = "Abort"; marshalManagedModeMatrix.Cells [5].Title = "Disable"; marshalManagedModeMatrix.CellSize = cellSize; var marshalManagedMode = new NSBox(new CGRect(0, throwManagedException.Frame.Bottom + 20, marshalManagedModeMatrix.Frame.Width, marshalManagedModeMatrix.Frame.Height + cellSize.Height)); marshalManagedMode.Title = "Marshaling mode"; marshalManagedMode.AddSubview(marshalManagedModeMatrix); var threadManagedMatrix = new NSMatrix(new CGRect(0, 0, managedBox.Frame.Width, cellSize.Height * 3 + 10), NSMatrixMode.Radio, protoCell, 3, 1); threadManagedMatrix.Cells [0].Title = "Main thread"; threadManagedMatrix.Cells [1].Title = "Background thread"; threadManagedMatrix.Cells [2].Title = "Threadpool thread"; threadManagedMatrix.CellSize = cellSize; var threadManaged = new NSBox(new CGRect(new CGPoint(0, marshalManagedMode.Frame.Bottom + 20), new CGSize(threadManagedMatrix.Frame.Width, threadManagedMatrix.Frame.Height + cellSize.Height))); threadManaged.Title = "Thread"; threadManaged.AddSubview(threadManagedMatrix); var marshalObjectiveCModeMatrix = new NSMatrix(marshalManagedModeMatrix.Frame, NSMatrixMode.Radio, protoCell, 6, 1); marshalObjectiveCModeMatrix.Cells [0].Title = "None"; marshalObjectiveCModeMatrix.Cells [1].Title = "Default"; marshalObjectiveCModeMatrix.Cells [2].Title = "Unwind managed code"; marshalObjectiveCModeMatrix.Cells [3].Title = "Throw managed exception"; marshalObjectiveCModeMatrix.Cells [4].Title = "Abort"; marshalObjectiveCModeMatrix.Cells [5].Title = "Disable"; marshalObjectiveCModeMatrix.CellSize = cellSize; var marshalObjectiveCMode = new NSBox(marshalManagedMode.Frame); marshalObjectiveCMode.Title = "Marshaling mode"; marshalObjectiveCMode.AddSubview(marshalObjectiveCModeMatrix); var threadObjectiveCMatrix = new NSMatrix(threadManagedMatrix.Frame, threadManagedMatrix.Mode, threadManagedMatrix.Prototype, threadManagedMatrix.Rows, threadManagedMatrix.Columns); threadObjectiveCMatrix.Cells [0].Title = "Main thread"; threadObjectiveCMatrix.Cells [1].Title = "Background thread"; threadObjectiveCMatrix.Cells [2].Title = "Threadpool thread"; threadObjectiveCMatrix.CellSize = cellSize; var threadObjectiveC = new NSBox(threadManaged.Frame); threadObjectiveC.Title = "Thread"; threadObjectiveC.AddSubview(threadObjectiveCMatrix); var throwObjectiveCException = new NSButton(throwManagedException.Frame); throwObjectiveCException.Title = "Throw Objective-C exception"; managedBox.Title = "Managed exception"; managedBox.AddSubview(throwManagedException); managedBox.AddSubview(threadManaged); managedBox.AddSubview(marshalManagedMode); managedBox.Frame = new CGRect(managedBox.Frame.X, managedBox.Frame.Y, managedBox.Frame.Width, threadManaged.Frame.Bottom + cellSize.Height); //managedBox.SetBoundsSize (new CGSize (managedBox.Bounds.Width, threadManaged.Frame.Bottom)); window.ContentView.AddSubview(managedBox); objectiveCBox.Title = "Objective-C exception"; objectiveCBox.AddSubview(throwObjectiveCException); objectiveCBox.AddSubview(threadObjectiveC); objectiveCBox.AddSubview(marshalObjectiveCMode); objectiveCBox.Frame = new CGRect(objectiveCBox.Frame.Location, managedBox.Frame.Size); window.ContentView.AddSubview(objectiveCBox); var windowContentSize = new CGSize(managedBox.Frame.Width + objectiveCBox.Frame.Width, Math.Max(managedBox.Frame.Height, objectiveCBox.Frame.Height)); window.SetContentSize(windowContentSize); window.ContentMinSize = windowContentSize; window.Center(); window.MakeKeyAndOrderFront(window); Action setModes = () => { if (marshalManagedModeMatrix.SelectedRow == 0) { Exceptions.ManagedExceptionMode = null; } else { Exceptions.ManagedExceptionMode = (MarshalManagedExceptionMode)(int)marshalManagedModeMatrix.SelectedRow - 1; } if (marshalObjectiveCModeMatrix.SelectedRow == 0) { Exceptions.ObjectiveCExceptionMode = null; } else { Exceptions.ObjectiveCExceptionMode = (MarshalObjectiveCExceptionMode)(int)marshalObjectiveCModeMatrix.SelectedRow - 1; } }; throwObjectiveCException.Activated += (sender, e) => { setModes(); Exceptions.ThrowObjectiveCException((ThreadMode)(int)threadObjectiveCMatrix.SelectedRow); }; throwManagedException.Activated += (sender, e) => { setModes(); Exceptions.ThrowManagedException((ThreadMode)(int)threadManagedMatrix.SelectedRow); }; }