Exemplo n.º 1
0
        public bool SendCommand(CommandInfo ci)
        {
            Control focusedControl = Sce.Atf.WinFormsUtil.GetFocusedControl();

            while (focusedControl != null && !(focusedControl is ICommandClient))
            {
                focusedControl = focusedControl.Parent;
            }

            ICommandClient focusedCmdClient = focusedControl as ICommandClient;

            if (focusedCmdClient != null)
            {
                if (focusedCmdClient.CanDoCommand(ci.CommandTag))
                {
                    focusedCmdClient.DoCommand(ci.CommandTag);
                    return(true);
                }
            }

            focusedCmdClient = DocumentManager.GetInst().ActiveDocument as ICommandClient;
            if (focusedCmdClient != null)
            {
                if (focusedCmdClient.CanDoCommand(ci.CommandTag))
                {
                    focusedCmdClient.DoCommand(ci.CommandTag);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        IEnumerable <object> IContextMenuCommandProvider.GetCommands(object context, object target)
        {
            ICommandClient cmdclient = (ICommandClient)this;

            if (context == this.TreeView)
            {
                if (Adapters.Is <IGame>(target) || Adapters.Is <GameReference>(target) || Adapters.Is <IResolveable>(target))
                {
                    foreach (Command command in Enum.GetValues(typeof(Command)))
                    {
                        if (cmdclient.CanDoCommand(command))
                        {
                            yield return(command);
                        }
                    }
                }

                // Some nodes can provide extra context menu commands
                // Nodes that can will have an adapter derived from
                // IContextMenuCommandProvider
                var subProvider = target.As <IContextMenuCommandProvider>();
                if (subProvider != null)
                {
                    var subClient          = target.Cast <ICommandClient>();
                    var registeredCommands = GetRegisteredCommands(subProvider);
                    foreach (var command in registeredCommands.m_commands)
                    {
                        if (subClient.CanDoCommand(command))
                        {
                            yield return(command);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void item_Click(object sender, EventArgs e)
        {
            // See if the user clicked the icon portion of the menu item and set the IconClicked property that
            // interested commands can check.
            IconClicked = IsMouseOverIcon(sender as ToolStripItem);

            // clear status text
            if (m_statusService != null)
            {
                m_statusService.ShowStatus(string.Empty);
            }

            ToolStripItem item = sender as ToolStripItem;
            object        tag  = item.Tag;

            if (tag != null)
            {
                ICommandClient client = GetClient(tag);
                if (client == null)
                {
                    client = m_activeClient;
                }
                if (client != null && client.CanDoCommand(tag))
                {
                    client.DoCommand(tag);
                }
            }

            IconClicked = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Utility function to get the command's client and call UpdateCommand.</summary>
        /// <param name="commandTag">The command to update</param>
        /// <param name="state">Command's state</param>
        private void UpdatePinnableCommand(object commandTag, CommandState state)
        {
            ICommandClient client = GetClient(commandTag);

            if (client == null)
            {
                client = m_activeClient;
            }

            if (client != null && client.CanDoCommand(commandTag))
            {
                client.UpdateCommand(commandTag, state);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets tags for context menu (right click) commands</summary>
        /// <param name="context">Context containing target object</param>
        /// <param name="target">Right clicked object, or null if none</param>
        IEnumerable <object> IContextMenuCommandProvider.GetCommands(object context, object target)
        {
            ICommandClient cmdclient = (ICommandClient)this;

            if (context == m_paletteService.TreeView)
            {
                foreach (Command command in Enum.GetValues(typeof(Command)))
                {
                    if (cmdclient.CanDoCommand(command))
                    {
                        yield return(command);
                    }
                }
            }
        }
Exemplo n.º 6
0
        IEnumerable <object> IContextMenuCommandProvider.GetCommands(object context, object target)
        {
            ICommandClient cmdclient = (ICommandClient)this;

            if (context == this.TreeView &&
                (Adapters.Is <IGame>(target) || Adapters.Is <GameReference>(target)))
            {
                foreach (Command command in Enum.GetValues(typeof(Command)))
                {
                    if (cmdclient.CanDoCommand(command))
                    {
                        yield return(command);
                    }
                }
            }
        }
        private void OscServiceMessageReceived(object sender, OscMessageReceivedArgs e)
        {
            CommandInfo cmdInfo;

            if (m_addressesToCommands.TryGetValue(e.Address, out cmdInfo))
            {
                ICommandClient cmdClient = m_commandService.GetClient(cmdInfo.CommandTag);
                if (cmdClient != null)
                {
                    if (cmdClient.CanDoCommand(cmdInfo.CommandTag))
                    {
                        cmdClient.DoCommand(cmdInfo.CommandTag);
                    }
                }
                e.Handled = true;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Processes the key as a command shortcut</summary>
        /// <param name="key">Key to process</param>
        /// <returns>True iff the key was processed as a command shortcut</returns>
        public virtual bool ProcessKey(Keys key)
        {
            KeyEventArgs keyEventArgs = new KeyEventArgs(key);

            ProcessingKey.Raise(this, keyEventArgs);
            if (keyEventArgs.Handled)
            {
                return(true);
            }

            Keys shortcut = KeysUtil.NumPadToNum(key);

            //if there is no key, return
            if (shortcut == Keys.None)
            {
                return(false);
            }

            //if the key is not a registered shortcut, return
            object tag;

            if (!m_shortcuts.TryGetValue(shortcut, out tag))
            {
                return(false);
            }

            //Is there a client, and if so, can the client do the command?
            ICommandClient client = GetClient(tag);

            if (client == null)
            {
                client = m_activeClient;
            }
            if (client == null || !client.CanDoCommand(tag))
            {
                return(false);
            }

            // do the command
            client.DoCommand(tag);
            return(true);
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        private void UpdateCommand(CommandInfo info, ICommandClient client)
        {
            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;

            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;
        }