protected override void RegisterCommandInfo(CommandInfo info) { // Embedded image resources will not be available as WPF app resources // If image resource does not exist we need to create it and add it to app resources object imageResourceKey = null; if ((info.ImageKey == null) && (!string.IsNullOrEmpty(info.ImageName))) { imageResourceKey = Sce.Atf.Wpf.ResourceUtil.GetKeyFromImageName(info.ImageName); info.ImageKey = imageResourceKey; } base.RegisterCommandInfo(info); // Associate the registered MenuInfo with this CommandService. Only can be registered once. info.CommandService = this; // If command has not been previously registered then create // a CommandItem for it and add it to the composition CommandItem command; if (!m_commandsLookup.TryGetValue(info.CommandTag, out command)) { command = new CommandItem(info, CanExecuteCommand, ExecuteCommand); m_commandsLookup.Add(command.CommandTag, command); if (m_composer != null) command.ComposablePart = m_composer.AddPart(command); } }
/// <summary> /// Registers a command for a command client</summary> /// <param name="info">Command description; standard commands are defined as static /// members on the CommandInfo class</param> /// <param name="client">Client that handles the command</param> public override void RegisterCommand(CommandInfo info, ICommandClient client) { base.RegisterCommand(info, client); if (info != null && client != null && info.CheckCanDoClients.Contains(client)) { m_checkCanDoClients.Add(info, client); m_checkCanDoClientsToUpdate.Add(info); } m_commandsSorted = false; }
public XLECamera() { CommandInfo = new CommandInfo( this, StandardMenu.View, StandardCommandGroup.ViewCamera, "camera".Localize() + "/" + "XLE".Localize(), "XLE orbit and pan camera".Localize(), Sce.Atf.Input.Keys.None, LevelEditorCore.Resources.MayaImage, CommandVisibility.Menu); }
public MayaStyleCameraController() { CommandInfo = new CommandInfo( this, StandardMenu.View, StandardCommandGroup.ViewCamera, "camera".Localize() + "/" + "Maya".Localize(), "Maya style camera".Localize(), Sce.Atf.Input.Keys.None, Resources.MayaImage, CommandVisibility.Menu); }
public WalkCameraController() { CommandInfo = new CommandInfo( this, StandardMenu.View, StandardCommandGroup.ViewCamera, "camera".Localize() + "/" + "Walk".Localize(), "Walk: WASD + Middle Mouse, press Alt+MiddleMouse for height, mouse wheel to adjust walk speed".Localize(), Sce.Atf.Input.Keys.None, Resources.WalkImage, CommandVisibility.Menu ); }
public FlyCameraController() { CommandInfo = new CommandInfo( this, StandardMenu.View, StandardCommandGroup.ViewCamera, "camera".Localize() + "/" + "Fly".Localize(), "Fly: WASD + Middle Mouse navigation, mouse-wheel to adjust speed".Localize(), Sce.Atf.Input.Keys.None, Resources.FlyImage, CommandVisibility.Menu ); }
public ArcBallCameraController() { CommandInfo = new CommandInfo( this, StandardMenu.View, StandardCommandGroup.ViewCamera, "camera".Localize() + "/" + "Arcball".Localize(), "Arcball".Localize(), Sce.Atf.Input.Keys.None, Resources.ArcballImage, CommandVisibility.Menu ); }
/// <summary> /// Finishes initializing component by setting up settings service and registering commands</summary> public virtual void Initialize() { if (m_settingsService != null) { BoundPropertyDescriptor recentDocumentCount = new BoundPropertyDescriptor(this, () => RecentDocumentCount, "Recent Files Count".Localize("Number of recent files to display in File Menu"), null, "Number of recent files to display in File Menu".Localize()); BoundPropertyDescriptor recentDocuments = new BoundPropertyDescriptor(this, () => RecentDocumentsAsCsv, "RecentDocuments", null, null); // Using the type name so that derived classes don't lose old user settings m_settingsService.RegisterSettings("Sce.Atf.Applications.RecentDocumentCommands", recentDocumentCount, recentDocuments); m_settingsService.RegisterUserSettings( "Documents".Localize(), recentDocumentCount); } if (CommandService != null) { var commandInfo = new CommandInfo(Command.Pin, StandardMenu.File, null, "Pin file".Localize("Pin active file to the recent files list"), "Pin active file to the recent files list".Localize(), Keys.None, Resources.PinGreenImage, CommandVisibility.Menu); CommandService.RegisterCommand(commandInfo, this); // Add an empty entry so the Recent Files menu shows up even if there are no // files in the list. This gets removed as soon as a file is added. m_emptyMruCommandInfo = new CommandInfo(Command.EmptyMru, StandardMenu.File, StandardCommandGroup.FileRecentlyUsed, "Recent Files".Localize() + "/(" + "empty".Localize() + ")", "No entries in recent files list".Localize(), Keys.None); CommandService.RegisterCommand( m_emptyMruCommandInfo, this); } }
/// <summary> /// Initializes this component</summary> public virtual void Initialize() { var helpCommandInfo = new CommandInfo(Commands.OpenHelpPage, StandardMenu.Help, StandardCommandGroup.HelpAbout, "Online Help".Localize(), "Opens an online help page for this app".Localize(), Sce.Atf.Input.Keys.F1, null, CommandVisibility.ApplicationMenu); helpCommandInfo.EnableCheckCanDoEvent(this); CommandService.RegisterCommand(helpCommandInfo, this); // We need to listen to the MenuItem's Click event, rather than the normal and otherwise // better way of using DoCommand, because the currently active Control might have a // WebHelp attached and it should take precedence if the user presses F1 but not if the // user uses the help menu command. CommandService.CommandControls controls = CommandService.GetCommandControls(helpCommandInfo); controls.MenuItem.Click += MenuItemOnClick; m_webHelp = MainForm.AddHelp(Url); }
public CommandItem(CommandInfo info, Func<ICommandItem, bool> canExecuteMethod, Action<ICommandItem> executeMethod) { m_info = info; m_text = info.DisplayedMenuText; MenuPath = ParseMenuPath(info.MenuText); m_description = info.Description; m_imageSourceKey = FixUpLegacyImage(info.ImageKey); info.ShortcutsChanged += Info_ShortcutsChanged; // Special hack here - if no menu tag is set then this command is only available // in context menus. Ideally should add CommandVisibility.ContextMenu option // for now just use CommandVisibility.None m_visibility = info.MenuTag != null ? info.Visibility : CommandVisibility.None; m_canExecuteMethod = canExecuteMethod; m_executeMethod = executeMethod; RebuildBinding(); }
/// <summary> /// Registers a command for a command client</summary> /// <param name="info">Command description; standard commands are defined as static /// members on the CommandInfo class</param> /// <param name="client">Client that handles the command</param> public override void RegisterCommand(CommandInfo info, ICommandClient client) { base.RegisterCommand(info, client); m_commandsSorted = false; }
private void RegisterMenuCommand(ControlInfo info, string text) { if (m_commandService != null) { object groupTag; if (info.MenuGroupTag != null) groupTag = info.MenuGroupTag; else if ((info.IsDocument.HasValue && info.IsDocument.Value) || info.Client is IDocumentClient) groupTag = StandardCommandGroup.WindowDocuments; else groupTag = StandardCommandGroup.WindowGeneral; var commandInfo = new CommandInfo( info.Control, StandardMenu.Window, groupTag, text, "Activate Window".Localize()); // CanDoCommand() always returns true, but UpdateCommand() updates 1) the menu // text from the Control's text and 2) the menu check mark depending on whether // the Control is visible and not hidden. We'd also have to keep track of these // CommandInfo objects. The performance gains don't seem worth the complexity. //commandInfo.EnableCheckCanDoEvent(this); m_commandService.RegisterCommand(commandInfo, this); } }
/// <summary> /// Force an update on a particular command</summary> /// <param name="info">Command to update</param> public void UpdateCommand(CommandInfo info) { ICommandClient client = GetClientOrActiveClient(info.CommandTag); UpdateCommand(info, client); }
/// <summary> /// Updates recent file menu items</summary> protected virtual void UpdateRecentFilesMenuItems() { if (CommandService != null) { var newCommandInfos = new List<CommandInfo>(); foreach (RecentDocumentInfo info in m_recentDocuments) { if (m_registeredRecentDocs.Contains(info)) { CommandService.UnregisterCommand(info, this); m_registeredRecentDocs.Remove(info); } } if (m_recentDocuments.Count > 0) { // Remove the "empty" entry from the MRU, since we have at least one document now. if (m_emptyMruCommandInfo != null) { CommandService.UnregisterCommand(m_emptyMruCommandInfo.CommandTag, this); m_emptyMruCommandInfo = null; } } foreach (RecentDocumentInfo info in m_recentDocuments.MostRecentOrder) { if (!m_registeredRecentDocs.Contains(info)) { string pathName = info.Uri.LocalPath; // replace slashes, so command service doesn't create hierarchical menu; actual path // is set in our UpdateCommand method. pathName = pathName.Replace("/", "-"); pathName = pathName.Replace("\\", "-"); var commandInfo = new CommandInfo( info, StandardMenu.File, StandardCommandGroup.FileRecentlyUsed, "Recent Files".Localize() + "/" + pathName, "Open a recently used file".Localize(), Keys.None); commandInfo.ImageName = info.Pinned ? Resources.PinGreenImage : Resources.PinGreyImage; commandInfo.ShortcutsEditable = false; CommandService.RegisterCommand( commandInfo, this); newCommandInfos.Add(commandInfo); m_registeredRecentDocs.Add(info); } } CommandInfos = newCommandInfos; } }
/// <summary> /// Constructor</summary> /// <param name="info">CommandInfo to use to initialize this object</param> /// <param name="commandPath">The menu names plus command name, each separated by '/'</param> public Shortcut(CommandInfo info, string commandPath) { Info = info; CommandPath = commandPath; Keys = info.Shortcuts; }
/// <summary> /// Gets the WinForms controls for a given CommandInfo instance</summary> /// <param name="info">CommandInfo instance</param> /// <returns>WinForms controls for given CommandInfo instance</returns> public CommandControls GetCommandControls(CommandInfo info) { if (info == null) throw new NullReferenceException("CommandInfo argument cannot be null"); return m_commandControls[info]; }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description); commandService.RegisterCommand(info, client); return info; }
/// <summary> /// Unregisters a unique CommandInfo object</summary> /// <param name="info">CommandInfo object to unregister</param> protected override void UnregisterCommandInfo(CommandInfo info) { CommandControls controls; if (m_commandControls.TryGetValue(info, out controls)) { controls.Dispose(); m_commandControls.Remove(info); } info.ShortcutsChanged -= commandInfo_ShortcutsChanged; info.VisibilityChanged -= commandInfo_VisibilityChanged; base.UnregisterCommandInfo(info); }
private void RegisterMenuCommand(ControlInfo info, string text) { if (m_commandService != null) { bool isDocument; if (info.IsDocument.HasValue) isDocument = info.IsDocument.Value; else isDocument = info.Client is IDocumentClient; var commandInfo = new CommandInfo( info.Control, StandardMenu.Window, isDocument ? StandardCommandGroup.WindowDocuments : StandardCommandGroup.WindowGeneral, text, "Activate Window".Localize()); // CanDoCommand() always returns true, so let's disable polling. commandInfo.EnableCheckCanDoEvent(this); m_commandService.RegisterCommand(commandInfo, this); } }
// Ensures that submenus exist to hold command private ToolStripItemCollection BuildSubMenus(ToolStripItemCollection commands, CommandInfo info) { string menuText = info.MenuText; string[] segments; if (menuText[0] == '@') segments = new[] { menuText.Substring(1, menuText.Length - 1) }; else segments = menuText.Split(s_pathDelimiters, 8); for (int i = 0; i < segments.Length - 1; i++) { string segment = segments[i]; ToolStripMenuItem subMenu = null; for (int j = 0; j < commands.Count; j++) { if (segment == commands[j].Text) { subMenu = commands[j] as ToolStripMenuItem; if (subMenu != null) break; } } if (subMenu == null) { subMenu = new ToolStripMenuItem(segment); subMenu.Name = segment; commands.Add(subMenu); MaintainSeparateGroups(commands, subMenu, info.GroupTag); } subMenu.BackColor = m_mainMenuStrip.BackColor; subMenu.ForeColor = m_mainMenuStrip.ForeColor; commands = subMenu.DropDownItems; } return commands; }
/// <summary> /// Registers a unique CommandInfo object</summary> /// <param name="info">CommandInfo object to register</param> protected override void RegisterCommandInfo(CommandInfo info) { m_commandsSorted = false; Image image = GetProperlySizedImage(info.ImageName); string uniqueId = GetCommandPath(info); // Create the WinForms controls to be associated with the registered MenuInfo var controls = new CommandControls( new ToolStripMenuItem(info.DisplayedMenuText, image), new ToolStripButton(info.MenuText, image) ); m_commandControls.Add(info, controls); // Associate the registered MenuInfo with this CommandService. Only can be registered once. info.CommandService = this; info.ShortcutsChanged += commandInfo_ShortcutsChanged; info.VisibilityChanged += commandInfo_VisibilityChanged; base.RegisterCommandInfo(info); ToolStripMenuItem menuItem = controls.MenuItem; menuItem.Name = uniqueId; menuItem.Tag = info.CommandTag; menuItem.MouseEnter += menuItem_MouseEnter; menuItem.MouseLeave += menuItem_MouseLeave; menuItem.MouseMove += menuItem_MouseMove; menuItem.Click += item_Click; ToolStripButton button = controls.Button; button.AutoSize = true; button.ImageScaling = ToolStripItemImageScaling.None; button.Name = uniqueId; button.DisplayStyle = (image != null) ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text; button.Tag = info.CommandTag; string toolTipText = info.Description; if (!string.IsNullOrEmpty(info.HelpUrl)) toolTipText += Environment.NewLine + "Press F1 for more info".Localize(); button.ToolTipText = toolTipText; button.Click += item_Click; }
// Adds a command to menus private void AddMenuCommand(ToolStripItemCollection commands, CommandInfo info) { // make sure all necessary sub-menus exist, and get command collection to hold this command commands = BuildSubMenus(commands, info); var menuItem = info.GetMenuItem(); menuItem.BackColor = m_mainMenuStrip.BackColor; menuItem.ForeColor = m_mainMenuStrip.ForeColor; commands.Add(menuItem); MaintainSeparateGroups(commands, menuItem, info.GroupTag); }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut, or Keys.None if none</param> /// <param name="imageKey">Object identifying image, or null if none</param> /// <param name="visibility">Whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, Keys shortcut, object imageKey, CommandVisibility visibility, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description, shortcut, imageKey, visibility); commandService.RegisterCommand(info, client); return info; }
/// <summary> /// Force an update on a particular command</summary> /// <param name="info">Command to update</param> public void UpdateCommand(CommandInfo info) { if (m_mainForm.InvokeRequired) { m_mainForm.BeginInvoke(new Action<CommandInfo>(UpdateCommand), info); return; } ToolStripMenuItem menuItem; ToolStripButton menuButton; info.GetMenuItemAndButton(out menuItem, out menuButton); CommandState commandState = new CommandState(); commandState.Text = info.DisplayedMenuText; commandState.Check = menuItem.Checked; ICommandClient client = GetClient(info.CommandTag); if (client == null) client = m_activeClient; bool enabled = false; if (client != null) { enabled = client.CanDoCommand(info.CommandTag); if (enabled) client.UpdateCommand(info.CommandTag, commandState); } string menuText = commandState.Text.Trim(); menuItem.Text = menuButton.Text = menuText; menuItem.Checked = menuButton.Checked = commandState.Check; menuItem.Enabled = menuButton.Enabled = enabled; }
/// <summary> /// This function redraws a particular menu item's icon. This is useful if only a /// specific icon has been changed; for example, on mouseover.</summary> /// <param name="info">The command whose icon needs a refresh</param> public override void RefreshImage(CommandInfo info) { Image image = GetProperlySizedImage(info.ImageName); if (image != null) { var button = info.GetButton(); button.AutoSize = true; button.ImageScaling = ToolStripItemImageScaling.None; button.Image = image; // Update the menu image too, but don't set AutoSize, as the menu icons // should always stay the same size. var menu = info.GetMenuItem(); menu.Image = image; } }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut, or Keys.None if none</param> /// <param name="imageName">Text identifying image, or null if none</param> /// <param name="visibility">Value describing whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, System.Windows.Forms.Keys shortcut, string imageName, CommandVisibility visibility, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description, KeysInterop.ToAtf(shortcut), imageName, visibility); commandService.RegisterCommand(info, client); return info; }