Esempio n. 1
0
        /// <summary>
        /// Creates and registers a command for a command client</summary>
        /// <param name="def">Command definition</param>
        /// <param name="client">Command client</param>
        /// <returns>ICommandItem for command</returns>
        public ICommandItem RegisterCommand(CommandDef def, ICommandClient client)
        {
            Requires.NotNull(client, "client");

            // Problem - what about same command tag registered in several places with different shortcuts
            // submenus etc?
            ICommandItem command;
            if (!m_commandsLookup.TryGetValue(def.CommandTag, out command))
            {
                if (!CommandIsUnique(def.MenuTag, def.CommandTag))
                {
                    throw new InvalidOperationException(
                        string.Format(
                            "Duplicate menu/command combination. CommandTag: {0}, MenuTag: {1}, GroupTag: {2}, MenuText: {3}",
                            def.CommandTag, def.GroupTag, def.MenuTag, def.Text));
                }

                command = new CommandItem(def, CanDoCommand, CommandExecuted);
                m_commands.Add(command);
                m_commands.Sort(new CommandComparer());
                m_commandsLookup.Add(command.CommandTag, command);
                int index = m_commands.IndexOf(command);
                CommandAdded.Raise<ItemInsertedEventArgs<ICommandItem>>(this, new ItemInsertedEventArgs<ICommandItem>(index, command));
            }

            m_commandClients.Add(def.CommandTag, client);

            return command;
        }
Esempio n. 2
0
        /// <summary>
        /// Creates and registers a command for a command client</summary>
        /// <param name="def">Command definition</param>
        /// <param name="client">Command client</param>
        /// <returns>ICommandItem for command</returns>
        public ICommandItem RegisterCommand(CommandDef def, ICommandClient client)
        {
            Requires.NotNull(client, "client");

            // Problem - what about same command tag registered in several places with different shortcuts
            // submenus etc?
            ICommandItem command;

            if (!m_commandsLookup.TryGetValue(def.CommandTag, out command))
            {
                if (!CommandIsUnique(def.MenuTag, def.CommandTag))
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Duplicate menu/command combination. CommandTag: {0}, MenuTag: {1}, GroupTag: {2}, MenuText: {3}",
                                  def.CommandTag, def.GroupTag, def.MenuTag, def.Text));
                }

                command = new CommandItem(def, CanDoCommand, CommandExecuted);
                m_commands.Add(command);
                m_commands.Sort(new CommandComparer());
                m_commandsLookup.Add(command.CommandTag, command);
                int index = m_commands.IndexOf(command);
                CommandAdded.Raise <ItemInsertedEventArgs <ICommandItem> >(this, new ItemInsertedEventArgs <ICommandItem>(index, command));
            }

            m_commandClients.Add(def.CommandTag, client);

            return(command);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates and registers a command</summary>
        /// <param name="commandRegistry">ICommandService</param>
        /// <param name="commandTag">Unique command ID</param>
        /// <param name="menuTag">Unique ID for menu command attached to</param>
        /// <param name="groupTag">Unique ID for command's group</param>
        /// <param name="menuText">Command text as it appears in menu</param>
        /// <param name="description">Command description</param>
        /// <param name="client">ICommandClient</param>
        /// <returns>ICommandItem for command</returns>
        public static ICommandItem RegisterCommand(
            this ICommandService commandRegistry,
            object commandTag,
            object menuTag,
            object groupTag,
            string menuText,
            string description,
            ICommandClient client)
        {
            Requires.NotNull(commandRegistry, "commandRegistry");
            var def = new CommandDef(commandTag, menuTag, groupTag, menuText, description);

            return(commandRegistry.RegisterCommand(def, client));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates and registers a command</summary>
        /// <param name="commandRegistry">ICommandService</param>
        /// <param name="commandTag">Unique command ID</param>
        /// <param name="menuTag">Unique ID for menu command attached to</param>
        /// <param name="groupTag">Unique ID for command's group</param>
        /// <param name="menuText">Command text as it appears in menu</param>
        /// <param name="description">Command description</param>
        /// <param name="shortcut">Command shortcut</param>
        /// <param name="imageSourceKey">Image resource for command</param>
        /// <param name="client">ICommandClient</param>
        /// <returns>ICommandItem for command</returns>
        public static ICommandItem RegisterCommand(
            this ICommandService commandRegistry,
            object commandTag,
            object menuTag,
            object groupTag,
            string menuText,
            string description,
            KeyGesture shortcut,
            object imageSourceKey,
            ICommandClient client)
        {
            Requires.NotNull(commandRegistry, "commandRegistry");
            var gestures = shortcut != null ? new InputGesture[] { shortcut } : null;
            var def      = new CommandDef(commandTag, menuTag, groupTag, menuText, null, description, imageSourceKey, gestures, CommandVisibility.Default);

            return(commandRegistry.RegisterCommand(def, client));
        }
Esempio n. 5
0
        public CommandItem(CommandDef def, 
            Func<object, bool> canExecuteMethod,
            Action<ICommandItem> executeMethod)
            : base(def.MenuTag, def.GroupTag, def.Text, def.Description)
        {
            m_commandTag = def.CommandTag;
            m_imageSourceKey = def.ImageSourceKey;
            m_inputGestures = def.InputGestures;
            m_menuPath = def.MenuPath;

            // 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 = def.MenuTag != null ? def.Visibility : CommandVisibility.None;
            m_canExecuteMethod = canExecuteMethod;
            m_executeMethod = executeMethod;

            RebuildBinding();
        }
Esempio n. 6
0
 /// <summary>
 /// Creates and registers a command</summary>
 /// <param name="commandRegistry">ICommandService</param>
 /// <param name="commandTag">Unique command ID</param>
 /// <param name="menuTag">Unique ID for menu command attached to</param>
 /// <param name="groupTag">Unique ID for command's group</param>
 /// <param name="menuText">Command text as it appears in menu</param>
 /// <param name="description">Command description</param>
 /// <param name="client">ICommandClient</param>
 /// <returns>ICommandItem for command</returns>
 public static ICommandItem RegisterCommand(
     this ICommandService commandRegistry,
     object commandTag,
     object menuTag,
     object groupTag,
     string menuText,
     string description,
     ICommandClient client)
 {
     Requires.NotNull(commandRegistry, "commandRegistry");
     var def = new CommandDef(commandTag, menuTag, groupTag, menuText, description);
     return commandRegistry.RegisterCommand(def, client);
 }
Esempio n. 7
0
 /// <summary>
 /// Creates and registers a command</summary>
 /// <param name="commandRegistry">ICommandService</param>
 /// <param name="commandTag">Unique command ID</param>
 /// <param name="menuTag">Unique ID for menu command attached to</param>
 /// <param name="groupTag">Unique ID for command's group</param>
 /// <param name="menuText">Command text as it appears in menu</param>
 /// <param name="description">Command description</param>
 /// <param name="shortcut">Command shortcut</param>
 /// <param name="imageSourceKey">Image resource for command</param>
 /// <param name="visibility">Flags indicating where command is visible: on toolbar, menus, etc.</param>
 /// <param name="client">ICommandClient</param>
 /// <returns>ICommandItem for command</returns>
 public static ICommandItem RegisterCommand(
     this ICommandService commandRegistry,
     object commandTag,
     object menuTag,
     object groupTag,
     string menuText,
     string description,
     KeyGesture shortcut,
     object imageSourceKey,
     CommandVisibility visibility,
     ICommandClient client)
 {
     Requires.NotNull(commandRegistry, "commandRegistry");
     var gestures = shortcut != null ? new InputGesture[] { shortcut } : null;
     var def = new CommandDef(commandTag, menuTag, groupTag, menuText, null, description, imageSourceKey, gestures, visibility);
     return commandRegistry.RegisterCommand(def, client);
 }
Esempio n. 8
0
        /// <summary>
        /// Registers a command for a command client.
        /// NOTE: CommandInfo.MenuItem and CommandInfo.Button will not be valid.
        /// Shortcut related properties and methods on CommandInfo will have no effect.</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 void RegisterCommand(Sce.Atf.Applications.CommandInfo info, Sce.Atf.Applications.ICommandClient client)
        {
            // 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 (!string.IsNullOrEmpty(info.ImageName))
            {
                var embeddedImage = ResourceUtil.GetImage(info.ImageName);
                if (embeddedImage == null)
                    throw new InvalidOperationException("Could not find embedded image: " + info.ImageName);

                Util.GetOrCreateResourceForEmbeddedImage(embeddedImage);
                imageResourceKey = embeddedImage;
            }

            // Convert text and path
            string displayText = GetDisplayMenuText(info.MenuText);
            info.DisplayedMenuText = displayText;

            string[] menuPath = GetMenuPath(info.MenuText);

            // Convert shortcuts
            var inputGestures = new List<InputGesture>();
            foreach (var formsKey in info.Shortcuts)
                inputGestures.Add(Util.ConvertKey(formsKey));

            // Create and register command passing this as command client
            var def = new CommandDef(
                info.CommandTag, 
                info.MenuTag, 
                info.GroupTag, 
                displayText,
                menuPath,
                info.Description,
                imageResourceKey,
                inputGestures.ToArray<InputGesture>(),
                info.Visibility);

            var clientAdapter = GetOrCreateClientAdapter(client);

            var command = m_commandService.RegisterCommand(def, clientAdapter);

            clientAdapter.AddCommand(command);
        }