Пример #1
0
        public void RegisterKeyShortcut(KeyboardShortcut kc)
        {
            Ksr_All.Add(kc);

            switch (kc.Combination)
            {
            case KeyboardCombination.None:
                if (SafeKeys.Contains(kc.Key))
                {
                    Ksr_None.Add(kc.Key, kc);
                }
                break;

            case KeyboardCombination.Ctrl:
                Ksr_Ctrl.Add(kc.Key, kc);
                break;

            case KeyboardCombination.Alt:
                if (SafeKeys.Contains(kc.Key))
                {
                    Ksr_Alt.Add(kc.Key, kc);
                }
                break;

            case KeyboardCombination.Shift:
                if (SafeKeys.Contains(kc.Key))
                {
                    Ksr_Shift.Add(kc.Key, kc);
                }
                break;

            case KeyboardCombination.AltShift:
                Ksr_AltShift.Add(kc.Key, kc);
                break;

            case KeyboardCombination.CtrlAlt:
                Ksr_CtrlAlt.Add(kc.Key, kc);
                break;

            case KeyboardCombination.CtrlShift:
                Ksr_CtrlShift.Add(kc.Key, kc);
                break;

            case KeyboardCombination.CtrlAltShift:
                Ksr_CtrlAltShift.Add(kc.Key, kc);
                break;
            }

            ShortcutRegistered?.Invoke(this, new KeyboardShortcutEventArgs(kc));
        }
Пример #2
0
        public void RegisterKeyShortcut(KeyboardCombination combination, Key key, RoutedEventHandler method, string methodId, MenuItem?menuItem)
        {
            KeyboardShortcut kc = new KeyboardShortcut(combination, key, method, methodId, menuItem);

            RegisterKeyShortcut(kc);
        }
Пример #3
0
 public KeyboardShortcutEventArgs(KeyboardShortcut shortcut)
 {
     KeyboardShortcut = shortcut;
 }
Пример #4
0
        public static List <KeyboardShortcut> LoadFromFile(string file, RoutedMethodRegistry?methodList)
        {
            if (!File.Exists(file))
            {
                throw new ArgumentException("The specified file does not exist. Keyboard shortcuts cannot be loaded.");
            }

            List <KeyboardShortcut> entries = new List <KeyboardShortcut>();

            XmlReader xr = XmlReader.Create(file);

            xr.MoveToContent();

            while (xr.Read())
            {
                if (xr.NodeType == XmlNodeType.Element)
                {
                    //xr.ReadStartElement("ks");

                    string c = xr.GetAttribute("comb");
                    string k = xr.GetAttribute("keyid");
                    string m = xr.GetAttribute("methodid");

                    if (string.IsNullOrEmpty(c) || string.IsNullOrEmpty(k) || string.IsNullOrEmpty(m))
                    {
                        // skip item
                    }
                    else if (Enum.TryParse(c, out KeyboardCombination kc))
                    {
                        if (int.TryParse(k, out int kv))
                        {
                            RoutedEventHandler?reh = null;
                            MenuItem?          mi  = null;

                            if (methodList != null)
                            {
                                if (methodList.Contains(m))
                                {
                                    var v = methodList[m];
                                    reh = v.handler;
                                    mi  = v.menuItem;
                                }
                                else if (methodList.Contains("mnu" + m))
                                {
                                    m = "mnu" + m;

                                    var v = methodList[m];
                                    reh = v.handler;
                                    mi  = v.menuItem;
                                }
                                else if (methodList.Contains("btn" + m))
                                {
                                    m = "btn" + m;

                                    var v = methodList[m];
                                    reh = v.handler;
                                    mi  = v.menuItem;
                                }
                            }
                            KeyboardShortcut ke = new KeyboardShortcut(kc, (Key)kv, reh, m, mi);
                            entries.Add(ke);
                        }
                        else
                        {
                            if (Enum.TryParse(k, out Key kz))
                            {
                                RoutedEventHandler?reh = null;
                                MenuItem?          mi  = null;

                                if (methodList != null)
                                {
                                    if (methodList.Contains(m))
                                    {
                                        var v = methodList[m];
                                        reh = v.handler;
                                        mi  = v.menuItem;
                                    }
                                    else if (methodList.Contains("mnu" + m))
                                    {
                                        m = "mnu" + m;

                                        var v = methodList[m];
                                        reh = v.handler;
                                        mi  = v.menuItem;
                                    }
                                    else if (methodList.Contains("btn" + m))
                                    {
                                        m = "btn" + m;

                                        var v = methodList[m];
                                        reh = v.handler;
                                        mi  = v.menuItem;
                                    }
                                }
                                KeyboardShortcut ke = new KeyboardShortcut(kc, kz, reh, m, mi);
                                entries.Add(ke);
                            }
                        }
                    }

                    //xr.ReadEndElement();
                }
            }

            xr.Close();

            return(entries);
        }