Exemplo n.º 1
0
        /// <summary>
        /// Sets ToolStrip for MenuInfo</summary>
        /// <param name="menuInfo">ToolStrip for MenuInfo</param>
        /// <param name="toolStrip">ToolStrip to set</param>
        /// <param name="commandService">Command service</param>
        public static void SetToolStrip(this MenuInfo menuInfo, ToolStrip toolStrip, CommandService commandService)
        {
            if (menuInfo.CommandService != null && menuInfo.CommandService != commandService)
                throw new NullReferenceException("MenuInfo has already been registered to a CommandService, and it is not the one specified.");

            if (toolStrip == null)
                throw new InvalidTransactionException("ToolStrip cannot be null");

            if (commandService == null)
                throw new InvalidTransactionException("CommandService cannot be null");

            commandService.SetMenuToolStrip(menuInfo, toolStrip);
        }
Exemplo n.º 2
0
        private void RegisterClientCommands()
        {
            var clientList = m_documentClients.Select(l => l.Value)
                             .Where(dc => dc.Info.AllowStandardFileCommands)
                             .ToList();

            // for each document client, build file/new and file/open commands
            var index = 0;

            foreach (var client in clientList)
            {
                Keys newShortcut  = Keys.None;
                Keys openShortcut = Keys.None;

                if (index == 0)
                {
                    newShortcut  = Keys.Control | Keys.N;
                    openShortcut = Keys.Control | Keys.O;
                }

                object newIconKey  = client.Info.NewIconKey;
                string newIconName = client.Info.NewIconName;
                if ((RegisterCommands & CommandRegister.FileNew) == CommandRegister.FileNew)
                {
                    CommandService.RegisterCommand(
                        new CommandInfo(
                            new FileCommandTag(Command.FileNew, client),
                            StandardMenu.File,
                            StandardCommandGroup.FileNew,
                            clientList.Count > 1 ?
                            "New".Localize("Name of a command") + '/' + client.Info.FileType :
                            string.Format("New {0}".Localize(), client.Info.FileType),
                            string.Format("Creates a new {0} document".Localize("{0} is the type of document to create"), client.Info.FileType),
                            newShortcut,
                            (newIconKey != null) ? newIconKey : newIconName,
                            ((!string.IsNullOrEmpty(newIconName)) || (newIconKey != null)) ? CommandVisibility.All : CommandVisibility.Menu),
                        this);
                }

                object openIconKey  = client.Info.OpenIconKey;
                string openIconName = client.Info.OpenIconName;
                if ((RegisterCommands & CommandRegister.FileOpen) == CommandRegister.FileOpen)
                {
                    CommandService.RegisterCommand(
                        new CommandInfo(
                            new FileCommandTag(Command.FileOpen, client),
                            StandardMenu.File,
                            StandardCommandGroup.FileNew,
                            clientList.Count > 1 ?
                            "Open".Localize("Name of a command") + '/' + client.Info.FileType :
                            string.Format("Open {0}".Localize(), client.Info.FileType),
                            string.Format("Open an existing {0} document".Localize(), client.Info.FileType),
                            openShortcut,
                            (openIconKey != null) ? openIconKey : openIconName,
                            ((!string.IsNullOrEmpty(openIconName)) || (openIconKey != null)) ? CommandVisibility.All : CommandVisibility.Menu),
                        this);
                }

                index++;
            }
        }