//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); }
public override void DidFinishLaunching (NSNotification notification) { var menu = new NSMenu (); var menuItem = new NSMenuItem (); menu.AddItem (menuItem); var appMenu = new NSMenu (); var quitItem = new NSMenuItem ("Quit", "q", (s, e) => NSApplication.SharedApplication.Terminate (menu)); appMenu.AddItem (quitItem); menuItem.Submenu = appMenu; NSApplication.SharedApplication.MainMenu = menu; m_window = new NSWindow ( new CGRect (0, 0, 1024, 720), NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.TexturedBackground, NSBackingStore.Buffered, false) { Title = "Bluebird WkBrowser", ReleasedWhenClosed = false, ContentMinSize = new CGSize (1024, 600), CollectionBehavior = NSWindowCollectionBehavior.FullScreenPrimary }; m_window.Center (); m_window.MakeKeyAndOrderFront (null); var viewController = new ViewController (); m_window.ContentView = viewController.View; m_window.ContentViewController = viewController; viewController.View.Frame = m_window.ContentView.Bounds; }
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); }); }
public override void NeedsUpdate (NSMenu menu) { // Get list of menu items NSMenuItem[] Items = menu.ItemArray (); // Get the key window and determine if the required images are available var window = NSApplication.SharedApplication.KeyWindow as MainWindow; var hasImage = (window != null) && (window.Image != null); var hasImageOnPasteboard = (window != null) && window.Document.ImageAvailableOnPasteboard; // Process every item in the menu foreach(NSMenuItem item in Items) { // Take action based on the menu title switch (item.Title) { case "Cut": case "Copy": case "Delete": // Only enable if there is an image in the view item.Enabled = hasImage; break; case "Paste": // Only enable if there is an image on the pasteboard item.Enabled = hasImageOnPasteboard; break; default: // Only enable the item if it has a sub menu item.Enabled = item.HasSubmenu; break; } } }
public override void AwakeFromNib () { base.AwakeFromNib (); var n = new NSMenu ("Open"); n.AutoEnablesItems = false; }
public static void ShowContextMenu (Gtk.Widget parent, Gdk.EventButton evt, NSMenu menu) { int x, y; parent.TranslateCoordinates (parent.Toplevel, (int)evt.X, (int)evt.Y, out x, out y); ShowContextMenu (parent, x, y, menu); }
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); }
public override void DidFinishLaunching(NSNotification notification) { var menu = new NSMenu(); var menuItem = new NSMenuItem(); menu.AddItem(menuItem); var appMenu = new NSMenu(); var quitItem = new NSMenuItem("Quit " + NSProcessInfo.ProcessInfo.ProcessName, "q", (s, e) => NSApplication.SharedApplication.Terminate(menu)); appMenu.AddItem(quitItem); menuItem.Submenu = appMenu; NSApplication.SharedApplication.MainMenu = menu; mainWindowController = new MainWindowController(); mainWindowController.Window.MakeKeyAndOrderFront(this); }
public MDServicesMenuItem () { Title = GettextCatalog.GetString ("Services"); var sub = NSApplication.SharedApplication.ServicesMenu; if (sub == null) { sub = new NSMenu (); NSApplication.SharedApplication.ServicesMenu = sub; } else { foreach (var m in sub.Supermenu.ItemArray ()) { if (m.Submenu == sub) { m.Submenu = new NSMenu (); break; } } } Submenu = sub; }
public override void DidFinishLaunching(NSNotification notification) { var version = "1.0.0"; var appName = "Lotta love for the Windows Apps user group!"; Xamarin.Insights.Initialize(Core.Keys.XamarinInsightsKey, version, appName, null); var menu = new NSMenu(); var menuItem = new NSMenuItem(); menu.AddItem(menuItem); var appMenu = new NSMenu(); var quitItem = new NSMenuItem("Quit " + NSProcessInfo.ProcessInfo.ProcessName, "q", (s, e) => NSApplication.SharedApplication.Terminate(menu)); appMenu.AddItem(quitItem); menuItem.Submenu = appMenu; NSApplication.SharedApplication.MainMenu = menu; }
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 FinishedLaunching (NSObject notification) { plotWindowController = new PlotWindowController (); var menu = new NSMenu (); var appMenu = new NSMenu (); appMenu.AddItem (new NSMenuItem ("Next example", "n", (s, e) => this.NextExample (1))); appMenu.AddItem (new NSMenuItem ("Previous example", "p", (s, e) => this.NextExample (-1))); appMenu.AddItem (NSMenuItem.SeparatorItem); appMenu.AddItem (new NSMenuItem ("Quit", "q", (s, e) => NSApplication.SharedApplication.Terminate (menu))); menu.AddItem (new NSMenuItem { Submenu = appMenu }); var fileMenu = new NSMenu ("File"); fileMenu.AddItem (new NSMenuItem ("Export", "e")); menu.AddItem (new NSMenuItem { Submenu = fileMenu }); var editMenu = new NSMenu ("Edit"); editMenu.AddItem (new NSMenuItem ("Copy", "c")); menu.AddItem (new NSMenuItem { Submenu = editMenu }); var examplesMenu = new NSMenu ("Examples"); exampleList = Examples.GetList (); var categories = exampleList.Select (e => e.Category).Distinct ().OrderBy (c => c).ToArray (); var categoryMenus = new Dictionary<string,NSMenu> (); foreach (var category in categories) { var categoryMenu = new NSMenu (category); examplesMenu.AddItem (new NSMenuItem (category) { Submenu = categoryMenu }); categoryMenus.Add (category, categoryMenu); } foreach (var example in exampleList) { var item = new NSMenuItem (example.Title, (s, e) => this.SetExample (example)); var categoryMenu = categoryMenus [example.Category]; categoryMenu.AddItem (item); } menu.AddItem (new NSMenuItem { Submenu = examplesMenu }); this.SetExample (exampleList.First ()); plotWindowController.Window.MakeKeyAndOrderFront (this); NSApplication.SharedApplication.MainMenu = menu; }
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); }); }
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); }
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; }
public void Show(Control control, Point pos) { if (control == null) { throw new ArgumentException(); } src_control = control; OnPopup(EventArgs.Empty); //m_view.RemoveAllItems(); //m_view.InsertItem("beep",null,"",0); NSPoint _pos = new NSPoint(pos.X, pos.Y); var point = control.m_view.ConvertPointToBase(_pos); NSMenu.PopUpContextMenu(m_view, NSEvent.MouseEvent(NSEventType.LeftMouseUp, point, NSEventModifierMask.Shift, 0, NSApplication.SharedApplication.MainWindow.WindowNumber, new NSGraphicsContext(), 0, 1, 1f), control, NSFont.MenuBarFontOfSize(12)); //m_view.PopUpMenu(new NSMenuItem("test",""),pos,control); OnCollapse(EventArgs.Empty); }
/// <summary> /// Initializes the menu. /// </summary> /// <param name="menu">The menu whose items are to be set.</param> internal void InitializeMenu(NSMenu menu) { _deviceConnectionViewModels.Clear(); var ports = DeviceConnectionViewModel.GetAvailableConnections(_ltoFlash); menu.RemoveAllItems(); var shortcutNumber = 0; foreach (var port in ports) { ++shortcutNumber; var menuItem = SetActiveDeviceCommand.CreateMenuItemForCommand(_group, true, null); menuItem.Title = port.Name; menuItem.Activated += HandleSetActiveDeviceCommandActivated; // doesn't use standard approach menuItem.Enabled = SetActiveDeviceCommand.CanExecute(port); if (shortcutNumber < 10) { menuItem.KeyEquivalent = shortcutNumber.ToString(); menuItem.KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask; } _deviceConnectionViewModels[menuItem.GetHashCode()] = port; } }
public MDServicesMenuItem() { Title = GettextCatalog.GetString("Services"); var sub = NSApplication.SharedApplication.ServicesMenu; if (sub == null) { sub = new NSMenu(); NSApplication.SharedApplication.ServicesMenu = sub; } else { foreach (var m in sub.Supermenu.ItemArray()) { if (m.Submenu == sub) { m.Submenu = new NSMenu(); break; } } } Submenu = sub; }
public override void DidFinishLaunching(NSNotification notification) { NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Accessory; var menu = new NSMenu(); this.statusItem.Title = "-"; this.statusItem.HighlightMode = true; this.statusItem.Image = this.slack0; this.statusItem.Menu = menu; menu.AddItem(new NSMenuItem { Title = "Slack", Action = new ObjCRuntime.Selector("slack:") }); menu.AddItem(new NSMenuItem { Title = "Setting", Action = new ObjCRuntime.Selector("setting:") }); menu.AddItem(new NSMenuItem { Title = "Quit", Action = new ObjCRuntime.Selector("quit:") }); this.getUnreadCountLoop(); }
public static NSMenu ToNSMenu(this Menu menus, NSMenu nsMenu = null) { if (nsMenu == null) { nsMenu = new NSMenu(menus.Text ?? ""); } foreach (var menu in menus) { var menuItem = new NSMenuItem(menu.Text ?? ""); var subMenu = new NSMenu(menu.Text ?? ""); menuItem.Submenu = subMenu; foreach (var item in menu.Items) { var subMenuItem = item.ToNSMenuItem(); GetAccelerators(subMenuItem, item); subMenu.AddItem(subMenuItem); item.PropertyChanged += (sender, e) => (sender as MenuItem)?.UpdateNSMenuItem(subMenuItem, new string[] { e.PropertyName }); } nsMenu.AddItem(menuItem); menu.ToNSMenu(subMenu); } return(nsMenu); }
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 override void AwakeFromNib() { versionLabel.StringValue = ClientInfo.AboutBoxVersionString; versionLabel.ToolTip = ClientInfo.AboutBoxVersionTooltip; appNameLabel.StringValue = ClientInfo.FullProductName; copyrightLabel.StringValue = BuildInfo.Copyright; licensesMenu = new NSMenu(Catalog.GetString("Licenses & Notices")); licensesMenu.AddItem(new NSMenuItem( Catalog.GetString("Microsoft Software License Terms…"), (o, e) => NSWorkspace.SharedWorkspace.OpenFile( NSBundle.MainBundle.PathForResource("License", "rtf")))); licensesMenu.AddItem(new NSMenuItem( Catalog.GetString("Third Party Notices…"), (o, e) => NSWorkspace.SharedWorkspace.OpenFile( NSBundle.MainBundle.PathForResource("ThirdPartyNotices", "txt")))); licensesMenu.AddItem(new NSMenuItem( Catalog.GetString("Microsoft Enterprise and Developer Privacy Statement…"), (o, e) => AppDelegate.SharedAppDelegate.ShowPrivacyStatement((NSObject)o))); }
public override void RightMouseDown(NSEvent theEvent) { base.RightMouseDown(theEvent); var row = GetRowByMouseEventArgs(theEvent); if (row > -1) { var selectedRowIndexes = SelectedRows.AsEnumerable().ToList(); if (!selectedRowIndexes.Contains((nuint)row)) { var extendSelection = UiStateHelper.CommandKeyDown; SelectRow(row, extendSelection); selectedRowIndexes = SelectedRows.AsEnumerable().ToList(); } var menuItems = new List <NSMenuItem>(); PrepareContextMenu?.Invoke(this, new ContextMenuArguments(menuItems, selectedRowIndexes)); if (menuItems.Any()) { var menu = new NSMenu(); foreach (var item in menuItems) { menu.AddItem(item); } // TODO location and synchronization state var locationInView = this.ConvertPointToView(theEvent.LocationInWindow, null); locationInView.X -= 26; menu.PopUpMenu(null, locationInView, this); } } }
//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); }
void CreateMenuItem(NSMenu menu, IRuntimeModel runtime) { var menuItem = new NSMenuItem { IndentationLevel = runtime.IsIndented ? 2 : 1, Enabled = runtime.Enabled, Hidden = !runtime.Visible, AttributedTitle = new NSAttributedString(runtime.DisplayString, new NSStringAttributes { Font = runtime.Notable ? NSFontManager.SharedFontManager.ConvertFont(menu.Font, NSFontTraitMask.Bold) : menu.Font, }), }; var subMenu = CreateSubMenuForRuntime(runtime); if (subMenu != null) { menuItem.Submenu = subMenu; menuItem.Enabled = true; } else { menuItem.Activated += (o2, e2) => { string old = ActiveRuntime.FullDisplayString; ActiveRuntime = runtimeModel.First(r => r.FullDisplayString == runtime.FullDisplayString); var ea = new HandledEventArgs(); if (RuntimeChanged != null) { RuntimeChanged(o2, ea); } if (ea.Handled) { ActiveRuntime = runtimeModel.First(r => r.FullDisplayString == old); } }; } menu.AddItem(menuItem); }
private void RequirePopup() { if (this.popupButton != null) { return; } RemoveComboBox(); this.popupButton = new FocusablePopUpButton { AllowsExpansionToolTips = true, Cell = { LineBreakMode = NSLineBreakMode.TruncatingTail, UsesSingleLineMode = true, }, ControlSize = NSControlSize.Small, Font = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)), TranslatesAutoresizingMaskIntoConstraints = false, StringValue = String.Empty, }; this.popupButtonList = new NSMenu(); this.popupButton.Menu = this.popupButtonList; this.popupButton.Activated += PopupButton_Activated; AddSubview(this.popupButton); AddConstraints(new[] { NSLayoutConstraint.Create(this.popupButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), NSLayoutConstraint.Create(this.popupButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create(this.popupButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), }); this.firstKeyView = this.popupButton; this.lastKeyView = this.popupButton; }
partial void StartSearch(NSSearchField sender) { var noteResults = AppDelegate.NoteEngine.GetNotes(sender.StringValue, true); NSMenu noteSearchMenu = new NSMenu("Search Results"); var action = new MonoMac.ObjCRuntime.Selector("searchResultSelected"); foreach (var name in noteResults.Values.Select(n => n.Title)) { noteSearchMenu.AddItem(name, action, string.Empty); } Logger.Debug(sender.Frame.ToString()); Logger.Debug(sender.Superview.Frame.ToString()); Logger.Debug(sender.Superview.Superview.Frame.ToString()); NSEvent evt = NSEvent.OtherEvent(NSEventType.ApplicationDefined, new PointF(sender.Frame.Left, sender.Frame.Top), (NSEventModifierMask)0, 0, sender.Window.WindowNumber, sender.Window.GraphicsContext, (short)NSEventType.ApplicationDefined, 0, 0); NSMenu.PopUpContextMenu(noteSearchMenu, evt, searchField); }
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 Certificate", node.CreateCertificate); menu.AddItem (createCertificate); } NSMenu.PopUpContextMenu (menu, theEvent, theEvent.Window.ContentView); } } return base.MenuForEvent (theEvent); }
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); var pt = nsview.ConvertPointFromBase(new PointF((float)trans_x, (float)trans_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); }
private void PopulateFestivalDaysMenu(NSMenu menu) { // Delete existing festival day menu items. foreach (var menuItem in _dayItems) { menu.RemoveItem(menuItem); } // Loop through the festival days _dayItems = new List <NSMenuItem> { }; var plan = _controller.Plan; var tag = _FirstFestivalDaysMenuItemTag; foreach (var day in ScreeningsPlan.FestivalDays) { var item = new NSMenuItem(ItemTitle(day)); item.Tag = tag++; item.Enabled = day != plan.CurrDay; item.Activated += (sender, e) => _controller.GoToDay(day); menu.AddItem(item); _dayItems.Add(item); } }
public override void MenuWillOpen(NSMenu menu) { if (owner.currentMenu != menu) { var cancelEventArgs = new CancelEventArgs(); if (owner.owner_item != null && owner.owner_item is ToolStripDropDownItem) { ToolStripDropDownItem dropdown_owner = (ToolStripDropDownItem)owner.owner_item; dropdown_owner.OnDropDownShow(cancelEventArgs); } if (!cancelEventArgs.Cancel) { owner.OnOpening(cancelEventArgs); } if (cancelEventArgs.Cancel) { menu.CancelTrackingWithoutAnimation(); return; } } owner.is_visible = true; owner.currentMenu = menu; owner.OnVisibleChanged(EventArgs.Empty); // Send WM_CANCELMODE to cancel any grabs owner.CancelGrab(); // Convert all the menu items to NSMenuItems (w/ embedded views if necessary) if (!beforePopupCalled) { BeforePopup(); } owner.OnOpened(EventArgs.Empty); }
void PopulateArrayItems(CommandArrayInfo infos, NSMenu parent, ref NSMenuItem lastSeparator, ref int index) { foreach (CommandInfo ci in infos) { if (ci.IsArraySeparator) { var n = NSMenuItem.SeparatorItem; n.Hidden = true; n.Target = this; lastSeparator = n; parent.InsertItem(n, index++); continue; } var item = new MDExpandedArrayItem { Info = ci, Target = this, Action = ActionSel, }; if (ci is CommandInfoSet) { item.Submenu = new NSMenu(); int i = 0; NSMenuItem sep = null; PopulateArrayItems(((CommandInfoSet)ci).CommandInfos, item.Submenu, ref sep, ref i); } SetItemValues(item, ci); if (!item.Hidden) { MDMenu.ShowLastSeparator(ref lastSeparator); } parent.InsertItem(item, index++); } }
public override NSMenu MenuForEvent(NSEvent theEvent) { if (SelectedRow >= (nint)0) { NSObject obj = this.ItemAtRow(SelectedRow); if (obj != null) { NSMenu menu = new NSMenu(); if (obj is VMDirSchemaClassEntryNode) { var node = obj as VMDirSchemaClassEntryNode; NSMenuItem addAttribute = new NSMenuItem(VMDirSchemaConstants.VMDIRSCHEMA_PROPERTIES, node.ShowProperties); menu.AddItem(addAttribute); } else if (obj is VMDirSchemaClassBaseNode) { var node = obj as VMDirSchemaClassBaseNode; NSMenuItem addObjectClass = new NSMenuItem(VMDirSchemaConstants.VMDIRSCHEMA_ADDCLASS, node.AddObjectClass); menu.AddItem(addObjectClass); } else if (obj is VMDirSchemaAttributeBaseNode) { var node = obj as VMDirSchemaAttributeBaseNode; NSMenuItem addAttribute = new NSMenuItem(VMDirSchemaConstants.VMDIRSCHEMA_ADDATTRIBUTE, node.AddNewAttribute); menu.AddItem(addAttribute); } else { //do nothing } NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView); } } return(base.MenuForEvent(theEvent)); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Do any additional setup after loading the view titleText.AttributedStringValue = titleString; hoverarea = new NSTrackingArea(SettingsButton.Bounds, NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.ActiveAlways, this, null); SettingsButton.AddTrackingArea(hoverarea); //Contextual Menu for settings settingsMenu = new NSMenu(); launch = new NSMenuItem("Launch at Login", new ObjCRuntime.Selector("launch:"), ""); NSMenuItem about = new NSMenuItem("About", new ObjCRuntime.Selector("about:"), ""); NSMenuItem quit = new NSMenuItem("Quit", new ObjCRuntime.Selector("quit:"), "q"); settingsMenu.AddItem(launch); settingsMenu.AddItem(about); settingsMenu.AddItem(NSMenuItem.SeparatorItem); settingsMenu.AddItem(quit); cursor = NSCursor.CurrentSystemCursor; }
private NSMenuItem CreateMenuItem(object sender, RepositoryAction action, ContextMenuArguments arguments) { if (action.BeginGroup) { arguments.MenuItems.Add(NSMenuItem.SeparatorItem); } var item = new NSMenuItem(action.Name, (s, e) => action.Action?.Invoke(s, e)); item.Enabled = action.CanExecute; // this is a deferred submenu. We want to make sure that the context menu can pop up // fast, while submenus are not evaluated yet. We don't want to make the context menu // itself slow because the creation of the submenu items takes some time. if (action.DeferredSubActionsEnumerator != null) { var submenu = new NSMenu { AutoEnablesItems = false }; submenu.Delegate = new DeferredInitializerDelegate(arguments.Initializers); arguments.Initializers.Add(item, () => { foreach (var subAction in action.DeferredSubActionsEnumerator()) { submenu.AddItem(CreateMenuItem(sender, subAction, arguments)); } Console.WriteLine($"Added {submenu.Items.Length} deferred sub action(s)."); }); item.Submenu = submenu; } return(item); }
public override void DidFinishLaunching(NSNotification notification) { Mono.Setup(); App.Run(); // Set our custom menu with Cocoa if (true) { // From XIB/NIB file (editable in Xcode Interface Builder) NSArray arr; bool res = NSBundle.MainBundle.LoadNibNamed("MainMenu", NSApplication.SharedApplication, out arr); Debug.Assert(res); } else { // Or we can create it programatically var menu1 = new NSMenu(); menu1.AddItem(new NSMenuItem("Hi there")); menu1.AddItem(NSMenuItem.SeparatorItem); menu1.AddItem(new NSMenuItem("Exit", (sender, e) => NSApplication.SharedApplication.Terminate(menu1))); var menu2 = new NSMenu("Second menu"); menu2.AddItem(new NSMenuItem("What")); menu2.AddItem(new NSMenuItem("Hey")); var menubar = new NSMenu(); menubar.AddItem(new NSMenuItem { Submenu = menu1 }); menubar.AddItem(new NSMenuItem { Submenu = menu2 }); NSApplication.SharedApplication.MainMenu = menubar; } }
public override void NeedsUpdate(NSMenu menu) { // Define some aliases for improved readability. ViewController viewController = _app.Controller; FilmRatingDialogController ratingController = _app.FilmsDialogController; ScreeningDialogController screeningInfoController = viewController.ScreeningInfoDialog; FilmInfoDialogController filmInfoController = _app.FilmInfoController; AnalyserDialogController analyserController = _app.AnalyserDialogController; // Process every item in the menu foreach (NSMenuItem item in menu.Items) { // If the Combine or Uncombine film dialog is active, all menu // items must be inactive. if (_app.CombineTitleController != null || _app.UncombineTitleController != null) { item.Enabled = false; continue; } // Take action based on the menu tag. switch (item.Tag) { case _showFilmsMenuItemTag: item.Enabled = ratingController == null && viewController.ViewIsActive(); break; case _toggleOnlyFilmsWithScreeningsMenuItemTag: item.Enabled = ratingController != null; break; case _toggleTypeMatchMethodMenuItemTag: item.Enabled = ratingController != null; break; case _showFilmInfoMenuItemTag: item.Enabled = screeningInfoController != null || viewController.RunningPopupsCount == 0 || (ratingController != null && !ratingController.TextBeingEdited && ratingController.OneFilmSelected() && filmInfoController == null); break; case _visitFilmWebsiteMenuItemTag: item.Enabled = screeningInfoController != null || viewController.RunningPopupsCount == 0 || (ratingController != null && !ratingController.TextBeingEdited && ratingController.OneFilmSelected()) || filmInfoController != null || (analyserController != null && analyserController.GetSelectedFilm() != null); break; case _combineTitlesMenuItemTag: item.Enabled = ratingController != null && !ratingController.TextBeingEdited && ratingController.MultipleFilmsSelected(); break; case _uncombineTitleMenuItemTag: item.Enabled = ratingController != null && !ratingController.TextBeingEdited && ratingController.OneFilmSelected(); break; default: item.Enabled = false; break; } } }
public override void MenuDidClose(NSMenu menu) { _menuDidClose(); }
public override void MenuWillOpen(NSMenu menu) { _menuWillOpen(); }
void MenuDidClose (NSMenu menu) { if (CloseHandler != null) { CloseHandler (); } }
public override void MenuWillOpen(NSMenu menu) { InvokeOnMainThread(delegate { NSApplication.SharedApplication.DockTile.BadgeLabel = null; }); }
public override void MenuWillHighlightItem (NSMenu menu, NSMenuItem item) { }
protected virtual void SetupMainAppMenu(NSMenu nativeMenu) { var menu = Element.GetMenu(_application); menu.ToNSMenu(nativeMenu, NativeMenuItemCreator); }
void CreateMenuItem (NSMenu menu, IRuntimeModel runtime) { var menuItem = new NSMenuItem { IndentationLevel = runtime.IsIndented ? 2 : 1, Enabled = runtime.Enabled, Hidden = !runtime.Visible, AttributedTitle = new NSAttributedString (runtime.DisplayString, new NSStringAttributes { Font = runtime.Notable ? NSFontManager.SharedFontManager.ConvertFont (menu.Font, NSFontTraitMask.Bold) : menu.Font, }), }; var subMenu = CreateSubMenuForRuntime (runtime); if (subMenu != null) { menuItem.Submenu = subMenu; menuItem.Enabled = true; } else { menuItem.Activated += (o2, e2) => { string old = ActiveRuntime.FullDisplayString; ActiveRuntime = runtimeModel.First (r => r.FullDisplayString == runtime.FullDisplayString); var ea = new HandledEventArgs (); if (RuntimeChanged != null) RuntimeChanged (o2, ea); if (ea.Handled) ActiveRuntime = runtimeModel.First (r => r.FullDisplayString == old); }; } menu.AddItem (menuItem); }
NSMenu CreateSubMenuForRuntime (IRuntimeModel runtime) { if (!runtime.Children.Any ()) return null; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = false, Font = NSFont.MenuFontOfSize (12), }; foreach (var item in runtime.Children) CreateMenuItem (menu, item); return menu; }
public PathSelectorView (CGRect frameRect) : base (frameRect) { PathComponentCells = new [] { new NSPathComponentCell { Image = ImageService.GetIcon ("project").ToNSImage (), Title = ConfigurationPlaceholder, Enabled = false, TextColor = NSColor.FromRgba (0.34f, 0.34f, 0.34f, 1), }, new NSPathComponentCell { Image = ImageService.GetIcon ("device").ToNSImage (), Title = RuntimePlaceholder, Enabled = false, TextColor = NSColor.FromRgba (0.34f, 0.34f, 0.34f, 1), } }; BackgroundColor = NSColor.Clear; FocusRingType = NSFocusRingType.None; Activated += (sender, e) => { var item = ClickedPathComponentCell; if (item == null) return; var componentRect = ((NSPathCell)Cell).GetRect (item, Frame, this); int idx = -1; int i = 0; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = false, Font = NSFont.MenuFontOfSize (12), }; if (object.ReferenceEquals (ClickedPathComponentCell, PathComponentCells [ConfigurationIdx])) { foreach (var configuration in ConfigurationModel) { if (idx == -1 && configuration.OriginalId == ActiveConfiguration.OriginalId) idx = i; var _configuration = configuration; menu.AddItem (new NSMenuItem (configuration.DisplayString, (o2, e2) => { ActiveConfiguration = configurationModel.First (c => c.OriginalId == _configuration.OriginalId); if (ConfigurationChanged != null) ConfigurationChanged (o2, e2); UpdatePathText (ConfigurationIdx, _configuration.DisplayString); }) { Enabled = true, IndentationLevel = 1, }); ++i; } } else if (object.ReferenceEquals (ClickedPathComponentCell, PathComponentCells [RuntimeIdx])) { foreach (var runtime in RuntimeModel) { if (idx == -1 && runtime.DisplayString == ActiveRuntime.DisplayString) idx = i; if (runtime.HasParent) continue; if (runtime.IsSeparator) menu.AddItem (NSMenuItem.SeparatorItem); else CreateMenuItem (menu, runtime); ++i; } } else throw new NotSupportedException (); if (menu.Count > 1) { var offs = new CGPoint (componentRect.Left + 3, componentRect.Top + 3); if (Window.Screen.BackingScaleFactor == 2) offs.Y += 0.5f; // fine tune menu position on retinas menu.PopUpMenu (null, offs, this); } }; }
void MenuWillHighlightItem (NSMenu menu, NSMenuItem willHighlightItem) { if (oldItem != null) { oldItem.FireDeselectedEvent (); oldItem = null; } if (willHighlightItem == null) return; int index = (int)menu.IndexOf (willHighlightItem); if (index < 0) return; oldItem = this.menu.Items [index]; oldItem.FireSelectedEvent (new Xwt.Rectangle (lastOpenPositon.X, lastOpenPositon.Y, menu.Size.Width, menu.Size.Height)); }
void CreateMenuItem (NSMenu menu, IRuntimeModel runtime) { NSMenuItem menuItem; string runtimeFullDisplayString; using (var mutableModel = runtime.GetMutableModel ()) { runtimeFullDisplayString = mutableModel.FullDisplayString; menuItem = new NSMenuItem { IndentationLevel = runtime.IsIndented ? 2 : 1, AttributedTitle = new NSAttributedString (mutableModel.DisplayString, new NSStringAttributes { Font = runtime.Notable ? NSFontManager.SharedFontManager.ConvertFont (menu.Font, NSFontTraitMask.Bold) : menu.Font, }), Enabled = mutableModel.Enabled, Hidden = !mutableModel.Visible, }; } var subMenu = CreateSubMenuForRuntime (runtime); if (subMenu != null) { menuItem.Submenu = subMenu; menuItem.Enabled = true; } else { menuItem.Activated += (o2, e2) => { string old; using (var activeMutableModel = ActiveRuntime.GetMutableModel ()) old = activeMutableModel.FullDisplayString; IRuntimeModel newRuntime = runtimeModel.FirstOrDefault (r => { using (var newRuntimeMutableModel = r.GetMutableModel ()) return newRuntimeMutableModel.FullDisplayString == runtimeFullDisplayString; }); if (newRuntime == null) return; ActiveRuntime = newRuntime; var ea = new HandledEventArgs (); if (RuntimeChanged != null) RuntimeChanged (o2, ea); if (ea.Handled) ActiveRuntime = runtimeModel.First (r => { using (var newRuntimeMutableModel = r.GetMutableModel ()) return newRuntimeMutableModel.FullDisplayString == old; }); }; } menu.AddItem (menuItem); }
void MenuDidClose (NSMenu menu) { if (menu.Supermenu != null) return; if (CloseHandler != null) { CloseHandler (); } this.menu.FireClosedEvent (); }
public override NSMenu MenuForEvent (NSEvent theEvent) { UIErrorHelper.CheckedExec (delegate() { CGPoint pt = this.ConvertPointFromView (theEvent.LocationInWindow, null); _selectedRow = this.GetRow (pt); //get datasource and node information NSTableViewDataSource ds = (NSTableViewDataSource)this.DataSource; NSMenu menu = new NSMenu (); if (_selectedRow >= 0) { if (ds is NodesListView) { string data = (ds as NodesListView).Entries [(int)_selectedRow].DisplayName; switch (data) { case "Key Pairs": NSMenuItem createKeyPair = new NSMenuItem ("Create Key Pair", HandleKeyPairRequest); menu.AddItem (createKeyPair); break; case "Certificates": NSMenuItem createCertificate = new NSMenuItem ("Create Certificate", HandleCreateSelfSignedCertificate); menu.AddItem (createCertificate); break; case "Signing Requests": NSMenuItem createSigningRequest = new NSMenuItem ("Create SigningRequest", HandleCreateSigningRequest); menu.AddItem (createSigningRequest); break; default: break; } } else if (ds is CertificateDetailsListView || ds is PrivateCertsListView) { X509Certificate2 cert = null; if (ds is CertificateDetailsListView) { CertificateDetailsListView lw = ds as CertificateDetailsListView; cert = lw.Entries [(int)_selectedRow]; if (lw.CertificateState == (int)VMCA.CertificateState.Active) { NSMenuItem revokeCert = new NSMenuItem ("Revoke Certificate", (object sender, EventArgs e) => { UIErrorHelper.CheckedExec (delegate() { VMCACertificateService.RevokeCertificate (cert, lw.ServerDto); NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadAll", this); }); }); menu.AddItem (revokeCert); } } if (ds is PrivateCertsListView) { cert = CertificateExtensions.GetX509Certificate2FromString ((ds as PrivateCertsListView).Entries [(int)_selectedRow].Certificate); } NSMenuItem showCert = new NSMenuItem ("Show Certificate", (object sender, EventArgs e) => { CertificateService.DisplayX509Certificate2 (this, cert); }); menu.AddItem (showCert); NSMenuItem showCertString = new NSMenuItem ("Show Certificate String", (object sender, EventArgs e) => { UIHelper.ShowGenericWindowAsSheet (VMCACertificate.GetCertificateAsString (cert), "Certificate String", VMCAAppEnvironment.Instance.MainWindow); }); menu.AddItem (showCertString); /* if (lw.CertificateState == -1) { NSMenuItem deleteString = new NSMenuItem ("Delete Certificate", (object sender, EventArgs e) => { lw.ServerDto.PrivateCertificates.RemoveAll (x => x.Certificate.Equals (cert.ToString ())); NSNotificationCenter.DefaultCenter.PostNotificationName ("ReloadTableView", this); }); menu.AddItem (deleteString); }*/ } else if (ds is CSRDetailListView) { CSRDetailListView lw = ds as CSRDetailListView; var csr = lw.Entries [(int)_selectedRow].CSR; NSMenuItem showCert = new NSMenuItem ("Show CSR", (object sender, EventArgs e) => { UIHelper.ShowGenericWindowAsSheet (csr, "CSR", VMCAAppEnvironment.Instance.MainWindow); }); menu.AddItem (showCert); } else if (ds is KeyPairDetailListView) { KeyPairDetailListView lw = ds as KeyPairDetailListView; var privateKey = lw.Entries [(int)_selectedRow].PrivateKey; var publicKey = lw.Entries [(int)_selectedRow].PublicKey; KeyPairData keyPair = new KeyPairData (privateKey, publicKey); NSMenuItem showCert = new NSMenuItem ("Export KeyPair", (object sender, EventArgs e) => { VMCAKeyPairNode.SaveKeyData (keyPair); }); menu.AddItem (showCert); } NSMenu.PopUpContextMenu (menu, theEvent, theEvent.Window.ContentView); } }); return base.MenuForEvent (theEvent); }
private static void AddToolbarItem(NSMutableDictionary theDict, NSString identifier, NSString label, NSString paletteLabel, NSString toolTip, Id target, IntPtr settingSelector, Id itemContent, IntPtr action, NSMenu menu) { NSMenuItem mItem; // here we create the NSToolbarItem and setup its attributes in line with the parameters NSToolbarItem item = new NSToolbarItem(identifier); item.Autorelease(); item.Label = label; item.PaletteLabel = paletteLabel; item.ToolTip = toolTip; // the settingSelector parameter can either be @selector(setView:) or @selector(setImage:). Pass in the right // one depending upon whether your NSToolbarItem will have a custom view or an image, respectively // (in the itemContent parameter). Then this next line will do the right thing automatically. item.PerformSelectorWithObject(settingSelector, itemContent); item.Target = target; item.Action = action; // If this NSToolbarItem is supposed to have a menu "form representation" associated with it (for text-only mode), // we set it up here. Actually, you have to hand an NSMenuItem (not a complete NSMenu) to the toolbar item, // so we create a dummy NSMenuItem that has our real menu as a submenu. if (menu != null) { // we actually need an NSMenuItem here, so we construct one mItem = new NSMenuItem(); mItem.Autorelease(); mItem.Submenu = menu; mItem.Title = menu.Title; item.MenuFormRepresentation = mItem; } // Now that we've setup all the settings for this new toolbar item, we add it to the dictionary. // The dictionary retains the toolbar item for us, which is why we could autorelease it when we created // it (above). theDict[identifier] = item; }
void PopulateArrayItems (CommandArrayInfo infos, NSMenu parent, ref NSMenuItem lastSeparator, ref int index) { if (infos == null) return; foreach (CommandInfo ci in infos) { if (ci.IsArraySeparator) { var n = NSMenuItem.SeparatorItem; n.Hidden = true; n.Target = this; lastSeparator = n; parent.InsertItem (n, index++); continue; } var item = new MDExpandedArrayItem { Info = ci, Target = this, Action = ActionSel, }; if (ci is CommandInfoSet) { item.Submenu = new NSMenu (); int i = 0; NSMenuItem sep = null; PopulateArrayItems (((CommandInfoSet)ci).CommandInfos, item.Submenu, ref sep, ref i); } SetItemValues (item, ci, true); if (!item.Hidden) MDMenu.ShowLastSeparator (ref lastSeparator); parent.InsertItem (item, index++); } }
public override bool SetGlobalMenu (CommandManager commandManager, string commandMenuAddinPath, string appMenuAddinPath) { if (setupFail) return false; try { InitApp (commandManager); NSApplication.SharedApplication.HelpMenu = null; var rootMenu = NSApplication.SharedApplication.MainMenu; if (rootMenu == null) { rootMenu = new NSMenu (); NSApplication.SharedApplication.MainMenu = rootMenu; } else { rootMenu.RemoveAllItems (); } CommandEntrySet appCes = commandManager.CreateCommandEntrySet (appMenuAddinPath); rootMenu.AddItem (new MDSubMenuItem (commandManager, appCes)); CommandEntrySet ces = commandManager.CreateCommandEntrySet (commandMenuAddinPath); foreach (CommandEntry ce in ces) { rootMenu.AddItem (new MDSubMenuItem (commandManager, (CommandEntrySet) ce)); } } catch (Exception ex) { try { var m = NSApplication.SharedApplication.MainMenu; if (m != null) { m.Dispose (); } NSApplication.SharedApplication.MainMenu = null; } catch {} LoggingService.LogError ("Could not install global menu", ex); setupFail = true; return false; } return true; }
public override void MenuDidClose(NSMenu menu) { RestoreTextColor(menu.HighlightedItem); }
public void CreateMenu() { using (NSAutoreleasePool a = new NSAutoreleasePool()) { this.menu = new NSMenu(); this.menu.AutoEnablesItems = false; this.state_item = new NSMenuItem() { Title = Controller.StateText, Enabled = false }; this.folder_item = new NSMenuItem() { Title = "SparkleShare" }; this.folder_item.Activated += delegate { Controller.SparkleShareClicked(); }; this.folder_item.Image = this.sparkleshare_image; this.folder_item.Image.Size = new SizeF(16, 16); this.folder_item.Enabled = true; this.add_item = new NSMenuItem() { Title = "Add Hosted Project…", Enabled = true }; this.add_item.Activated += delegate { Controller.AddHostedProjectClicked(); }; this.recent_events_item = new NSMenuItem() { Title = "View Recent Changes…", Enabled = Controller.OpenRecentEventsItemEnabled }; if (Controller.Folders.Length > 0) { this.recent_events_item.Activated += delegate { Controller.OpenRecentEventsClicked(); }; } this.notify_item = new NSMenuItem() { Enabled = (Controller.Folders.Length > 0) }; if (Program.Controller.NotificationsEnabled) { this.notify_item.Title = "Turn Notifications Off"; } else { this.notify_item.Title = "Turn Notifications On"; } this.notify_item.Activated += delegate { Program.Controller.ToggleNotifications(); InvokeOnMainThread(delegate { if (Program.Controller.NotificationsEnabled) { this.notify_item.Title = "Turn Notifications Off"; } else { this.notify_item.Title = "Turn Notifications On"; } }); }; this.about_item = new NSMenuItem() { Title = "About SparkleShare", Enabled = true }; this.about_item.Activated += delegate { Controller.AboutClicked(); }; this.quit_item = new NSMenuItem() { Title = "Quit", Enabled = Controller.QuitItemEnabled }; this.quit_item.Activated += delegate { Controller.QuitClicked(); }; this.menu.AddItem(this.state_item); this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.folder_item); this.folder_menu_items = new NSMenuItem [Controller.Folders.Length]; this.submenu_items = new NSMenuItem [Controller.OverflowFolders.Length]; if (Controller.Folders.Length > 0) { this.folder_tasks = new EventHandler [Controller.Folders.Length]; this.overflow_tasks = new EventHandler [Controller.OverflowFolders.Length]; int i = 0; foreach (string folder_name in Controller.Folders) { NSMenuItem item = new NSMenuItem(); item.Title = folder_name; if (Program.Controller.UnsyncedFolders.Contains(folder_name)) { item.Image = this.caution_image; } else { item.Image = this.folder_image; } item.Image.Size = new SizeF(16, 16); this.folder_tasks [i] = OpenFolderDelegate(folder_name); this.folder_menu_items [i] = item; this.folder_menu_items [i].Activated += this.folder_tasks [i]; i++; } ; i = 0; foreach (string folder_name in Controller.OverflowFolders) { NSMenuItem item = new NSMenuItem(); item.Title = folder_name; if (Program.Controller.UnsyncedFolders.Contains(folder_name)) { item.Image = this.caution_image; } else { item.Image = this.folder_image; } item.Image.Size = new SizeF(16, 16); this.overflow_tasks [i] = OpenFolderDelegate(folder_name); this.submenu_items [i] = item; this.submenu_items [i].Activated += this.overflow_tasks [i]; i++; } ; } foreach (NSMenuItem item in this.folder_menu_items) { this.menu.AddItem(item); } if (this.submenu_items.Length > 0) { this.submenu = new NSMenu(); foreach (NSMenuItem item in this.submenu_items) { this.submenu.AddItem(item); } this.more_item = new NSMenuItem() { Title = "More Projects", Submenu = this.submenu }; this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.more_item); } this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.add_item); this.menu.AddItem(this.recent_events_item); this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.notify_item); this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.about_item); this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.quit_item); this.menu.Delegate = new SparkleStatusIconMenuDelegate(); this.status_item.Menu = this.menu; } }
public void DidBecomeReady(ICDevice device) { var scanner = device as ICScannerDevice; var availabeTypes = scanner.AvailableFunctionalUnitTypes; var functionalUnit = scanner.SelectedFunctionalUnit; Console.WriteLine($"{nameof (DidBecomeReady)}: {scanner}"); FunctionalUnitMenu.RemoveAllItems(); FunctionalUnitMenu.Enabled = false; if (availabeTypes.Length > 0) { var menu = new NSMenu(); FunctionalUnitMenu.Enabled = true; foreach (var item in availabeTypes) { NSMenuItem menuItem; switch ((ICScannerFunctionalUnitType)item.Int32Value) { case ICScannerFunctionalUnitType.Flatbed: menuItem = new NSMenuItem("Flatbed", "", SelectFunctionalUnit) { Tag = (nint)(long)ICScannerFunctionalUnitType.Flatbed }; menu.AddItem(menuItem); break; case ICScannerFunctionalUnitType.PositiveTransparency: menuItem = new NSMenuItem("PositiveTransparency", "", SelectFunctionalUnit) { Tag = (nint)(long)ICScannerFunctionalUnitType.PositiveTransparency }; menu.AddItem(menuItem); break; case ICScannerFunctionalUnitType.NegativeTransparency: menuItem = new NSMenuItem("NegativeTransparency", "", SelectFunctionalUnit) { Tag = (nint)(long)ICScannerFunctionalUnitType.NegativeTransparency }; menu.AddItem(menuItem); break; case ICScannerFunctionalUnitType.DocumentFeeder: menuItem = new NSMenuItem("DocumentFeeder", "", SelectFunctionalUnit) { Tag = (nint)(long)ICScannerFunctionalUnitType.DocumentFeeder }; menu.AddItem(menuItem); break; } } FunctionalUnitMenu.Menu = menu; } Console.WriteLine($"observeValueForKeyPath - functionalUnit: {functionalUnit}"); if (functionalUnit != null) { FunctionalUnitMenu.SelectItemWithTag((nint)(long)functionalUnit.Type); } }
void MenuWillOpen(NSMenu menu) { Ide.IdeApp.DisableIdleActions(); StartBumpingGtkLoop(); }
static NSMenu FromMenu (ContextMenu menu, Action closeHandler) { var result = new NSMenu () { AutoEnablesItems = false }; result.WeakDelegate = new ContextMenuDelegate { CloseHandler = closeHandler }; foreach (var menuItem in menu.Items) { var item = CreateMenuItem (menuItem); result.AddItem (item); } return result; }
public override void MenuWillHighlightItem(NSMenu menu, NSMenuItem item) { }
void MenuNeedsUpdate (NSMenu menu) { Debug.Assert (menu == this); // MacOS calls this for each menu when it's about to open, but also for every menu on every keystroke. // We only want to do the update when the menu's about to open, since it's expensive. Checking whether // NSMenuProperty.Image needs to be updated is the only way to distinguish between these cases. // // http://www.cocoabuilder.com/archive/cocoa/285859-reason-for-menuneedsupdate-notification.html // if (PropertiesToUpdate ().HasFlag (NSMenuProperty.Image)) UpdateCommands (); }