/// <summary>
        /// Intercepts all key down strokes and populate textbox only on valid
        /// shortcut keys</summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void txtNewShortcut_KeyDown(object sender, KeyEventArgs e)
        {
            e.SuppressKeyPress = true;

            m_newKey = KeysUtil.KeyArgToKeys(e);
            m_newKey = KeysUtil.NumPadToNum(m_newKey);
            UpdateControls();
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Reserves a shortcut key, so it is not available as command shortcut</summary>
        /// <param name="key">Reserved key</param>
        /// <param name="reason">Reason why key is reserved to display to user</param>
        public void ReserveKey(Keys key, string reason)
        {
            if (key == Keys.None)
            {
                throw new ArgumentException("key");
            }
            if (reason == null)
            {
                throw new ArgumentNullException("reason");
            }

            // add or update key to reserved keys.
            key = KeysUtil.NumPadToNum(key);
            if (m_reservedKeys.ContainsKey(key))
            {
                m_reservedKeys[key] = reason;
            }
            else
            {
                m_reservedKeys[key] = reason;
                EraseShortcut(key);
            }
        }
Пример #4
0
        /// <summary>
        /// Sets shortcut</summary>
        /// <param name="shortcut">Shortcut keys</param>
        /// <param name="info">CommandInfo corresponding to shortcut keys</param>
        /// <remarks>Keeps m_shortcuts field, the menu item, and the CommandInfo in sync with regards to shortcuts
        /// and ensures that each shortcut is unique</remarks>
        protected void SetShortcut(Keys shortcut, CommandInfo info)
        {
            shortcut = KeysUtil.NumPadToNum(shortcut);

            // if shortcut is reserved then do not set it.
            if (m_reservedKeys.ContainsKey(shortcut))
            {
                Outputs.WriteLine(OutputMessageType.Warning, "cannot assign " + KeysUtil.KeysToString(shortcut, true) +
                                  " to " + GetCommandPath(info) + " it is reserved for " + m_reservedKeys[shortcut]);

                info.RemoveShortcut(shortcut);

                // erase shortcut if exist.
                EraseShortcut(shortcut);
                return;
            }

            info.AddShortcut(shortcut);

            if (shortcut != Keys.None)
            {
                // If the shortcut already exists for a different command, then erase the old commands's shortcut.
                if (m_shortcuts.ContainsKey(shortcut) &&
                    m_shortcuts[shortcut] != info.CommandTag)
                {
                    object existingCommandTag = m_shortcuts[shortcut];
                    if (m_commandsById.ContainsKey(existingCommandTag))
                    {
                        CommandInfo existingInfo = m_commandsById[existingCommandTag];
                        existingInfo.RemoveShortcut(shortcut);
                    }
                }

                m_shortcuts[shortcut] = info.CommandTag;
            }
        }