Ejemplo n.º 1
0
        /// <summary>
        /// Creates a List of <see cref="SortedMapItem"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="SortedMapItem.SortOrder"/>
        /// </summary>
        /// <param name="SelectedValues">
        /// Instance of <see cref="SelectedOptions{T}"/>. Each value in SelectedValues will set the
        /// corresponding <see cref="SortedMapItem.Selected"/> to true;
        /// </param>
        /// <param name="ExcludeRules">
        /// If any rule matches the exclude then the matched item will not be
        /// outputted in the list.
        /// </param>
        /// <returns>
        /// List of <see cref="SortedMapItem"/>
        /// </returns>
        /// <remarks>
        /// <see cref="SortedMapItem.Parent"/> is set to the List.
        /// </remarks>
        public virtual List <SortedMapItem> ToList(SelectedOptions <T> SelectedValues, EnumRule <T> ExcludeRules)
        {
            List <SortedMapItem> SortList = new List <SortedMapItem>();

            if (this.Item == null)
            {
                return(SortList);
            }

            foreach (var map in this.Item)
            {
                SortedMapItem newMap = new SortedMapItem();
                if (ExcludeRules[map.Key])
                {
                    // exclude rule continue
                    continue;
                }
                newMap.Key       = map.Key;
                newMap.Value     = map.Value;
                newMap.SortOrder = map.SortOrder;
                if (SelectedValues.HasKey[map.Key])
                {
                    newMap.Selected = true;
                }
                newMap.Parent = SortList;
                SortList.Add(newMap);
            }
            // Sort the list based upon sort values for display.
            // This comes into play when the binding list is bound to a list control
            // such as a drop down list.
            SortList.Sort((value1, value2) => value1.SortOrder.CompareTo(value2.SortOrder));
            return(SortList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a new <see cref="SelectedOptions{T}"/> instance containing the selected values of <paramref name="ListItems"/>
        /// </summary>
        /// <param name="ListItems">The list containing one or more Selected Items to add to the list</param>
        /// <returns>
        /// A new Instance of <see cref="SelectedOptions{T}"/> with the values that were marked as Selected in the
        /// <paramref name="ListItems"/>
        /// </returns>
        public static SelectedOptions <T> FromList(IList <AhkKeyMapAhkMapValue> ListItems)
        {
            var opt = new SelectedOptions <T>();

            if (ListItems.Count == 0)
            {
                return(opt);
            }
            foreach (var item in ListItems)
            {
                if (item.Selected == true)
                {
                    if (opt.HasKey[item.Key] == false)
                    {
                        if (Enum.IsDefined(typeof(T), item.Key))
                        {
                            T en;
                            if (Enum.TryParse(item.Key, out en) == true)
                            {
                                opt.Options.Add(en);
                                opt.Keys.Add(item.Key);
                            }
                        }
                    }
                }
            }
            return(opt);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a List of <see cref="AhkKeyMapAhkMapValue"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="AhkKeyMapAhkMapValue.Sort"/>
        /// </summary>
        /// <param name="SelectedValues">
        /// Instance of <see cref="SelectedOptions{T}"/>. Each value in SelectedValues will set the
        /// corresponding <see cref="AhkKeyMapAhkMapValue.Selected"/> to true;
        /// </param>
        /// <param name="ExcludeRules">
        /// If any rule matches the exclude then the matched item will not be
        /// outputted in the list.
        /// </param>
        /// <returns>
        /// List of <see cref="AhkKeyMapAhkMapValue"/>
        /// </returns>
        /// <remarks>
        /// <see cref="AhkKeyMapAhkMapValue.Parent"/> is set to the List.
        /// </remarks>
        public virtual List <AhkKeyMapAhkMapValue> ToList(SelectedOptions <T> SelectedValues, EnumRule <T> ExcludeRules)
        {
            List <AhkKeyMapAhkMapValue> SortList = new List <AhkKeyMapAhkMapValue>();

            if (this.AhkMapValue == null)
            {
                return(SortList);
            }

            foreach (var map in this.AhkMapValue)
            {
                AhkKeyMapAhkMapValue newMap = new AhkKeyMapAhkMapValue();
                if (ExcludeRules[map.Key])
                {
                    // exclude rule continue
                    continue;
                }
                // newMap.Parent = bl;
                newMap.AutoHotKeyValue = map.AutoHotKeyValue;
                newMap.DisplayValue    = map.DisplayValue;
                newMap.Key             = map.Key;
                newMap.Sort            = map.Sort;
                if (SelectedValues.HasKey[map.Key])
                {
                    newMap.Selected = true;
                }
                newMap.Parent = SortList;
                SortList.Add(newMap);
            }
            // Sort the list based upon sort values for display.
            // This comes into play when the binding list is bound to a list control
            // such as a drop down list.
            SortList.Sort((value1, value2) => value1.Sort.CompareTo(value2.Sort));
            return(SortList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a Instance of <see cref="SelectedOptions{T}"/> From a String value
        /// </summary>
        /// <param name="s">The String to parse for values</param>
        /// <returns>
        /// Instance of <see cref="SelectedOptions{T}"/> if Parse succeeded; Otherwise, null.
        /// </returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static SelectedOptions <T> Parse(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                throw new ArgumentNullException();
            }
            try
            {
                // all chars except for `n and `t are single chars
                var opt = new SelectedOptions <T>();

                var es = s.Split(',');

                foreach (string strEs in es)
                {
                    if (string.IsNullOrWhiteSpace(strEs))
                    {
                        continue;
                    }
                    T      eValue = (T)Enum.Parse(typeof(T), strEs, false);
                    string sKey   = eValue.ToString();
                    if (opt.HasKey[sKey] == false)
                    {
                        opt.Options.Add(eValue);
                        opt.Keys.Add(sKey);
                    }
                }

                return(opt);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Attempts to Parse a string representing one or more Options.
        /// </summary>
        /// <param name="s">The Options to Parse</param>
        /// <param name="ec">The <see cref="SelectedOptions{T}"/> that represents the parsed results</param>
        /// <returns>
        /// Returns True if the parse was successful; Otherwise false
        /// </returns>
        public static bool TryParse(string s, out SelectedOptions <T> ec)
        {
            bool retval = false;
            SelectedOptions <T> outec = null;

            try
            {
                SelectedOptions <T> ecs = SelectedOptions <T> .Parse(s);

                outec  = ecs;
                retval = true;
            }
            catch (Exception)
            {
            }
            ec = outec;
            return(retval);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new instance of <see cref="SelectedOptions{T}"/> populated with the
        /// values in <paramref name="Options"/>
        /// </summary>
        /// <param name="Options">The Array of Enum Values use to populate the instance</param>
        /// <returns>
        /// Instance of <see cref="SelectedOptions{T}"/>. If <paramref name="Options"/> is null
        /// then return instance will have no values.
        /// </returns>
        public static SelectedOptions <T> FromArray(T[] Options)
        {
            SelectedOptions <T> opt = new SelectedOptions <T>();

            if (Options == null)
            {
                return(opt);
            }
            foreach (var e in Options)
            {
                string sKey = e.ToString();
                if (opt.HasKey[sKey] == false)
                {
                    opt.Options.Add(e);
                    opt.Keys.Add(sKey);
                }
            }
            return(opt);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a Binding List of <see cref="AhkKeyMapAhkMapValue"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="AhkKeyMapAhkMapValue.Sort"/>
        /// </summary>
        /// <param name="SelectedValues">
        /// Instance of <see cref="SelectedOptions{T}"/>. Each value in SelectedValues will set the
        /// corresponding <see cref="AhkKeyMapAhkMapValue.Selected"/> to true;
        /// </param>
        /// <returns>
        /// Binding list of <see cref="AhkKeyMapAhkMapValue"/>
        /// </returns>
        /// <remarks>
        /// <see cref="AhkKeyMapAhkMapValue.Parent"/> is set to the Binding List.
        /// </remarks>
        public virtual BindingList <AhkKeyMapAhkMapValue> ToBindingList(SelectedOptions <T> SelectedValues)
        {
            BindingList <AhkKeyMapAhkMapValue> bl = new BindingList <AhkKeyMapAhkMapValue>();

            if (this.AhkMapValue == null)
            {
                return(bl);
            }
            List <AhkKeyMapAhkMapValue> SortList = new List <AhkKeyMapAhkMapValue>();

            foreach (var map in this.AhkMapValue)
            {
                AhkKeyMapAhkMapValue newMap = new AhkKeyMapAhkMapValue();
                // newMap.Parent = bl;
                newMap.AutoHotKeyValue = map.AutoHotKeyValue;
                newMap.DisplayValue    = map.DisplayValue;
                newMap.Key             = map.Key;
                newMap.Sort            = map.Sort;
                if (SelectedValues.HasKey[map.Key])
                {
                    newMap.Selected = true;
                }
                SortList.Add(newMap);
            }
            // Sort the list based upon sort values for display.
            // This comes into play when the binding list is bound to a list control
            // such as a drop down list.
            SortList.Sort((value1, value2) => value1.Sort.CompareTo(value2.Sort));

            // Now that the list is sorted add the values to the binding list.
            foreach (var map in SortList)
            {
                map.Parent = bl;
                bl.Add(map);
            }
            SortList.Clear();
            return(bl);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a Binding List of <see cref="SortedMapItem"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="SortedMapItem.SortOrder"/>
        /// </summary>
        /// <param name="SelectedValues">
        /// Instance of <see cref="SelectedOptions{T}"/>. Each value in SelectedValues will set the
        /// corresponding <see cref="SortedMapItem.Selected"/> to true;
        /// </param>
        /// <returns>
        /// Binding list of <see cref="SortedMapItem"/>
        /// </returns>
        /// <remarks>
        /// <see cref="SortedMapItem.Parent"/> is set to the Binding List.
        /// </remarks>
        public virtual BindingList <SortedMapItem> ToBindingList(SelectedOptions <T> SelectedValues)
        {
            BindingList <SortedMapItem> bl = new BindingList <SortedMapItem>();

            if (this.Item == null)
            {
                return(bl);
            }
            List <SortedMapItem> SortList = new List <SortedMapItem>();

            foreach (var map in this.Item)
            {
                SortedMapItem newMap = new SortedMapItem();
                // newMap.Parent = bl;
                newMap.Key       = map.Key;
                newMap.Value     = map.Value;
                newMap.SortOrder = map.SortOrder;
                if (SelectedValues.HasKey[map.Key])
                {
                    newMap.Selected = true;
                }
                SortList.Add(newMap);
            }
            // Sort the list based upon sort values for display.
            // This comes into play when the binding list is bound to a list control
            // such as a drop down list.
            SortList.Sort((value1, value2) => value1.SortOrder.CompareTo(value2.SortOrder));

            // Now that the list is sorted add the values to the binding list.
            foreach (var map in SortList)
            {
                map.Parent = bl;
                bl.Add(map);
            }
            SortList.Clear();
            return(bl);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a List of <see cref="SortedMapItem"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="SortedMapItem.SortOrder"/>
        /// </summary>
        /// <returns>
        /// List of <see cref="SortedMapItem"/>
        /// </returns>
        /// <remarks>
        /// <see cref="SortedMapItem.Parent"/> is set to the List.
        /// </remarks>
        public virtual List <SortedMapItem> ToList()
        {
            SelectedOptions <T> ec = new SelectedOptions <T>();

            return(ToList(ec));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a Binding List of <see cref="SortedMapItem"/> objects representing all the Values
        /// in T enum. The List is Sorted Based upon <see cref="SortedMapItem.SortOrder"/>
        /// </summary>
        /// <returns>
        /// Binding list of <see cref="SortedMapItem"/>
        /// </returns>
        /// <remarks>
        /// <see cref="SortedMapItem.Parent"/> is set to the Binding List.
        /// </remarks>
        public virtual BindingList <SortedMapItem> ToBindingList()
        {
            SelectedOptions <T> opt = new SelectedOptions <T>();

            return(ToBindingList(opt));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a Binding List of <see cref="AhkKeyMapAhkMapValue"/> objects representing all the Values
        /// in T enum. The List is Sorted Based upon <see cref="AhkKeyMapAhkMapValue.Sort"/>
        /// </summary>
        /// <returns>
        /// Binding list of <see cref="AhkKeyMapAhkMapValue"/>
        /// </returns>
        /// <remarks>
        /// <see cref="AhkKeyMapAhkMapValue.Parent"/> is set to the Binding List.
        /// </remarks>
        public virtual BindingList <AhkKeyMapAhkMapValue> ToBindingList()
        {
            SelectedOptions <T> opt = new SelectedOptions <T>();

            return(ToBindingList(opt));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a List of <see cref="AhkKeyMapAhkMapValue"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="AhkKeyMapAhkMapValue.Sort"/>
        /// </summary>
        /// <returns>
        /// List of <see cref="AhkKeyMapAhkMapValue"/>
        /// </returns>
        /// <remarks>
        /// <see cref="AhkKeyMapAhkMapValue.Parent"/> is set to the List.
        /// </remarks>
        public virtual List <AhkKeyMapAhkMapValue> ToList()
        {
            SelectedOptions <T> ec = new SelectedOptions <T>();

            return(ToList(ec));
        }