Example #1
0
        /// <summary>
        /// Initializes this component</summary>
        public virtual void Initialize()
        {
            CommandInfo helpCommandInfo =
                CommandService.RegisterCommand(Commands.OpenHelpPage, StandardMenu.Help,
                                               StandardCommandGroup.HelpAbout, "Online Help".Localize(),
                                               "Opens an online help page for this app".Localize(), Keys.F1, null,
                                               CommandVisibility.ApplicationMenu, 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);
        }
Example #2
0
        private static CommandService.CommandControls GetCommandControls(this CommandInfo commandInfo)
        {
            if (commandInfo.CommandService == null)
            {
                throw new InvalidOperationException("CommandInfo has not been registered to a CommandService.");
            }

            var commandService = (CommandService)commandInfo.CommandService;

            if (commandService == null)
            {
                throw new InvalidOperationException("CommandInfo was registered to an ICommandService, but not specifically to a WinFormsCommandService.");
            }

            CommandService.CommandControls commandControls = commandService.GetCommandControls(commandInfo);
            if (commandControls == null)
            {
                throw new InvalidOperationException("WinForms CommandService to which CommandInfo thinks it's registered has no record of it.");
            }

            return(commandControls);
        }
Example #3
0
 /// <summary>
 /// Gets the ToolStripMenuItem and ToolStripButton associated with this CommandInfo that was
 /// previously registered to the WinForms Sce.Atf.Applications.CommandService</summary>
 /// <param name="commandInfo">CommandInfo</param>
 /// <param name="menuItem">ToolStripMenuItem associated with given CommandInfo</param>
 /// <param name="button">ToolStripButton associated with given CommandInfo</param>
 public static void GetMenuItemAndButton(this CommandInfo commandInfo, out ToolStripMenuItem menuItem, out ToolStripButton button)
 {
     CommandService.CommandControls controls = GetCommandControls(commandInfo);
     menuItem = controls.MenuItem;
     button   = controls.Button;
 }