public GetCommand ( object cmdId ) : MonoDevelop.Components.Commands.Command | ||
cmdId | object | /// The identifier of the command /// |
리턴 | MonoDevelop.Components.Commands.Command |
public virtual Command GetCommand (CommandManager manager) { if (localCmd != null) { if (manager.GetCommand (localCmd.Id) == null) manager.RegisterCommand (localCmd); localCmd = null; } return manager.GetCommand (cmdId); }
public CommandMenuItem (object commandId, CommandManager commandManager, string overrideLabel, bool disabledVisible): base ("") { this.commandId = commandId; this.commandManager = commandManager; this.overrideLabel = overrideLabel; this.disabledVisible = disabledVisible; ActionCommand cmd = commandManager.GetCommand (commandId) as ActionCommand; if (cmd != null) isArray = cmd.CommandArray; }
public CommandCheckMenuItem (object commandId, CommandManager commandManager, string overrideLabel, bool disabledVisible): base ("") { this.commandId = commandId; this.commandManager = commandManager; this.overrideLabel = overrideLabel; this.disabledVisible = disabledVisible; ActionCommand cmd = commandManager.GetCommand (commandId) as ActionCommand; if (cmd != null && cmd.ActionType == ActionType.Radio) this.DrawAsRadio = true; }
public MDMenu (CommandManager manager, CommandEntrySet ces, CommandSource commandSource, object initialCommandTarget) { this.WeakDelegate = this; AutoEnablesItems = false; Title = (ces.Name ?? "").Replace ("_", ""); foreach (CommandEntry ce in ces) { if (ce.CommandId == Command.Separator) { AddItem (NSMenuItem.SeparatorItem); if (!string.IsNullOrEmpty (ce.OverrideLabel)) AddItem (new MDMenuHeaderItem (ce.OverrideLabel)); 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)); } }
static Gtk.MenuItem CreateMenuItem (CommandManager manager, Command cmd, object cmdId, bool isArrayMaster, string overrideLabel, bool disabledVisible) { cmdId = CommandManager.ToCommandId (cmdId); if (cmdId == CommandManager.ToCommandId (Command.Separator)) return new Gtk.SeparatorMenuItem (); if (cmd == null) cmd = manager.GetCommand (cmdId); if (cmd == null) { MonoDevelop.Core.LoggingService.LogWarning ("Unknown command '{0}'", cmdId); return new Gtk.MenuItem ("<Unknown Command>"); } if (cmd is CustomCommand) { Gtk.Widget child = (Gtk.Widget) Activator.CreateInstance (((CustomCommand)cmd).WidgetType); CustomMenuItem ti = new CustomMenuItem (); ti.Child = child; return ti; } ActionCommand acmd = cmd as ActionCommand; if (acmd.ActionType == ActionType.Normal || (isArrayMaster && acmd.CommandArray)) return new CommandMenuItem (cmdId, manager, overrideLabel, disabledVisible); else return new CommandCheckMenuItem (cmdId, manager, overrideLabel, disabledVisible); }
void InitApp (CommandManager commandManager) { if (initedApp) return; commandManager.CommandActivating += OnCommandActivating; //mac-ify these command names commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences..."); commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies..."); commandManager.GetCommand (HelpCommands.About).Text = GettextCatalog.GetString ("About {0}", BrandingService.ApplicationName); commandManager.GetCommand (MacIntegrationCommands.HideWindow).Text = GettextCatalog.GetString ("Hide {0}", BrandingService.ApplicationName); commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager..."); initedApp = true; IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent; if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) { IdeApp.Workbench.RootWindow.Realized += (sender, args) => { var win = GtkQuartz.GetWindow ((Gtk.Window) sender); win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary; }; } }
void InitApp (CommandManager commandManager) { if (initedApp) return; commandManager.CommandActivating += OnCommandActivating; //mac-ify these command names commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences..."); commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies..."); commandManager.GetCommand (HelpCommands.About).Text = GettextCatalog.GetString ("About {0}", BrandingService.ApplicationName); commandManager.GetCommand (MacIntegrationCommands.HideWindow).Text = GettextCatalog.GetString ("Hide {0}", BrandingService.ApplicationName); commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager..."); initedApp = true; IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent; if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) { IdeApp.Workbench.RootWindow.Realized += (sender, args) => { var win = GtkQuartz.GetWindow ((Gtk.Window) sender); win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary; }; } PatchGtkTheme (); NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Runtime.RunInMainThread ( delegate { Styles.LoadStyle(); PatchGtkTheme(); })); // FIXME: Immediate theme switching disabled, until NSAppearance issues are fixed //IdeApp.Preferences.UserInterfaceTheme.Changed += (s,a) => PatchGtkTheme (); }
void InitApp (CommandManager commandManager) { if (initedApp) return; MacMainMenu.SetAppQuitCommand (CommandManager.ToCommandId (FileCommands.Exit)); MacMainMenu.AddCommandIDMappings (new Dictionary<object, CarbonCommandID> () { { CommandManager.ToCommandId (EditCommands.Copy), CarbonCommandID.Copy }, { CommandManager.ToCommandId (EditCommands.Cut), CarbonCommandID.Cut }, { CommandManager.ToCommandId (EditCommands.MonodevelopPreferences), CarbonCommandID.Preferences }, { CommandManager.ToCommandId (EditCommands.Redo), CarbonCommandID.Redo }, { CommandManager.ToCommandId (EditCommands.Undo), CarbonCommandID.Undo }, { CommandManager.ToCommandId (EditCommands.SelectAll), CarbonCommandID.SelectAll }, { CommandManager.ToCommandId (FileCommands.NewFile), CarbonCommandID.New }, { CommandManager.ToCommandId (FileCommands.OpenFile), CarbonCommandID.Open }, { CommandManager.ToCommandId (FileCommands.Save), CarbonCommandID.Save }, { CommandManager.ToCommandId (FileCommands.SaveAs), CarbonCommandID.SaveAs }, { CommandManager.ToCommandId (FileCommands.CloseFile), CarbonCommandID.Close }, { CommandManager.ToCommandId (FileCommands.Exit), CarbonCommandID.Quit }, { CommandManager.ToCommandId (FileCommands.ReloadFile), CarbonCommandID.Revert }, { CommandManager.ToCommandId (HelpCommands.About), CarbonCommandID.About }, { CommandManager.ToCommandId (HelpCommands.Help), CarbonCommandID.AppHelp }, { CommandManager.ToCommandId (MacIntegrationCommands.HideWindow), CarbonCommandID.Hide }, { CommandManager.ToCommandId (MacIntegrationCommands.HideOthers), CarbonCommandID.HideOthers }, }); //mac-ify these command names commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences..."); commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies..."); commandManager.GetCommand (HelpCommands.About).Text = GettextCatalog.GetString ("About {0}", BrandingService.ApplicationName); commandManager.GetCommand (MacIntegrationCommands.HideWindow).Text = GettextCatalog.GetString ("Hide {0}", BrandingService.ApplicationName); commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager..."); initedApp = true; IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent; if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) { IdeApp.Workbench.RootWindow.Realized += (sender, args) => { var win = GtkQuartz.GetWindow ((Gtk.Window) sender); win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary; }; } }
static void InitApp (CommandManager commandManager) { if (initedApp) return; MacMainMenu.AddCommandIDMappings (new Dictionary<object, CarbonCommandID> () { { CommandManager.ToCommandId (EditCommands.Copy), CarbonCommandID.Copy }, { CommandManager.ToCommandId (EditCommands.Cut), CarbonCommandID.Cut }, //FIXME: for some reason mapping this causes two menu items to be created // { EditCommands.MonodevelopPreferences, CarbonCommandID.Preferences }, { CommandManager.ToCommandId (EditCommands.Redo), CarbonCommandID.Redo }, { CommandManager.ToCommandId (EditCommands.Undo), CarbonCommandID.Undo }, { CommandManager.ToCommandId (EditCommands.SelectAll), CarbonCommandID.SelectAll }, { CommandManager.ToCommandId (FileCommands.NewFile), CarbonCommandID.New }, { CommandManager.ToCommandId (FileCommands.OpenFile), CarbonCommandID.Open }, { CommandManager.ToCommandId (FileCommands.Save), CarbonCommandID.Save }, { CommandManager.ToCommandId (FileCommands.SaveAs), CarbonCommandID.SaveAs }, { CommandManager.ToCommandId (FileCommands.CloseFile), CarbonCommandID.Close }, { CommandManager.ToCommandId (FileCommands.Exit), CarbonCommandID.Quit }, { CommandManager.ToCommandId (FileCommands.ReloadFile), CarbonCommandID.Revert }, { CommandManager.ToCommandId (HelpCommands.About), CarbonCommandID.About }, { CommandManager.ToCommandId (HelpCommands.Help), CarbonCommandID.AppHelp }, }); //mac-ify these command names commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences..."); commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies..."); commandManager.GetCommand (HelpCommands.About).Text = string.Format (GettextCatalog.GetString ("About {0}"), BrandingService.ApplicationName); commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager..."); initedApp = true; MacMainMenu.SetAppQuitCommand (CommandManager.ToCommandId (FileCommands.Exit)); MacMainMenu.AddAppMenuItems ( commandManager, CommandManager.ToCommandId (HelpCommands.About), CommandManager.ToCommandId (MonoDevelop.Ide.Updater.UpdateCommands.CheckForUpdates), CommandManager.ToCommandId (Command.Separator), CommandManager.ToCommandId (EditCommands.MonodevelopPreferences), CommandManager.ToCommandId (EditCommands.DefaultPolicies), CommandManager.ToCommandId (ToolCommands.AddinManager)); IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent; }
public static void AddAppMenuItems (CommandManager manager, params object [] cmdIds) { //FIXME: we assume we get first pick of cmdIDs HIMenuItem mnu = HIToolbox.GetMenuItem ((uint)CarbonCommandID.Hide); appMenu = mnu.MenuRef; var appMenuId = HIToolbox.GetMenuID (appMenu); for (int i = cmdIds.Length - 1; i >= 0; i--) { var cmdId = cmdIds[i]; if (cmdId == Command.Separator) { HIToolbox.InsertMenuSeparator (mnu.MenuRef, 0); continue; } Command cmd = manager.GetCommand (cmdId); if (cmd == null){ MonoDevelop.Core.LoggingService.LogError ("Null command in Mac app menu for ID {0}", cmdId); continue; } uint macCmdId = GetNewMenuItemId (cmd); ushort pos = HIToolbox.InsertMenuItem (mnu.MenuRef, (cmd.Text ?? "").Replace ("_", ""), 0, 0, macCmdId); SetMenuAccelerator (new HIMenuItem (mnu.MenuRef, pos), cmd.AccelKey); menuIdMap[cmdId] = appMenuId; } }
public TitleMenuItem(MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null, Menu menu = null) { this.manager = manager; this.initialCommandTarget = initialCommandTarget; this.commandSource = commandSource; this.commandArrayInfo = commandArrayInfo; this.menu = menu; menuEntry = entry; menuEntrySet = entry as CommandEntrySet; menuLinkEntry = entry as LinkCommandEntry; if (commandArrayInfo != null) { Header = commandArrayInfo.Text; var commandArrayInfoSet = commandArrayInfo as CommandInfoSet; if (commandArrayInfoSet != null) { foreach (var item in commandArrayInfoSet.CommandInfos) { if (item.IsArraySeparator) { Items.Add(new Separator { UseLayoutRounding = true, }); } else { Items.Add(new TitleMenuItem(manager, entry, item, commandSource, initialCommandTarget, menu)); } } } } if (menuEntrySet != null) { Header = menuEntrySet.Name; foreach (CommandEntry item in menuEntrySet) { if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator) { Items.Add(new Separator { UseLayoutRounding = true, }); } else { Items.Add(new TitleMenuItem(manager, item, menu: menu)); } } } else if (menuLinkEntry != null) { Header = menuLinkEntry.Text; Click += OnMenuLinkClicked; } else if (entry != null) { actionCommand = manager.GetCommand(menuEntry.CommandId) as ActionCommand; if (actionCommand == null) { return; } IsCheckable = actionCommand.ActionType == ActionType.Check; // FIXME: Use proper keybinding text. if (actionCommand.KeyBinding != null) { InputGestureText = KeyBindingManager.BindingToDisplayLabel(actionCommand.KeyBinding, true); } try { if (!actionCommand.Icon.IsNull) { Icon = new ImageBox(actionCommand.Icon.GetStockIcon().WithSize(Xwt.IconSize.Small)); } } catch (Exception ex) { MonoDevelop.Core.LoggingService.LogError("Failed loading menu icon: " + actionCommand.Icon, ex); } Click += OnMenuClicked; } Height = SystemParameters.CaptionHeight; UseLayoutRounding = true; }
public TitleMenuItem(MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null) { this.manager = manager; this.initialCommandTarget = initialCommandTarget; this.commandSource = commandSource; this.commandArrayInfo = commandArrayInfo; menuEntry = entry; menuEntrySet = entry as CommandEntrySet; menuLinkEntry = entry as LinkCommandEntry; if (commandArrayInfo != null) { Header = commandArrayInfo.Text; var commandArrayInfoSet = commandArrayInfo as CommandInfoSet; if (commandArrayInfoSet != null) { foreach (var item in commandArrayInfoSet.CommandInfos) { if (item.IsArraySeparator) { Items.Add(new Separator { UseLayoutRounding = true, }); } else { Items.Add(new TitleMenuItem(manager, entry, item, commandSource, initialCommandTarget)); } } } } if (menuEntrySet != null) { Header = menuEntrySet.Name; foreach (CommandEntry item in menuEntrySet) { if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator) { Items.Add(new Separator { UseLayoutRounding = true, }); } else { Items.Add(new TitleMenuItem(manager, item)); } } } else if (menuLinkEntry != null) { Header = menuLinkEntry.Text; Click += OnMenuLinkClicked; } else if (entry != null) { actionCommand = manager.GetCommand(menuEntry.CommandId) as ActionCommand; if (actionCommand == null) { return; } IsCheckable = actionCommand.ActionType == ActionType.Check; // FIXME: Use proper keybinding text. if (actionCommand.KeyBinding != null) { InputGestureText = actionCommand.KeyBinding.ToString(); } if (!actionCommand.Icon.IsNull) { Icon = new Image { Source = actionCommand.Icon.GetImageSource(Xwt.IconSize.Small) } } ; Click += OnMenuClicked; } Height = SystemParameters.CaptionHeight; UseLayoutRounding = true; } /// <summary> /// Updates a command entry. Should only be called from a toplevel node. /// This will update all the menu's children. /// </summary> void Update() { hasCommand = false; if (menuLinkEntry != null) { return; } if (menuEntrySet != null || commandArrayInfo is CommandInfoSet) { for (int i = 0; i < Items.Count; ++i) { var titleMenuItem = Items[i] as TitleMenuItem; if (titleMenuItem != null) { titleMenuItem.Update(); continue; } // If we have a separator, don't draw another one if the previous visible item is a separator. var separatorMenuItem = Items [i] as Separator; separatorMenuItem.Visibility = Visibility.Collapsed; for (int j = i - 1; j >= 0; --j) { var iterMenuItem = Items [j] as Control; if (iterMenuItem is Separator) { break; } if (iterMenuItem.Visibility != Visibility.Visible) { continue; } separatorMenuItem.Visibility = Visibility.Visible; break; } } if (menuEntrySet != null && menuEntrySet.AutoHide) { Visibility = Items.Cast <Control> ().Any(item => item.Visibility == Visibility.Visible) ? Visibility.Visible : Visibility.Collapsed; } return; } var info = manager.GetCommandInfo(menuEntry.CommandId, new CommandTargetRoute(initialCommandTarget)); if (actionCommand != null) { if (!string.IsNullOrEmpty(info.Description) && (string)ToolTip != info.Description) { ToolTip = info.Description; } if (actionCommand.CommandArray && commandArrayInfo == null) { Visibility = Visibility.Collapsed; var parent = (TitleMenuItem)Parent; int count = 1; int indexOfThis = parent.Items.IndexOf(this); foreach (var child in info.ArrayInfo) { Control toAdd; if (child.IsArraySeparator) { toAdd = new Separator(); } else { toAdd = new TitleMenuItem(manager, menuEntry, child); } toRemoveFromParent.Add(toAdd); parent.Items.Insert(indexOfThis + (count++), toAdd); } return; } } SetInfo(commandArrayInfo != null ? commandArrayInfo : info); } bool hasCommand = false; void SetInfo(CommandInfo info) { hasCommand = true; Header = info.Text; Icon = new Image { Source = info.Icon.GetImageSource(Xwt.IconSize.Small) }; IsEnabled = info.Enabled; Visibility = info.Visible && (menuEntry.DisabledVisible || IsEnabled) ? Visibility.Visible : Visibility.Collapsed; IsChecked = info.Checked || info.CheckedInconsistent; ToolTip = info.Description; } /// <summary> /// Clears a command entry's saved data. Should only be called from a toplevel node. /// This will update all the menu's children. /// </summary> IEnumerable <Control> Clear() { if (menuLinkEntry != null) { return(Enumerable.Empty <TitleMenuItem> ()); } if (menuEntrySet != null) { var toRemove = Enumerable.Empty <Control> (); foreach (var item in Items) { var titleMenuItem = item as TitleMenuItem; if (titleMenuItem == null) { continue; } toRemove = toRemove.Concat(titleMenuItem.Clear()); } foreach (var item in toRemove) { Items.Remove(item); } return(Enumerable.Empty <TitleMenuItem> ()); } var ret = toRemoveFromParent; toRemoveFromParent = new List <Control> (); return(ret); }