//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 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", "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 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 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); }
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 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; }
//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); }
private void CreateStatusItem() { // Create the status bar item NSStatusBar statusBar = NSStatusBar.SystemStatusBar; _statusBarItem = statusBar.CreateStatusItem(NSStatusItemLength.Variable); _statusBarItem.Button.Image = NSImage.ImageNamed("TrayIcon.ico"); // Listen to touches on the status bar item _statusBarItem.Button.SendActionOn(NSEventType.OtherMouseUp); _statusBarItem.Button.Activated += StatusItemActivated; // Create the menu that gets opened on a right click _menu = new NSMenu(); var closeAppItem = new NSMenuItem("Close"); closeAppItem.Activated += CloseAppItem_Activated; _menu.AddItem(closeAppItem); }
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); }
static NSMenu CreateMenu() { var root = new NSMenu("MainMenu"); var appMenu = new NSMenu("AppMenu"); //appMenu.AddItem(new NSMenuItem("Hide", "h", (sender, e) => { Console.WriteLine("Hide"); })); //appMenu.AddItem(new NSMenuItem("Hide others", "o", (sender, e) => { Console.WriteLine("Hide Others"); })); //appMenu.AddItem(new NSMenuItem("Quit", "q", (sender, e) => { Console.WriteLine("Quit"); app.Terminate(app); })); appMenu.AddItem(new NSMenuItem("Hide", new Selector("hide:"), "h")); appMenu.AddItem(new NSMenuItem("Hide Others", new Selector("hideOtherApplications:"), "o")); appMenu.AddItem(new NSMenuItem("Quit XibLessApp", new Selector("terminate:"), "q")); var appMenuItem = root.AddItem("AppMenuItem", null, ""); root.SetSubmenu(appMenu, appMenuItem); return(root); }
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; mainWindowController = new MainWindowController(); mainWindowController.Window.MakeKeyAndOrderFront(this); }
internal static NSMenu GetMenu() { var menubar = new NSMenu(); var appMenuItem = new NSMenuItem(); menubar.AddItem(appMenuItem); var appMenu = new NSMenu(); var quitMenuItem = new NSMenuItem(QuitTitle, QuitCharCode, delegate { NSApplication.SharedApplication.Terminate(menubar); }); appMenu.AddItem(quitMenuItem); appMenuItem.Submenu = appMenu; return(menubar); }
public void BeforePopup() { // Early opening before we call NSMenu.PopUpMenu beforePopupCalled = true; menu.RemoveAllItems(); foreach (ToolStripItem item in owner.Items) { var menuItem = item.ToNSMenuItem(); var actionObj = new ActionDispatcher((sender, e) => { owner.OnItemClicked(new ToolStripItemClickedEventArgs(item)); item.PerformClick(); }); menuItem.Target = actionObj; menuItem.Action = ActionDispatcher.Action; menuItem.Menu?.RemoveItem(menuItem); menu.AddItem(menuItem); } }
// constructor public AppDelegate() { // Init Xamarin.Forms Forms.Init(); // Create the tray item w/ icon and menu statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(NSStatusItemLength.Square); statusItem.Button.Image = NSImage.ImageNamed("TrayIcon_White.ico").ResizeTo(new CGSize(18, 18)); statusMenu = new NSMenu(); NSMenuItem quitMenuItem = new NSMenuItem("Quit"); quitMenuItem.Activated += (object sender, EventArgs e) => { NSApplication.SharedApplication.Terminate(this); }; statusMenu.AddItem(quitMenuItem); // The core app will appear inside a popover Core.PreferencesProvider.Default = new MacPreferencesProvider(); popover = new NSPopover(); Application.SetCurrentApplication(new Core.App()); }
static void CreateMacMenu() { var menuBar = new NSMenu(""); var appMenuItem = new NSMenuItem(""); var appMenu = new NSMenu("FormsTest"); var quitItem = new NSMenuItem("Quit") { KeyEquivalent = "q" }; quitItem.Activated += (sender, e) => { Terminate(); }; appMenu.AddItem(quitItem); menuBar.AddItem(appMenuItem); menuBar.SetSubmenu(appMenu, appMenuItem); var editMenuItem = new NSMenuItem(); var editMenu = new NSMenu("Edit"); var selectAllItem = new NSMenuItem("Select All") { Action = new ObjCRuntime.Selector("selectAll:"), KeyEquivalent = "a" }; editMenu.AddItem(selectAllItem); var copyItem = new NSMenuItem("Copy") { Action = new ObjCRuntime.Selector("copy:"), KeyEquivalent = "c" }; editMenu.AddItem(copyItem); var pasteItem = new NSMenuItem("Paste") { Action = new ObjCRuntime.Selector("paste:"), KeyEquivalent = "v" }; editMenu.AddItem(pasteItem); menuBar.AddItem(editMenuItem); menuBar.SetSubmenu(editMenu, editMenuItem); NSApplication.SharedApplication.Menu = menuBar; }
private void MenuBarPresenter_Loaded(object sender, RoutedEventArgs e) { _menuBar = this.FindFirstParent <MenuBar>() ?? throw new InvalidOperationException($"MenuBarPresenter must be used with a MenuBar control"); NSMenu menubar = new NSMenu(); menubar.AutoEnablesItems = false; NSApplication.SharedApplication.MainMenu = menubar; foreach (var item in _menuBar.Items) { NSMenuItem appMenuItem = new NSMenuItem() { Enabled = true }; menubar.AddItem(appMenuItem); AddSubMenus(appMenuItem, item); } }
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>(); var arguments = new ContextMenuArguments(menuItems, selectedRowIndexes); PrepareContextMenu?.Invoke(this, arguments); if (menuItems.Any()) { var menu = new NSMenu { AutoEnablesItems = false }; menu.Delegate = new DeferredInitializerDelegate(arguments.Initializers); foreach (var item in menuItems) { menu.AddItem(item); } var locationInView = this.ConvertPointToView(theEvent.LocationInWindow, null); locationInView.X -= 26; menu.PopUpMenu(null, locationInView, this); } } }
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)); }
void IWindow.ShowColorSelector(ModelColor[] options) { if (changeColorNSEvent == null) { return; } var menu = new NSMenu(); foreach (var opt in options) { var item = new NSMenuItem(); var dict = new NSMutableDictionary(); dict.SetValueForKey(opt.ToColor().ToNSColor(), NSStringAttributeKey.BackgroundColor); var attrStr = new NSAttributedString(" ", dict); item.AttributedTitle = attrStr; item.Action = new Selector("OnColorMenuItemClicked:"); item.Target = this; item.Tag = unchecked ((int)opt.Argb); menu.AddItem(item); } NSMenu.PopUpContextMenu(menu, changeColorNSEvent, changeColorLinkLabel); }
public override void MenuWillOpen(NSMenu menu) { var e = owner.viewModel; menu.RemoveAllItems(); var(visibleItems, checkedItems) = e.OnMenuItemOpening(true); Action <MenuItem, string, Action> addItem = (item, str, handler) => { if ((item & visibleItems) != 0) { menu.AddItem(new NSMenuItem(str, (sender, evt) => handler())); } }; addItem(MenuItem.SaveLogAs, "Save as...", e.OnSaveLogAsMenuItemClicked); addItem(MenuItem.SourceProperties, "Properties...", e.OnSourceProprtiesMenuItemClicked); addItem(MenuItem.OpenContainingFolder, "Open containing folder", e.OnOpenContainingFolderMenuItemClicked); addItem(MenuItem.ShowOnlyThisLog, "Show only this log", e.OnShowOnlyThisLogClicked); addItem(MenuItem.ShowAllLogs, "Show all logs", e.OnShowAllLogsClicked); addItem(MenuItem.CloseOthers, "Close others", e.OnCloseOthersClicked); addItem(MenuItem.CopyErrorMessage, "Copy error message", e.OnCopyErrorMessageClicked); addItem(MenuItem.SaveMergedFilteredLog, "Save joint log...", e.OnSaveMergedFilteredLogMenuItemClicked); }
static void Main() { NSApplication.Init(); var menuBar = new NSMenu(); var appMenuItem = new NSMenuItem(); menuBar.AddItem(appMenuItem); var appMenu = new NSMenu(); appMenu.AddItem(new NSMenuItem("Quit", new Selector("terminate:"), "q")); appMenuItem.Submenu = appMenu; var app = NSApplication.SharedApplication; app.Delegate = new AppDelegate(); app.MainMenu = menuBar; app.ApplicationIconImage = NSImage.ImageNamed("AppIcon"); app.ActivationPolicy = NSApplicationActivationPolicy.Regular; app.Run(); }
/// <summary> /// Populates the film menu items with all screenings of the current film. /// </summary> /// <param name="menu">Menu.</param> /// private void PopulateFilmScreeningsMenuItems(NSMenu menu) { // Remove the existing screening items from the menu. foreach (string title in _filmScreeningByMenuItemTitle.Keys) { menu.RemoveItem(menu.ItemWithTitle(title)); } // Add the screenings with same film to the Screening menu. int screeningNumber = 0; var mask = NSEventModifierMask.AlternateKeyMask | NSEventModifierMask.CommandKeyMask; _filmScreeningByMenuItemTitle = new Dictionary <string, Screening> { }; _FilmScreeningEnabledByTag = new Dictionary <nint, bool> { }; var screenings = _screeningProvider.Screenings; foreach (var screening in screenings) { screeningNumber += 1; string itemTitle = screening.ToMenuItemString(); NSMenuItem item = new NSMenuItem(itemTitle) { Action = new Selector("NavigateFilmScreening:"), Tag = _filmMenuHeaderItemTag + screeningNumber, State = NSCellStateValue.Off }; if (screeningNumber <= 9) { item.KeyEquivalent = screeningNumber.ToString(); item.KeyEquivalentModifierMask = mask; } menu.AddItem(item); bool enabled = AnalyserViewRunning() || screening != Screening; _FilmScreeningEnabledByTag.Add(item.Tag, enabled); _filmScreeningByMenuItemTitle.Add(itemTitle, screening); } }
NSMenuItem CreateMenuItem(NSMenu menu, IRuntimeModel runtime) { NSMenuItem menuItem; string runtimeFullDisplayString; using (var mutableModel = runtime.GetMutableModel()) { runtimeFullDisplayString = mutableModel.FullDisplayString; menuItem = new NSMenuItem() { IndentationLevel = runtime.IsIndented ? 1 : 0, 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, }; if (ActiveRuntime == runtime || (ActiveRuntime?.Children.Contains(runtime) ?? false)) { menuItem.State = NSCellStateValue.On; } } var subMenu = CreateSubMenuForRuntime(runtime); if (subMenu != null) { menuItem.Submenu = subMenu; menuItem.Enabled = true; } else { menuItem.Activated += (o2, e2) => { ActiveRuntime = runtime; }; } menu.AddItem(menuItem); return(menuItem); }
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 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); }
/// <summary> /// Builds the menu. /// </summary> /// <returns>The menu.</returns> private void BuildMenu() { NSMenu ms = new NSMenu(); fullScreenshot = new NSMenuItem("Full Screenshot"); regionScreenshot = new NSMenuItem("Region Screenshot"); windowScreenshot = new NSMenuItem("Window Screenshot"); toolsItem = new NSMenuItem("Tools"); ms.AddItem(fullScreenshot); ms.AddItem(regionScreenshot); ms.AddItem(windowScreenshot); ms.AddItem(NSMenuItem.SeparatorItem); ms.AddItem(toolsItem); ms.AddItem(NSMenuItem.SeparatorItem); NSMenuItem quitButton = new NSMenuItem("Quit"); quitButton.Activated += (object sender, EventArgs e) => { NSApplication.SharedApplication.Terminate(this); }; ms.AddItem(quitButton); statusItem.Menu = ms; }
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); }
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); } }
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); }
void ConstructMenu() { var menu = new NSMenu(); var scanSelectItem = new NSMenuItem("Scan - select", OnScanSelect); scanSelectItem.BindHotKey(NSUserDefaultsController.SharedUserDefaultsController, Constants.KEY_HOTKEY_SCAN_SELECT); menu.AddItem(scanSelectItem); var scanClickItem = new NSMenuItem("Scan - click", OnScanClick); scanClickItem.BindHotKey(NSUserDefaultsController.SharedUserDefaultsController, Constants.KEY_HOTKEY_SCAN_CLICK); menu.AddItem(scanClickItem); menu.AddItem(NSMenuItem.SeparatorItem); menu.AddItem(new NSMenuItem("Preferences", OnPreferences)); menu.AddItem(new NSMenuItem("Check for updates", OnCheckForUpdates)); menu.AddItem(new NSMenuItem("Quit", OnQuit)); _statusItem.Menu = menu; }
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 void Add(MenuItem item) { items.Add(item); nsmenu.AddItem(item); }
public override NSMenu GetMenu (FIMenuKind menuKind) { var menu = new NSMenu (string.Empty); menu.AddItem ("Get URL", new ObjCRuntime.Selector ("getURL:"), string.Empty); return menu; }
public StatusIcon() : base() { using (var a = new NSAutoreleasePool()) { CreateAnimationFrames(); this.status_item = NSStatusBar.SystemStatusBar.CreateStatusItem(28); this.status_item.HighlightMode = true; this.status_item.Image = this.animation_frames [0]; this.status_item.Image = this.animation_frames [0]; this.status_item.Image.Size = new SizeF(16, 16); this.status_item.AlternateImage = this.animation_frames_active [0]; this.status_item.AlternateImage.Size = new SizeF(16, 16); CreateMenu(); } Controller.UpdateIconEvent += delegate(int icon_frame) { using (var a = new NSAutoreleasePool()) { BeginInvokeOnMainThread(delegate { if (icon_frame > -1) { this.status_item.Image = this.animation_frames [icon_frame]; this.status_item.Image.Size = new SizeF(16, 16); this.status_item.AlternateImage = this.animation_frames_active [icon_frame]; this.status_item.AlternateImage.Size = new SizeF(16, 16); } else { this.status_item.Image = this.error_image; this.status_item.AlternateImage = this.error_image_active; this.status_item.Image.Size = new SizeF(16, 16); this.status_item.AlternateImage.Size = new SizeF(16, 16); } }); } }; Controller.UpdateStatusItemEvent += delegate(string state_text) { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { this.state_item.Title = state_text; }); } }; Controller.UpdateMenuEvent += delegate { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(() => CreateMenu()); } }; Controller.UpdateSuspendSyncFolderEvent += delegate(string reponame) { using (var a = new NSAutoreleasePool()){ InvokeOnMainThread(delegate { NSMenuItem PauseItem; if (FolderItems.TryGetValue(reponame, out PauseItem)) { setSyncItemState(PauseItem, getSyncStatus(reponame)); } }); } }; // TODO Need to implement this method like the COCOA way to do it Controller.UpdateTransmissionMenuEvent += delegate { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { List <FileTransmissionEvent> transmissions = Program.Controller.ActiveTransmissions(); NSMenu transmissionmenu = new NSMenu(); foreach (FileTransmissionEvent transmission in transmissions) { NSMenuItem transmissionItem = new TransmissionMenuItem(transmission); transmissionmenu.AddItem(transmissionItem); } if (transmissions.Count > 0) { state_item.Submenu = transmissionmenu; state_item.Enabled = true; } else { state_item.Enabled = false; } }); } }; }
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); } }; }
static NSMenu FromMenu (ContextMenu menu) { var result = new NSMenu () { AutoEnablesItems = false }; foreach (var menuItem in menu.Items) { var item = CreateMenuItem (menuItem); result.AddItem (item); } return result; }
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; }
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; if (parent.Count > index) parent.InsertItem (n, index); else parent.AddItem (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); if (parent.Count > index) parent.InsertItem (item, index); else parent.AddItem (item); index++; } index--; }
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); }
//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)); }
private void InitializeUserInterfaces() { openNiconicoUrlOnSuccess = false; searchLevel = 3; // init search levels var levelMenu = new NSMenu(); foreach (var n in Enumerable.Range(0, 11)) { var item = new NSMenuItem(n.ToString()); item.Activated += (sender, e) => { searchLevel = n; if (!string.IsNullOrEmpty(lastUri)) FindImage(lastUri); }; levelMenu.AddItem(item); } SearchLevelSelector.Menu = levelMenu; SearchLevelSelector.SelectItem(3); TargetImageView.FileDropped += (sender, e) => FindImage(e.Payload); TargetImageView.ImageUrlDropped += (sender, e) => FindImageByUrl(e.Payload); }
public void CreateMenu() { using (NSAutoreleasePool a = new NSAutoreleasePool()) { this.menu = new NSMenu(); this.menu.AutoEnablesItems = false; this.FolderItems = new Dictionary <String, NSMenuItem>(); this.state_item = new NSMenuItem() { Title = Controller.StateText, Enabled = false }; this.log_item = new NSMenuItem() { Title = CmisSync.Properties_Resources.ViewLog }; this.log_item.Activated += delegate { Controller.LogClicked(); }; this.add_item = new NSMenuItem() { Title = CmisSync.Properties_Resources.AddARemoteFolder, Enabled = true }; this.add_item.Activated += delegate { Controller.AddRemoteFolderClicked(); }; this.about_item = new NSMenuItem() { Title = CmisSync.Properties_Resources.About, Enabled = true }; this.about_item.Activated += delegate { Controller.AboutClicked(); }; this.quit_item = new NSMenuItem() { Title = CmisSync.Properties_Resources.Exit, Enabled = true }; this.quit_item.Activated += delegate { Controller.QuitClicked(); }; this.menu.AddItem(this.state_item); this.menu.AddItem(NSMenuItem.SeparatorItem); if (Controller.Folders.Length > 0) { foreach (string folder_name in Controller.Folders) { this.menu.AddItem(CreateFolderMenuItem(folder_name)); } ; if (Controller.OverflowFolders.Length > 0) { NSMenuItem moreitem = new NSMenuItem(); moreitem.Title = "More Folder"; NSMenu moreitemsmenu = new NSMenu(); foreach (string folder_name in Controller.OverflowFolders) { moreitemsmenu.AddItem(CreateFolderMenuItem(folder_name)); } ; moreitem.Submenu = moreitemsmenu; this.menu.AddItem(moreitem); } this.menu.AddItem(NSMenuItem.SeparatorItem); } this.menu.AddItem(this.add_item); this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.log_item); this.menu.AddItem(this.about_item); this.menu.AddItem(NSMenuItem.SeparatorItem); this.menu.AddItem(this.quit_item); this.menu.Delegate = new StatusIconMenuDelegate(); this.status_item.Menu = this.menu; } }
NSMenu CreateSubMenuForRuntime (IRuntimeModel runtime) { if (!runtime.Children.Any ()) return null; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = true, Font = NSFont.MenuFontOfSize (12), }; foreach (var item in runtime.Children) if (item.IsSeparator) menu.AddItem (NSMenuItem.SeparatorItem); else CreateMenuItem (menu, item); return menu; }
/// <summary> /// Recursively build a menu from the set of Language Format Commands. /// </summary> /// <param name="menu">The <c>NSMenu</c> to grow.</param> /// <param name="commands">The list of <see cref="AppKit.TextKit.Formatter.LanguageFormatCommand"/>s.</param> private void AssembleMenu(NSMenu menu, List<LanguageFormatCommand> commands) { NSMenuItem menuItem; // Add any formatting commands to the Formatting menu foreach (LanguageFormatCommand command in commands) { // Add separator or item? if (command.Title == "") { menuItem = NSMenuItem.SeparatorItem; } else { menuItem = new NSMenuItem (command.Title); // Submenu? if (command.SubCommands.Count > 0) { // Yes, populate submenu menuItem.Submenu = new NSMenu (command.Title); AssembleMenu (menuItem.Submenu, command.SubCommands); } else { // No, add normal menu item menuItem.Activated += (sender, e) => { // Apply the command on the selected text TextEditor.PerformFormattingCommand (command); }; } } menu.AddItem (menuItem); } }
NSMenuItem CreateMenuItem (NSMenu menu, IRuntimeModel runtime) { NSMenuItem menuItem; string runtimeFullDisplayString; using (var mutableModel = runtime.GetMutableModel ()) { runtimeFullDisplayString = mutableModel.FullDisplayString; menuItem = new NSMenuItem () { IndentationLevel = runtime.IsIndented ? 1 : 0, 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, }; if (ActiveRuntime == runtime || (ActiveRuntime?.Children.Contains (runtime) ?? false)) { menuItem.State = NSCellStateValue.On; } } var subMenu = CreateSubMenuForRuntime (runtime); if (subMenu != null) { menuItem.Submenu = subMenu; menuItem.Enabled = true; } else { menuItem.Activated += (o2, e2) => { ActiveRuntime = runtime; }; } menu.AddItem (menuItem); return menuItem; }
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 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); }
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); }
public override NSMenu MenuForEvent (NSEvent theEvent) { CGPoint pt = this.ConvertPointToView (theEvent.LocationInWindow, null); int row = (int)this.GetRow (pt); if (row >= 0) { NSObject obj = this.ItemAtRow (row); if (obj != null) { NSMenu menu = new NSMenu (); menu.Font = NSFont.UserFontOfSize((float)12.0); if (obj is ServerNode) { ServerNode serverNode = obj as ServerNode; if (serverNode.IsLoggedIn) { // NSMenuItem logout = new NSMenuItem ("Logout", serverNode.OnLogout); // // var image = NSImage.ImageNamed ("NSLockLockedTemplate"); // logout.Image = image; // logout.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (logout); NSMenuItem addNewTenant = new NSMenuItem ("Add New Tenant", serverNode.OnAddNewTenant); var image = NSImage.ImageNamed ("NSAddTemplate"); addNewTenant.Image = image; addNewTenant.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (addNewTenant); // NSMenuItem addExistingTenant = new NSMenuItem ("Add Existing Tenant", serverNode.OnAddExistingTenant); // image = NSImage.ImageNamed ("NSAddTemplate"); // addExistingTenant.Image = image; // addExistingTenant.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (addExistingTenant); NSMenuItem activeDirectory = new NSMenuItem ("Active Directory", serverNode.OnShowActiveDirectory); image = NSImage.ImageNamed ("NSNetwork"); activeDirectory.Image = image; activeDirectory.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (activeDirectory); NSMenuItem getComputers = new NSMenuItem ("Computers", serverNode.OnShowComputers); image = NSImage.ImageNamed ("NSComputer"); getComputers.Image = image; getComputers.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (getComputers); NSMenuItem tokenWizard = new NSMenuItem ("Diagnostics", serverNode.ShowTokenWizard); image = NSImage.ImageNamed ("NSRevealFreestandingTemplate"); tokenWizard.Image = image; tokenWizard.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (tokenWizard); // NSMenuItem httpTransport = new NSMenuItem ("Show HTTP Transport", serverNode.ShowHttpTransport); // image = NSImage.ImageNamed ("NSBookmarksTemplate"); // httpTransport.Image = image; // httpTransport.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (httpTransport); } // else { // NSMenuItem login = new NSMenuItem ("Login", serverNode.OnLogin); // var image = NSImage.ImageNamed ("NSLockLockedTemplate"); // login.Image = image; // login.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (login); // // NSMenuItem delete = new NSMenuItem ("Delete", serverNode.DeleteServer); // image = NSImage.ImageNamed ("NSTrashFull"); // delete.Image = image; // delete.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (delete); // } } else if (obj is TenantNode) { TenantNode tenantNode = obj as TenantNode; // NSMenuItem deleteTenant = new NSMenuItem ("Delete", tenantNode.Delete); // var image = NSImage.ImageNamed ("Delete_Object_64.png"); // deleteTenant.Image = image; // deleteTenant.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (deleteTenant); NSMenuItem showConfig = new NSMenuItem ("Tenant Configuration", tenantNode.ShowConfiguration); var image = NSImage.ImageNamed ("config.png"); showConfig.Image = image; showConfig.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (showConfig); } else if (obj is IdentitySourcesNode) { IdentitySourcesNode identitySources = obj as IdentitySourcesNode; NSMenuItem refreshSource = new NSMenuItem ("Refresh", identitySources.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); refreshSource.Image = image; refreshSource.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (refreshSource); } else if (obj is IdentitySourceNode) { IdentitySourceNode identitySourceNode = obj as IdentitySourceNode; NSMenuItem refreshSource = new NSMenuItem ("Refresh", identitySourceNode.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); refreshSource.Image = image; refreshSource.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (refreshSource); if (!identitySourceNode.IsDefaultDomain) { NSMenuItem setAsDefault = new NSMenuItem ("Set as default domain", identitySourceNode.SetAsDefault); menu.AddItem (setAsDefault); } } else if (obj is UsersNode) { UsersNode node = obj as UsersNode; NSMenuItem item = null; if (node.IsSystemDomain) { item = new NSMenuItem ("Add New User", node.AddNewUser); var image1 = NSImage.ImageNamed ("Add_User_64.png"); item.Image = image1; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is SolutionUsersNode) { SolutionUsersNode node = obj as SolutionUsersNode; NSMenuItem item = null; if (node.IsSystemDomain) { item = new NSMenuItem ("Add New Solution User", node.AddNewUser); var image1 = NSImage.ImageNamed ("Add_User_64.png"); item.Image = image1; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is GroupsNode) { GroupsNode node = obj as GroupsNode; NSMenuItem item = null; if (node.IsSystemDomain) { item = new NSMenuItem ("Add New Group", node.AddNewGroup); var image1 = NSImage.ImageNamed ("Add_Group_64.png"); item.Image = image1; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is RelyingPartyNode) { RelyingPartyNode node = obj as RelyingPartyNode; NSMenuItem item = null; item = new NSMenuItem ("Add Relying Party", node.AddRelyingParty); var image1 = NSImage.ImageNamed ("NSAddTemplate"); item.Image = image1; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is OidcClientNode) { OidcClientNode node = obj as OidcClientNode; NSMenuItem item = null; item = new NSMenuItem ("Add OIDC Client", node.AddOidcClient); var image1 = NSImage.ImageNamed ("NSAddTemplate"); item.Image = image1; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is IdentityProvidersNode) { IdentityProvidersNode node = obj as IdentityProvidersNode; NSMenuItem item = null; item = new NSMenuItem ("Add External Identity Provider", node.AddExternalIdentityProvider); menu.AddItem (item); item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is TrustedCertificateNode) { TrustedCertificateNode node = obj as TrustedCertificateNode; NSMenuItem item = null; item = new NSMenuItem ("Add Certificate Chain", node.AddCertificateChain); var image = NSImage.ImageNamed ("certificate.png"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); item = new NSMenuItem ("Refresh", node.Refresh); image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is ExternalDomainsNode) { ExternalDomainsNode node = obj as ExternalDomainsNode; NSMenuItem item = null; item = new NSMenuItem ("Add New External Domain", node.AddNewExternalDomain); var image1 = NSImage.ImageNamed ("NSAddTemplate"); item.Image = image1; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); } else if (obj is ExternalDomainNode) { ExternalDomainNode node = obj as ExternalDomainNode; NSMenuItem item = null; item = new NSMenuItem ("Refresh", node.Refresh); var image = NSImage.ImageNamed ("NSRefresh"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); item = new NSMenuItem ("Properties", node.View); image = NSImage.ImageNamed ("config.png"); item.Image = image; item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; menu.AddItem (item); // item = new NSMenuItem ("Delete", node.Delete); // image = NSImage.ImageNamed ("NSTrashFull"); // item.Image = image; // item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (item); } NSMenu.PopUpContextMenu (menu, theEvent, theEvent.Window.ContentView); } } return base.MenuForEvent (theEvent); }
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); } }
public void UpdateRecentFiles() { AppDelegate ad = (AppDelegate)NSApplication.SharedApplication.Delegate; var recentMenu = new NSMenu("DemoApp"); int count = 0; foreach (var item in Configuration.Settings.RecentFiles.Files) { if (System.IO.File.Exists(item.FileName)) { var menuItem = new NSMenuItem(System.IO.Path.GetFileName(item.FileName), (s, e) => { OpenSubtitlePromptForChanges(item.FileName); }); recentMenu.AddItem(menuItem); count++; } } if (count > 0) { recentMenu.AddItem(NSMenuItem.SeparatorItem); recentMenu.AddItem(new NSMenuItem("Clear", (s, e) => { Configuration.Settings.RecentFiles.Files.Clear(); UpdateRecentFiles(); })); } ad.OpenRecent.Submenu = recentMenu; }
public override NSMenu MenuForEvent(NSEvent theEvent) { CGPoint pt = this.ConvertPointToView(theEvent.LocationInWindow, null); int row = (int)this.GetRow(pt); if (row >= 0) { NSObject obj = this.ItemAtRow(row); if (obj != null) { NSMenu menu = new NSMenu(); menu.Font = NSFont.UserFontOfSize((float)12.0); if (obj is ServerNode) { ServerNode serverNode = obj as ServerNode; if (serverNode.IsLoggedIn) { // NSMenuItem logout = new NSMenuItem ("Logout", serverNode.OnLogout); // // var image = NSImage.ImageNamed ("NSLockLockedTemplate"); // logout.Image = image; // logout.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (logout); NSMenuItem addNewTenant = new NSMenuItem("Add New Tenant", serverNode.OnAddNewTenant); var image = NSImage.ImageNamed("NSAddTemplate"); addNewTenant.Image = image; addNewTenant.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(addNewTenant); // NSMenuItem addExistingTenant = new NSMenuItem ("Add Existing Tenant", serverNode.OnAddExistingTenant); // image = NSImage.ImageNamed ("NSAddTemplate"); // addExistingTenant.Image = image; // addExistingTenant.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (addExistingTenant); NSMenuItem activeDirectory = new NSMenuItem("Active Directory", serverNode.OnShowActiveDirectory); image = NSImage.ImageNamed("NSNetwork"); activeDirectory.Image = image; activeDirectory.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(activeDirectory); NSMenuItem getComputers = new NSMenuItem("Computers", serverNode.OnShowComputers); image = NSImage.ImageNamed("NSComputer"); getComputers.Image = image; getComputers.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(getComputers); NSMenuItem tokenWizard = new NSMenuItem("Diagnostics", serverNode.ShowTokenWizard); image = NSImage.ImageNamed("NSRevealFreestandingTemplate"); tokenWizard.Image = image; tokenWizard.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(tokenWizard); // NSMenuItem httpTransport = new NSMenuItem ("Show HTTP Transport", serverNode.ShowHttpTransport); // image = NSImage.ImageNamed ("NSBookmarksTemplate"); // httpTransport.Image = image; // httpTransport.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (httpTransport); } // else { // NSMenuItem login = new NSMenuItem ("Login", serverNode.OnLogin); // var image = NSImage.ImageNamed ("NSLockLockedTemplate"); // login.Image = image; // login.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (login); // // NSMenuItem delete = new NSMenuItem ("Delete", serverNode.DeleteServer); // image = NSImage.ImageNamed ("NSTrashFull"); // delete.Image = image; // delete.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (delete); // } } else if (obj is TenantNode) { TenantNode tenantNode = obj as TenantNode; // NSMenuItem deleteTenant = new NSMenuItem ("Delete", tenantNode.Delete); // var image = NSImage.ImageNamed ("Delete_Object_64.png"); // deleteTenant.Image = image; // deleteTenant.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (deleteTenant); NSMenuItem showConfig = new NSMenuItem("Tenant Configuration", tenantNode.ShowConfiguration); var image = NSImage.ImageNamed("config.png"); showConfig.Image = image; showConfig.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(showConfig); } else if (obj is IdentitySourcesNode) { IdentitySourcesNode identitySources = obj as IdentitySourcesNode; NSMenuItem refreshSource = new NSMenuItem("Refresh", identitySources.Refresh); var image = NSImage.ImageNamed("NSRefresh"); refreshSource.Image = image; refreshSource.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(refreshSource); } else if (obj is IdentitySourceNode) { IdentitySourceNode identitySourceNode = obj as IdentitySourceNode; NSMenuItem refreshSource = new NSMenuItem("Refresh", identitySourceNode.Refresh); var image = NSImage.ImageNamed("NSRefresh"); refreshSource.Image = image; refreshSource.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(refreshSource); if (!identitySourceNode.IsDefaultDomain) { NSMenuItem setAsDefault = new NSMenuItem("Set as default domain", identitySourceNode.SetAsDefault); menu.AddItem(setAsDefault); } } else if (obj is UsersNode) { UsersNode node = obj as UsersNode; NSMenuItem item = null; if (node.IsSystemDomain) { item = new NSMenuItem("Add New User", node.AddNewUser); var image1 = NSImage.ImageNamed("Add_User_64.png"); item.Image = image1; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is SolutionUsersNode) { SolutionUsersNode node = obj as SolutionUsersNode; NSMenuItem item = null; if (node.IsSystemDomain) { item = new NSMenuItem("Add New Solution User", node.AddNewUser); var image1 = NSImage.ImageNamed("Add_User_64.png"); item.Image = image1; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is GroupsNode) { GroupsNode node = obj as GroupsNode; NSMenuItem item = null; if (node.IsSystemDomain) { item = new NSMenuItem("Add New Group", node.AddNewGroup); var image1 = NSImage.ImageNamed("Add_Group_64.png"); item.Image = image1; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is RelyingPartyNode) { RelyingPartyNode node = obj as RelyingPartyNode; NSMenuItem item = null; item = new NSMenuItem("Add Relying Party", node.AddRelyingParty); var image1 = NSImage.ImageNamed("NSAddTemplate"); item.Image = image1; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is OidcClientNode) { OidcClientNode node = obj as OidcClientNode; NSMenuItem item = null; item = new NSMenuItem("Add OIDC Client", node.AddOidcClient); var image1 = NSImage.ImageNamed("NSAddTemplate"); item.Image = image1; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is IdentityProvidersNode) { IdentityProvidersNode node = obj as IdentityProvidersNode; NSMenuItem item = null; item = new NSMenuItem("Add External Identity Provider", node.AddExternalIdentityProvider); menu.AddItem(item); item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is TrustedCertificateNode) { TrustedCertificateNode node = obj as TrustedCertificateNode; NSMenuItem item = null; item = new NSMenuItem("Add Certificate Chain", node.AddCertificateChain); var image = NSImage.ImageNamed("certificate.png"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); item = new NSMenuItem("Refresh", node.Refresh); image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is ExternalDomainsNode) { ExternalDomainsNode node = obj as ExternalDomainsNode; NSMenuItem item = null; item = new NSMenuItem("Add New External Domain", node.AddNewExternalDomain); var image1 = NSImage.ImageNamed("NSAddTemplate"); item.Image = image1; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); } else if (obj is ExternalDomainNode) { ExternalDomainNode node = obj as ExternalDomainNode; NSMenuItem item = null; item = new NSMenuItem("Refresh", node.Refresh); var image = NSImage.ImageNamed("NSRefresh"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); item = new NSMenuItem("Properties", node.View); image = NSImage.ImageNamed("config.png"); item.Image = image; item.Image.Size = new CGSize { Width = (float)16.0, Height = (float)16.0 }; menu.AddItem(item); // item = new NSMenuItem ("Delete", node.Delete); // image = NSImage.ImageNamed ("NSTrashFull"); // item.Image = image; // item.Image.Size = new CGSize{ Width = (float)16.0, Height = (float)16.0 }; // menu.AddItem (item); } NSMenu.PopUpContextMenu(menu, theEvent, theEvent.Window.ContentView); } } return(base.MenuForEvent(theEvent)); }
public override void MouseDown (NSEvent theEvent) { if (!Enabled) return; var locationInView = ConvertPointFromView (theEvent.LocationInWindow, null); var cellIdx = IndexOfCellAtX (locationInView.X); if (cellIdx == -1) { return; } var item = Cells [cellIdx]; if (item == null || !item.Enabled) return; var componentRect = ((NSPathCell)Cell).GetRect (item, Frame, this); int i = 0; NSMenuItem selectedItem = null; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = false, Font = NSFont.MenuFontOfSize (12), }; if (cellIdx == RunConfigurationIdx) { if (ActiveRunConfiguration == null) return; foreach (var configuration in RunConfigurationModel) { var _configuration = configuration; var menuitem = new NSMenuItem (configuration.DisplayString, (o2, e2) => { ActiveRunConfiguration = runConfigurationModel.First (c => c.OriginalId == _configuration.OriginalId); }) { Enabled = true, IndentationLevel = 1, }; menu.AddItem (menuitem); if (selectedItem == null && configuration.OriginalId == ActiveRunConfiguration.OriginalId) selectedItem = menuitem; } } else if (cellIdx == ConfigurationIdx) { if (ActiveConfiguration == null) return; foreach (var configuration in ConfigurationModel) { var _configuration = configuration; var menuitem = new NSMenuItem (configuration.DisplayString, (o2, e2) => { ActiveConfiguration = configurationModel.First (c => c.OriginalId == _configuration.OriginalId); }) { Enabled = true, IndentationLevel = 1, }; menu.AddItem (menuitem); if (selectedItem == null && configuration.OriginalId == ActiveConfiguration.OriginalId) selectedItem = menuitem; } } else if (cellIdx == RuntimeIdx) { if (ActiveRuntime == null) return; using (var activeMutableModel = ActiveRuntime.GetMutableModel ()) { foreach (var runtime in RuntimeModel) { if (runtime.HasParent) continue; NSMenuItem menuitem = null; if (runtime.IsSeparator) menu.AddItem (NSMenuItem.SeparatorItem); else menuitem = CreateMenuItem (menu, runtime); using (var mutableModel = runtime.GetMutableModel ()) { if (selectedItem == null && menuitem != null && mutableModel.DisplayString == activeMutableModel.DisplayString) selectedItem = menuitem; } ++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 (selectedItem, offs, this); } }