Beispiel #1
0
        public LayeringCommands()
        {
            m_contextMenuStrip           = new ContextMenuStrip();
            m_contextMenuStrip.AutoClose = true;

            m_addLayer        = new ToolStripMenuItem("New Layer".Localize());
            m_addLayer.Click += (sender, e) => AddNewLayer();

            m_deleteLayer                          = new ToolStripMenuItem("Delete".Localize());
            m_deleteLayer.Click                   += (sender, e) => Delete();
            m_deleteLayer.ShortcutKeys             = Keys.Delete;
            m_deleteLayer.ShortcutKeyDisplayString = KeysUtil.KeysToString(Keys.Delete, true);
            m_deleteLayer.Image                    = ResourceUtil.GetImage16(CommandInfo.EditDelete.ImageName);

            m_contextMenuStrip.Items.Add(m_addLayer);
            m_contextMenuStrip.Items.Add(m_deleteLayer);
        }
        // Updates the UI from the private non-UI fields
        private void UpdateControls()
        {
            string strKey = KeysUtil.KeysToString(m_currentShortcut.Keys, false);
            bool   hasKey = !string.IsNullOrEmpty(strKey);

            btnRemoveShortcut.Enabled = hasKey;
            lblCurShortcut.Text       = (hasKey) ? strKey : null;

            btnSetToDefault.Enabled = !m_currentShortcut.KeysAreDefault;
            lblCmdDescription.Text  = m_currentShortcut.Info.Description;

            if (m_newKey == Keys.None)
            {
                txtNewShortcut.Text       = string.Empty;
                btnAddShortcut.Enabled    = false;
                btnAssignShortcut.Enabled = false;
                lblUsedBy.Text            = null;
                grpShortUsed.Enabled      = false;
            }
            else
            {
                txtNewShortcut.Text           = KeysUtil.KeysToString(m_newKey, false);
                txtNewShortcut.SelectionStart = txtNewShortcut.Text.Length;
                btnAddShortcut.Enabled        = true;
                btnAssignShortcut.Enabled     = true;
                string otherCommands = GetUsedByText(m_newKey);
                lblUsedBy.Text       = otherCommands;
                grpShortUsed.Enabled = otherCommands.Length > 0;
            }

            bool allCommandsAreDefault = true;

            foreach (Shortcut shortcut in m_shortcuts)
            {
                if (!shortcut.KeysAreDefault)
                {
                    allCommandsAreDefault = false;
                    break;
                }
            }
            btnAllDefault.Enabled = !allCommandsAreDefault;
        }
Beispiel #3
0
        public BookmarkLister(ICommandService commandService)
            : base(commandService)
        {
            Configure(out m_controlInfo);
            m_commandService = commandService;

            m_contextMenuStrip           = new ContextMenuStrip();
            m_contextMenuStrip.AutoClose = true;

            m_addBookmark        = new ToolStripMenuItem("Add Bookmark".Localize());
            m_addBookmark.Click += (sender, e) => AddBookmark();

            m_deleteBookmark                          = new ToolStripMenuItem("Delete".Localize());
            m_deleteBookmark.Click                   += (sender, e) => Delete();
            m_deleteBookmark.ShortcutKeys             = Keys.Delete;
            m_deleteBookmark.ShortcutKeyDisplayString = KeysUtil.KeysToString(Keys.Delete, true);
            m_deleteBookmark.Image                    = ResourceUtil.GetImage16(CommandInfo.EditDelete.ImageName);

            m_contextMenuStrip.Items.Add(m_addBookmark);
            m_contextMenuStrip.Items.Add(m_deleteBookmark);
        }
        // takes m_newKey and either replaces m_currentShortcut.Keys or adds to it, depending on 'addShortcut'
        private void SetShortcuts(bool addShortcut)
        {
            // only add when we have valid shortcut
            if (m_newKey == Keys.None)
            {
                return;
            }

            // don't assign reserved key
            if (m_reservedKeys.ContainsKey(m_newKey))
            {
                string newKeyString = KeysUtil.KeysToString(m_newKey, false);
                MessageBox.Show(this, newKeyString + " is reserved for " + m_reservedKeys[m_newKey], Text);
                return;
            }

            // remove shortcut from any other command that uses this shortcut
            RemoveShortcut(m_newKey);

            // assign the new key to the current command
            var newKeys = new List <Keys>();

            if (addShortcut)
            {
                foreach (Keys key in m_currentShortcut.Keys)
                {
                    if (key != Keys.None)
                    {
                        newKeys.Add(key);
                    }
                }
            }
            newKeys.Add(m_newKey);
            m_currentShortcut.Keys = newKeys;

            // reset
            m_newKey = Keys.None;
            UpdateControls();
        }
Beispiel #5
0
        private void RebuildShortcutKeyDisplayString()
        {
            // rebuild on when ShortcutChanged event is raised.

            StringBuilder displayString = new StringBuilder();

            foreach (Keys k in Shortcuts)
            {
                if (k == Keys.None)
                {
                    continue;
                }

                if (displayString.Length > 0)
                {
                    displayString.Append(" ; ");
                }
                displayString.Append(KeysUtil.KeysToString(k, true));
            }

            ShortcutKeyDisplayString = displayString.ToString();
        }
Beispiel #6
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;
            }
        }