Ejemplo n.º 1
0
        public List <HotKeyManager.HotKeyActions> SetHotKeyCombo(
            HotKeyManager.HotKeyActions action,
            HotKeyManager.KeyCombo combo)
        {
            List <HotKeyManager.HotKeyActions> hotKeyActionsList = new List <HotKeyManager.HotKeyActions>();

            string[] strArray = combo.states.Split('|');
            foreach (HotKeyManager.HotKeyActions key in this.HotKeys.Keys)
            {
                if (key != action && this.HotKeys[key].key == combo.key && (this.HotKeys[key].alt == combo.alt && this.HotKeys[key].control == combo.control) && this.HotKeys[key].shift == combo.shift)
                {
                    string states  = this.HotKeys[key].states;
                    char[] chArray = new char[1] {
                        '|'
                    };
                    foreach (string str in states.Split(chArray))
                    {
                        if (((IEnumerable <string>)strArray).Contains <string>(str))
                        {
                            this.HotKeys[key].key = Keys.None;
                            hotKeyActionsList.Add(key);
                        }
                    }
                }
            }
            this.HotKeys[action] = combo;
            hotKeyActionsList.Add(action);
            return(hotKeyActionsList);
        }
Ejemplo n.º 2
0
        public bool LoadProfile(string profileName, bool absolutepath = false)
        {
            string str = !absolutepath ? HotKeyManager._profileRootDirectory + "\\" + profileName + ".keys" : profileName;

            if (profileName == "~Default")
            {
                str = this._assetdir + "\\" + profileName + ".keys";
            }
            if (!File.Exists(str))
            {
                return(false);
            }
            this.HotKeys.Clear();
            if (profileName == "~Default")
            {
                this.DefaultHotKeys.Clear();
            }
            this._profileName = profileName;
            XPathNavigator navigator = new XPathDocument(App.GetStreamForFile(str) != null ? App.GetStreamForFile(str) : (Stream) new FileStream(str, FileMode.Open)).CreateNavigator();

            navigator.MoveToFirstChild();
            do
            {
                if (navigator.HasChildren)
                {
                    navigator.MoveToFirstChild();
                    do
                    {
                        if (navigator.HasChildren)
                        {
                            HotKeyManager.KeyCombo      keyCombo = new HotKeyManager.KeyCombo();
                            HotKeyManager.HotKeyActions key      = HotKeyManager.HotKeyActions.NoAction;
                            navigator.MoveToFirstChild();
                            do
                            {
                                switch (navigator.Name)
                                {
                                case "event":
                                    if (Enum.IsDefined(typeof(HotKeyManager.HotKeyActions), (object)navigator.Value))
                                    {
                                        key = (HotKeyManager.HotKeyActions)Enum.Parse(typeof(HotKeyManager.HotKeyActions), navigator.Value, true);
                                        break;
                                    }
                                    break;

                                case "states":
                                    keyCombo.states = navigator.Value;
                                    break;

                                case "shift":
                                    keyCombo.shift = bool.Parse(navigator.Value);
                                    break;

                                case "ctrl":
                                    keyCombo.control = bool.Parse(navigator.Value);
                                    break;

                                case "alt":
                                    keyCombo.alt = bool.Parse(navigator.Value);
                                    break;

                                case "key":
                                    keyCombo.key = !Enum.IsDefined(typeof(Keys), (object)navigator.Value) ? Keys.None : (Keys)Enum.Parse(typeof(Keys), navigator.Value, true);
                                    break;
                                }
                            }while (navigator.MoveToNext());
                            if (key != HotKeyManager.HotKeyActions.NoAction && !this.HotKeys.ContainsKey(key))
                            {
                                this.HotKeys.Add(key, keyCombo);
                                if (profileName == "~Default")
                                {
                                    this.DefaultHotKeys.Add(key, keyCombo);
                                }
                            }
                            navigator.MoveToParent();
                        }
                    }while (navigator.MoveToNext());
                }
            }while (navigator.MoveToNext());
            this._loaded = true;
            foreach (HotKeyManager.HotKeyActions action in Enum.GetValues(typeof(HotKeyManager.HotKeyActions)))
            {
                if (!this.HotKeys.Keys.Contains <HotKeyManager.HotKeyActions>(action) && this.DefaultHotKeys.Keys.Contains <HotKeyManager.HotKeyActions>(action))
                {
                    this.SetHotKeyCombo(action, this.DefaultHotKeys[action]);
                }
            }
            this.SyncKeyProfile("");
            this.SaveProfile();
            return(true);
        }