Exemplo n.º 1
0
        /// <summary>
        ///     Switches the group of a specified index
        /// </summary>
        /// <param name="key">The Input-Key to the key you want moved</param>
        /// <param name="targetGroup">The Index of the Group you want the key moved to</param>
        public void SwitchGroup(Key key, int targetGroup)
        {
            lock (ThreadLock)
            {
                if (key.Group >= Groups.Count || key.Member >= Groups[key.Group].Members.Count || targetGroup >= Groups.Count)
                {
                    return;
                }

                //Grab the Input we want moved
                OpenTextInput input = Groups[key.Group].Members[key.Member];


                //Update the Index of the Input
                input.Index = Groups[targetGroup].Members.Count;

                //Add it to the desired group
                Groups[targetGroup].Members.Add(input);

                {
                    //Check if this is in favorites
                    string str = $"{key.Group}-{key.Member}";
                    if (FavoriteMembers.Contains(str))
                    {
                        FavoriteMembers.Remove(str);
                        str = $"{targetGroup}-{input.Index}";
                        FavoriteMembers.Add(str);
                    }
                }
                //Remove it from its old location
                Groups[key.Group].Members.RemoveAt(key.Member);


                //Remove the Group if it is empty
                if (key.Group != 0 && Groups[key.Group].Members.Count < 1)
                {
                    {
                        //Check if this is in favorites
                        if (FavoriteGroups.Contains(key.Group))
                        {
                            FavoriteGroups.Remove(key.Group);
                        }
                    }
                    Groups.RemoveAt(key.Group);
                    UpdateGroupIndexes();
                }
                else //Otherwise update the Member Indexes
                {
                    UpdateMemberIndexes(key.Group);
                }
            }

            EventStream();
        }
Exemplo n.º 2
0
        public void SetGroupFavorite(int group)
        {
            lock (ThreadLock)
            {
                if (Groups.Count <= group || group < 0)
                {
                    return;
                }

                //TODO: OLD_FAVORITE_GROUPS
                //if (FavoriteGroups.Contains(group))
                //    FavoriteGroups.Remove(group);
                //else
                //    FavoriteGroups.Add(group);
                bool checkAction = false;
                for (int i = 0; i < Groups[group].Members.Count; i++)
                {
                    Key key = new Key
                    {
                        Group  = group,
                        Member = i
                    };

                    //Skip if already contained
                    string str = key.Group + "-" + key.Member;
                    if (FavoriteMembers.Contains(str))
                    {
                        continue;
                    }


                    checkAction = true;
                    SetMemberFavorite(key);
                }

                //If all members are already favorites, un-favorite them all instead
                if (!checkAction)
                {
                    for (int i = 0; i < Groups[@group].Members.Count; i++)
                    {
                        Key key = new Key
                        {
                            Group  = @group,
                            Member = i
                        };
                        SetMemberFavorite(key);
                    }
                }
            }

            EventStream();
        }
Exemplo n.º 3
0
        private void ArchiveInput(Key member)
        {
            //Grab the Input we want moved
            OpenTextInput input = Groups[member.Group].Members[member.Member];

            {
                //Check if this is in favorites
                string str = $"{member.Group}-{member.Member}";
                if (FavoriteMembers.Contains(str))
                {
                    FavoriteMembers.Remove(str);
                }
            }
            //Remove it from its old location
            Groups[member.Group].Members.RemoveAt(member.Member);
            input.Index = Archive.Count;
            Archive.Add(input);
        }
Exemplo n.º 4
0
        public void SetMemberFavorite(Key input)
        {
            lock (ThreadLock)
            {
                if (Groups.Count <= input.Group || input.Group < 0)
                {
                    return;
                }

                string str = input.Group + "-" + input.Member;
                if (FavoriteMembers.Contains(str))
                {
                    FavoriteMembers.Remove(str);
                }
                else
                {
                    FavoriteMembers.Add(str);
                }
            }

            EventStream();
        }
Exemplo n.º 5
0
        public void SwitchGroup(IEnumerable <Key> keys, int target)
        {
            if (target >= Groups.Count)
            {
                return;
            }

            foreach (Key key in keys)
            {
                if (key.Group == target || key.Group >= Groups.Count || key.Member >= Groups[key.Group].Members.Count)
                {
                    continue;
                }

                //Grab the Input we want moved
                OpenTextInput input = Groups[key.Group].Members[key.Member];

                //Update the Index of the Input
                input.Index = Groups[target].Members.Count;

                lock (ThreadLock)
                {
                    {
                        //Check if this is in favorites
                        string str = $"{key.Group}-{key.Member}";
                        if (FavoriteMembers.Contains(str))
                        {
                            FavoriteMembers.Remove(str);
                            str = $"{target}-{input.Index}";
                            FavoriteMembers.Add(str);
                        }
                    }
                    //Remove it from its old location
                    Groups[key.Group].Members.RemoveAt(key.Member);

                    //Add it to the desired group
                    Groups[target].Members.Add(input);
                }
            }

            for (int i = 1; i < Groups.Count; i++)
            {
                if (Groups[i].Members.Count < 1) //TODO: Keep Previously Empty Groups?
                {
                    int prev = Groups[i].Column;
                    {
                        //Check if this is in favorites
                        if (FavoriteGroups.Contains(i))
                        {
                            FavoriteGroups.Remove(i);
                        }
                    }
                    Groups.RemoveAt(i);
                    if (Groups.All(check => check.Column != prev))
                    {
                        RemoveColumn(prev);
                    }

                    i--;
                }
            }

            UpdateGroupIndexes();

            foreach (OpenTextGroup group in Groups)
            {
                lock (ThreadLock)
                {
                    UpdateMemberIndexes(group.Index);
                }
            }

            EventStream();
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Merges two inputs into one another
        /// </summary>
        /// <param name="parent">This is the key that will still be visible</param>
        /// <param name="child">This key will be hidden inside parent</param>
        public void Merge(Key parent, Key child)
        {
            lock (ThreadLock)
            {
                if (parent.Group >= Groups.Count || parent.Member >= Groups[parent.Group].Members.Count || child.Group >= Groups.Count || child.Member >= Groups[child.Group].Members.Count)
                {
                    return;
                }

                //Check if parent is already merged with something
                if (Groups[parent.Group].Members[parent.Member] is OpenTextMerged mergedParent)
                {
                    //Check if child is merged with something
                    if (Groups[child.Group].Members[child.Member] is OpenTextMerged mergedChild)
                    {
                        //Separate the child from all the grand-kids(The child's children)
                        OpenTextInput singleChild = new OpenTextInput
                        {
                            Description = mergedChild.Description,
                            Title       = mergedChild.Title,
                            UserID      = mergedChild.UserID
                        };

                        //Gather the grand-kids
                        List <OpenTextInput> grandKids = mergedChild.Children;

                        //Add child and all grand-kids to parent
                        mergedParent.Children.Add(singleChild);

                        foreach (OpenTextInput kid in grandKids)
                        {
                            mergedParent.Children.Add(kid);
                        }
                    }
                    else
                    {
                        //Add the Child to parent
                        mergedParent.Children.Add(Groups[child.Group].Members[child.Member]);
                    }

                    //Check if this is in favorites
                    string str = $"{child.Group}-{child.Member}";
                    if (FavoriteMembers.Contains(str))
                    {
                        FavoriteMembers.Remove(str);
                        str = $"{parent.Group}-{parent.Member}";
                        FavoriteMembers.Add(str);
                    }

                    //Remove the child from its old location
                    Groups[child.Group].Members.RemoveAt(child.Member);
                    UpdateMemberIndexes(child.Group);
                }
                else
                {
                    //Make parent into a merged Input
                    OpenTextMerged merge = new OpenTextMerged
                    {
                        Children    = new List <OpenTextInput>(),
                        Description = Groups[parent.Group].Members[parent.Member].Description,
                        Title       = Groups[parent.Group].Members[parent.Member].Title,
                        UserID      = "Multiple Users",
                        Index       = Groups[parent.Group].Members[parent.Member].Index
                    };

                    //Add Parent as the first child
                    merge.Children.Add(Groups[parent.Group].Members[parent.Member]);

                    //Check if child is merged with something
                    if (Groups[child.Group].Members[child.Member] is OpenTextMerged mergedChild)
                    {
                        //Separate the child from all the grand-kids(The child's children)
                        OpenTextInput singleChild = new OpenTextInput
                        {
                            Description = mergedChild.Description,
                            Title       = mergedChild.Title,
                            UserID      = mergedChild.UserID
                        };

                        //Gather the grand-kids
                        List <OpenTextInput> grandKids = mergedChild.Children;

                        //Add child and all grand-kids to parent
                        merge.Children.Add(singleChild);

                        foreach (OpenTextInput kid in grandKids)
                        {
                            merge.Children.Add(kid);
                        }
                    }
                    else
                    {
                        //Add child to new parent
                        merge.Children.Add(Groups[child.Group].Members[child.Member]);
                    }

                    //Check if this is in favorites
                    string str = $"{child.Group}-{child.Member}";
                    if (FavoriteMembers.Contains(str))
                    {
                        FavoriteMembers.Remove(str);
                        str = $"{parent.Group}-{parent.Member}";
                        FavoriteMembers.Add(str);
                    }

                    Groups[child.Group].Members.RemoveAt(child.Member);
                    Groups[parent.Group].Members[parent.Member] = merge;
                    UpdateMemberIndexes(child.Group);
                }
            }

            EventStream();
        }