public MDMenu(CommandManager manager, CommandEntrySet ces, CommandSource commandSource, object initialCommandTarget, EventHandler closeHandler) { CloseHandler = closeHandler; this.WeakDelegate = this; AutoEnablesItems = false; Title = (ces.Name ?? "").Replace("_", ""); Font = NSFont.MenuFontOfSize(12); foreach (CommandEntry ce in ces) { if (ce.CommandId == Command.Separator) { AddItem(NSMenuItem.SeparatorItem); continue; } if (string.Equals(ce.CommandId as string, servicesID, StringComparison.Ordinal)) { AddItem(new MDServicesMenuItem()); continue; } var subset = ce as CommandEntrySet; if (subset != null) { AddItem(new MDSubMenuItem(manager, subset, commandSource, initialCommandTarget)); continue; } var lce = ce as LinkCommandEntry; if (lce != null) { AddItem(new MDLinkMenuItem(lce)); continue; } Command cmd = manager.GetCommand(ce.CommandId); if (cmd == null) { LoggingService.LogError("MacMenu: '{0}' maps to null command", ce.CommandId); continue; } if (cmd is CustomCommand) { LoggingService.LogWarning("MacMenu: '{0}' is unsupported custom-rendered command' '", ce.CommandId); continue; } var acmd = cmd as ActionCommand; if (acmd == null) { LoggingService.LogWarning("MacMenu: '{0}' has unknown command type '{1}'", cmd.GetType(), ce.CommandId); continue; } AddItem(new MDMenuItem(manager, ce, acmd, commandSource, initialCommandTarget)); } }
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); }
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); } }; }
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 = PathComponentCells [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 == 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); } }
void PopupMenuForCell(NSPathComponentCell item) { var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this); int i = 0; NSMenuItem selectedItem = null; var menu = new NSMenu { AutoEnablesItems = false, ShowsStateColumn = true, Font = NSFont.MenuFontOfSize(12), }; if (item.Identifier == RunConfigurationIdentifier) { 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 (item.Identifier == ConfigurationIdentifier) { 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 (item.Identifier == RuntimeIdentifier) { if (ActiveRuntime == null) { return; } using (var activeMutableModel = ActiveRuntime.GetMutableModel()) { foreach (var runtime in RuntimeModel) { 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(); } LastSelectedCell = IndexFromIdentifier(item.Identifier); 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); } }