예제 #1
0
        /// <summary>
        /// used to add/remove/update a specific <see cref="KBind"/>
        /// </summary>
        /// <param name="kBind"></param>
        /// <param name="add"></param>
        private bool UpdateKeyBindGroups(KBind kBind, KBindChange change)
        {
            bool changeHappened = false;

            kBind.Init();
            //if(kBind.keyCombinations != null && kBind.keyCombinations[0].modifiers != null)
            //	Log(kBind.keyCombinations[0].modifiers[0]);
            //Log(kBind);
            EnsureInitializedKeyBinding();
            if (change == KBindChange.Update)
            {
                changeHappened |= UpdateKeyBindGroups(kBind, KBindChange.Remove);
                change          = KBindChange.Add;
            }
            for (int k = 0; k < keyBindGroups.Length; ++k)
            {
                KBindGroup group = keyBindGroups[k];
                changeHappened |= group.UpdateKeyBinding(kBind, change);
            }
            if (updateText && changeHappened)
            {
                UpdateCurrentKeyBindText();
            }
            return(changeHappened);
        }
예제 #2
0
        public bool AddKeyBind(KBind kBind)
        {
            int         index        = (!string.IsNullOrEmpty(kBind.name)) ? KeyBinds.FindIndex(kb => kb.name == kBind.name) : -1;
            KBindChange kindOfChange = KBindChange.Add;

            if (index >= 0)
            {
                kindOfChange = KBindChange.Update;                 // will cause lists to Remove then re-Add
                return(false);
            }
            else
            {
                KeyBinds.Add(kBind);
            }
            return(UpdateKeyBindGroups(kBind, kindOfChange));
        }
예제 #3
0
            /// <param name="kBind"></param>
            /// <param name="kind"></param>
            /// <returns></returns>
            public bool UpdateKeyBinding(KBind kBind, KBindChange kind)
            {
                if (kind == KBindChange.Add && !putInList(kBind))
                {
                    return(false);
                }
                bool changeHappened = false;
                int  index          = keyBindList.IndexOf(kBind);

                switch (kind)
                {
                case KBindChange.Add:
                    if (index >= 0)
                    {
                        Log("already added " + name + " " + kBind.name + "?");
                    }
                    if (index < 0)
                    {
                        keyBindList.Add(kBind);
                        keyBindList.Sort();
                        changeHappened = true;
                        //Log($"added {name} {kBind.name}");
                    }
                    else
                    {
                        if (index >= 0)
                        {
                            Log("will not add duplicate " + name + " " + kBind.name);
                        }
                    }
                    break;

                case KBindChange.Remove:
                    if (index >= 0)
                    {
                        keyBindList.RemoveAt(index); changeHappened = true;
                    }
                    break;

                case KBindChange.Update:
                    throw new Exception("Update is composed of a Remove and Add, should never be called directly like this.");
                }
                return(changeHappened);
            }
예제 #4
0
            /// <param name="kBind"></param>
            /// <param name="kind"></param>
            /// <returns></returns>
            public bool UpdateKeyBinding(KBind kBind, KBindChange kind)
            {
                if (kind == KBindChange.Add && putInList != null && !putInList.Invoke(kBind))
                {
                    return(false);
                }
                bool changeHappened = false;
                int  index          = allKeyBindings.IndexOf(kBind);       // TODO get index from sorted list with IList extension?

                switch (kind)
                {
                case KBindChange.Add:
                    if (index >= 0)
                    {
                        Show.Log("already added " + name + " " + kBind.name + "?");
                    }
                    if (index < 0)
                    {
                        allKeyBindings.Add(kBind); allKeyBindings.Sort();                         // TODO insert sorted in IList extension?
                        for (int i = 0; i < kBind.keyCombinations.Length; ++i)
                        {
                            KCombo kCombo = kBind.keyCombinations[i];
                            if (!bindingsByKey.TryGetValue(kCombo.key, out List <KBindTrigger> kBinds))
                            {
                                kBinds = new List <KBindTrigger>();
                                bindingsByKey[kCombo.key] = kBinds;
                            }
                            kBinds.Add(new KBindTrigger {
                                kCombo = kCombo, kBind = kBind
                            }); kBinds.Sort();                                                                                          // TODO insert sorted in IList extension?
                        }
                        changeHappened = true;
                        //Log($"added {name} {kBind.name}");
                    }
                    else
                    {
                        if (index >= 0)
                        {
                            Show.Log("will not add duplicate " + name + " " + kBind.name);
                        }
                    }
                    break;

                case KBindChange.Remove:
                    if (index >= 0)
                    {
                        allKeyBindings.RemoveAt(index); changeHappened = true;
                        for (int i = 0; i < kBind.keyCombinations.Length; ++i)
                        {
                            KCombo kCombo = kBind.keyCombinations[i];
                            if (bindingsByKey.TryGetValue(kCombo.key, out List <KBindTrigger> kBinds))
                            {
                                int subIndex = kBinds.FindIndex(k => k.kBind == kBind);                                 // TODO get index from sorted list with IList extension?
                                kBinds.RemoveAt(subIndex);
                            }
                        }
                    }
                    break;

                case KBindChange.Update:
                    throw new Exception("Update is composed of a Remove and Add, should never be called directly like this.");
                }
                return(changeHappened);
            }
예제 #5
0
 private static bool UpdateLists(KBind kBind, KBindChange change)
 {
     return(Instance.UpdateKeyBindGroups(kBind, change));
 }