예제 #1
0
 private void EraseShortcut(Keys shortcut)
 {
     // If the shortcut already exists then erase it.
     if (m_shortcuts.ContainsKey(shortcut))
     {
         object existingCommandTag = m_shortcuts[shortcut];
         if (m_commandsById.ContainsKey(existingCommandTag))
         {
             CommandInfo existingInfo = m_commandsById[existingCommandTag];
             existingInfo.RemoveShortcut(shortcut);
             m_shortcuts.Remove(shortcut);
         }
     }
 }
예제 #2
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;
            }
        }