Ejemplo n.º 1
0
        /// <summary>
        /// Try to register the provided list.
        /// </summary>
        /// <param name="listName">Name of the list to register.</param>
        /// <param name="listItems">Items of the list to register.</param>
        /// <param name="listLevel">The definitionlevel of the list to register.</param>
        /// <param name="ListCreator">Function used to create a new list from listName and listItems. Can be null: in this case the standard list creator will be used.</param>
        /// <param name="storedList">On return, this is the list which is either registered, or is an already registed list with exactly the same elements.</param>
        /// <returns>True if the list was new and thus was added to the collection; false if the list has already existed.</returns>
        public bool TryRegisterList(string listName, IEnumerable <TItem> listItems, Main.ItemDefinitionLevel listLevel, Func <string, IEnumerable <TItem>, TList> ListCreator, out TList storedList)
        {
            if (string.IsNullOrEmpty(listName))
            {
                throw new ArgumentNullException(nameof(listName));
            }

            if (TryGetListByMembers(listItems, listName, out var nameOfExistingGroup)) // if a group with such a list already exist
            {
                storedList = _allLists[nameOfExistingGroup].List;
                return(false);
            }
            else // a group with such members don't exist currently
            {
                if (_allLists.ContainsKey(listName)) // but name is already in use
                {
                    listName = GetUnusedName(listName);
                }

                storedList = (ListCreator ?? CreateNewList)(listName, listItems);
                _allLists.Add(storedList.Name, EntryValueCreator(storedList, listLevel));
                OnListAdded(storedList, listLevel);
                return(true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Try to register the provided list.
        /// </summary>
        /// <param name="instance">The new list which is tried to register.</param>
        /// <param name="level">The level on which this list is defined.</param>
        /// <param name="storedList">On return, this is the list which is either registered, or is an already registed list with exactly the same elements.</param>
        /// <returns>True if the list was new and thus was added to the collection; false if the list has already existed.</returns>
        public bool TryRegisterList(TList instance, Main.ItemDefinitionLevel level, out TList storedList)
        {
            if (null == instance)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            return(InternalTryRegisterList(instance, level, out storedList, true));
        }
Ejemplo n.º 3
0
        protected virtual void OnListChanged(TList list, Main.ItemDefinitionLevel level)
        {
            if (level == ItemDefinitionLevel.UserDefined)
            {
                OnUserDefinedListAddedChangedRemoved(list);
            }

            _changed.Target?.Invoke();
        }
Ejemplo n.º 4
0
        public StyleListManagerBaseEntryValue(TList list, Main.ItemDefinitionLevel level)
        {
            if (null == list)
            {
                throw new ArgumentNullException(nameof(list));
            }

            List = list;

            Level = level;
        }
Ejemplo n.º 5
0
        private static string GetLevelString(Main.ItemDefinitionLevel level)
        {
            switch (level)
            {
            case Main.ItemDefinitionLevel.Builtin:
                return("Builtin");

            case Main.ItemDefinitionLevel.Application:
                return("App");

            case Main.ItemDefinitionLevel.UserDefined:
                return("User");

            case Main.ItemDefinitionLevel.Project:
                return("Project");

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Try to register the provided list.
 /// </summary>
 /// <param name="instance">The new list which is tried to register.</param>
 /// <param name="level">The level on which this list is defined.</param>
 /// <param name="storedList">On return, this is the list which is either registered, or is an already registed list with exactly the same elements.</param>
 /// <param name="fireAddEvent">If true, the add event is fired when a list is added.</param>
 /// <returns>True if the list was new and thus was added to the collection; false if the list has already existed.</returns>
 protected bool InternalTryRegisterList(TList instance, Main.ItemDefinitionLevel level, out TList storedList, bool fireAddEvent)
 {
     if (TryGetListByMembers(instance, instance.Name, out var nameOfExistingGroup)) // if a group with such a list already exist
     {
         if (nameOfExistingGroup != instance.Name)                                  // if it has the same list, but a different name, do nothing at all
         {
             storedList = _allLists[nameOfExistingGroup].List;
             return(false);
         }
         else // if it has the same list, and the same name, even better, nothing is left to be done
         {
             storedList = _allLists[nameOfExistingGroup].List;
             return(false);
         }
     }
     else // a group with such members don't exist currently
     {
         if (_allLists.ContainsKey(instance.Name)) // but name is already in use
         {
             storedList = (TList)instance.WithName(GetUnusedName(instance.Name));
             _allLists.Add(storedList.Name, EntryValueCreator(storedList, level));
             if (fireAddEvent)
             {
                 OnListAdded(storedList, level);
             }
             return(true);
         }
         else // name is not in use
         {
             storedList = instance;
             _allLists.Add(instance.Name, EntryValueCreator(instance, level));
             if (fireAddEvent)
             {
                 OnListAdded(instance, level);
             }
             return(true);
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Try to register the provided list. This function is intended to be used during deserialization. It keeps track of when a list was renamed, and stores
        /// this information in the deserialization info to be used by the members of the list during deserialization.
        /// </summary>
        /// <param name="deserializationInfo">The deserialization info of the deserialization that is under way. Can be null.</param>
        /// <param name="instance">The new list which is tried to register.</param>
        /// <param name="level">The level on which this list is defined.</param>
        /// <param name="storedList">On return, this is the list which is either registered, or is an already registed list with exactly the same elements.</param>
        /// <returns>True if the list was new and thus was added to the collection; false if the list has already existed.</returns>
        public bool TryRegisterList(Altaxo.Serialization.Xml.IXmlDeserializationInfo deserializationInfo, TList instance, Main.ItemDefinitionLevel level, out TList storedList)
        {
            var result = InternalTryRegisterList(instance, level, out storedList, true);

            var renameDictionary = deserializationInfo?.GetPropertyOrDefault <Dictionary <string, string> >(DeserializationRenameDictionaryKey);

            if (null != renameDictionary)
            {
                renameDictionary[instance.Name] = storedList.Name;
            }

            return(result);
        }
Ejemplo n.º 8
0
 public ColorSetManagerEntryValue(IColorSet colorSet, Main.ItemDefinitionLevel level, bool isPlotColorSet)
     : base(colorSet, level)
 {
     IsPlotColorSet = isPlotColorSet;
 }