private bool VerifyShortcut(KeyEventArgs args)
        {
            OPMShortcut cmd = ShortcutMapper.MapCommand(args.KeyData);

            if (cmd == OPMShortcut.CmdOutOfRange)
            {
                // Key combination currently not assigned so it's OK to use it.
                return(true);
            }

            if (cmd == _cmd)
            {
                // Same command => ok to reassign.
                return(true);
            }

            string cmdOld = cmd.ToString().Replace("Cmd", string.Empty);
            string cmdNew = _cmd.ToString().Replace("Cmd", string.Empty);

            KeysConverter kc  = new KeysConverter();
            string        key = kc.ConvertToInvariantString(args.KeyData);

            if ((args.KeyData == Keys.Space && ShortcutMapper.IsPlayer) ||
                !ShortcutMapper.IsConfigurableShortcut(cmd))
            {
                // Key combination currently assigned
                // to a non-configurable command (e.g. F1 = help)
                MessageDisplay.Show(Translator.Translate("TXT_DUP_SHORTCUT_FIXED", key, cmdOld),
                                    Translator.Translate("TXT_DUPPLICATE_SHORTCUT"),
                                    MessageBoxIcon.Warning);
                return(false);
            }

            if (MessageDisplay.Query(Translator.Translate("TXT_DUP_SHORTCUT_CONFIRM", key, cmdOld, cmdNew),
                                     Translator.Translate("TXT_DUPPLICATE_SHORTCUT"),
                                     MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
            {
                // Key combination already assigned and the user did not want to change it use it.
                return(false);
            }

            // Unassign old shortcut
            if (ShortcutMapper.KeyCommands[(int)cmd].KeyData == args.KeyData)
            {
                // Was used for primary shortcut
                ShortcutMapper.KeyCommands[(int)cmd] = new KeyEventArgs(Keys.None);
            }
            else if (ShortcutMapper.AltKeyCommands[(int)cmd].KeyData == args.KeyData)
            {
                // Was used for alternate shortcut
                ShortcutMapper.AltKeyCommands[(int)cmd] = new KeyEventArgs(Keys.None);
            }

            return(true);
        }
Example #2
0
        private int ShortcutsSorter(OPMShortcut cmd1, OPMShortcut cmd2)
        {
            bool cfg1 = ShortcutMapper.IsConfigurableShortcut(cmd1);
            bool cfg2 = ShortcutMapper.IsConfigurableShortcut(cmd2);

            if (cfg1 != cfg2)
            {
                return(cfg1.CompareTo(cfg2));
            }
            else
            {
                return(cmd1.CompareTo(cmd2));
            }
        }
Example #3
0
 void lvShortcuts_SubItemEditing(object sender, ListViewSubItemEventArgs args)
 {
     if (args != null && args.Item != null && !args.Handled)
     {
         OPMShortcut cmd = (OPMShortcut)args.Item.Tag;
         if (ShortcutMapper.IsConfigurableShortcut(cmd))
         {
             if (args.SubItemIndex == hdrKey.Index)
             {
                 EditCommand(cmd, true);
             }
             else if (args.SubItemIndex == hdrAltkey.Index)
             {
                 EditCommand(cmd, false);
             }
         }
     }
 }
Example #4
0
        public void DisplayKeys()
        {
            try
            {
                User32.LockWindowUpdate(this.Handle);

                this.SuspendLayout();

                lvShortcuts.Items.Clear();

                List <OPMShortcut> shortcuts = new List <OPMShortcut>();
                for (OPMShortcut cmd = ShortcutMapper.CmdFirst; cmd < ShortcutMapper.CmdLast; cmd++)
                {
                    shortcuts.Add(cmd);
                }

                shortcuts.Sort(ShortcutsSorter);

                StringBuilder sb = new StringBuilder();

                foreach (OPMShortcut cmd in shortcuts)
                {
                    if (ShortcutMapper.IsHiddenShortcut(cmd))
                    {
                        continue;
                    }

                    string        cmdName = cmd.ToString();
                    string        desc    = Translator.Translate("TXT_" + cmdName.ToUpperInvariant());
                    KeysConverter kc      = new KeysConverter();
                    string        key     = kc.ConvertToInvariantString(ShortcutMapper.KeyCommands[(int)cmd].KeyData);
                    string        altKey  = kc.ConvertToInvariantString(ShortcutMapper.AltKeyCommands[(int)cmd].KeyData);

                    ListViewItem item = new ListViewItem(cmdName.Replace("Cmd", string.Empty));

                    OPMListViewSubItem subItemDesc   = new OPMListViewSubItem(item, desc);
                    OPMListViewSubItem subItemKey    = null;
                    OPMListViewSubItem subItemAltKey = null;

                    if (ShortcutMapper.IsConfigurableShortcut(cmd))
                    {
                        subItemKey    = new OPMListViewSubItem(_llEditKeys, item, key);
                        subItemAltKey = new OPMListViewSubItem(_llEditKeys, item, altKey);
                    }
                    else
                    {
                        subItemKey    = new OPMListViewSubItem(item, key);
                        subItemAltKey = new OPMListViewSubItem(item, altKey);
                    }

                    item.SubItems.Add(subItemDesc);
                    item.SubItems.Add(subItemKey);
                    item.SubItems.Add(subItemAltKey);


                    item.Tag = cmd;
                    lvShortcuts.Items.Add(item);

                    sb.AppendLine("<tr>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(item.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(subItemDesc.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(subItemKey.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(subItemAltKey.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine("Yes");
                    sb.AppendLine("</td>");

                    sb.AppendLine("</tr>");
                }

                this.ResumeLayout();
            }
            finally
            {
                User32.LockWindowUpdate(IntPtr.Zero);
            }
        }