Example #1
0
        /// <summary>
        /// Adds the provided project item to the Altaxo project, for instance a table or a graph, to the project. If another project item with the same name already exists,
        /// a new unique name for the item is found, based on the given name.
        /// For <see cref="T:Altaxo.Main.Properties.ProjectFolderPropertyDocument"/>s, if a document with the same name is already present, the properties are merged.
        /// </summary>
        /// <param name="item">The item to add.</param>
        /// <exception cref="System.ArgumentNullException">item</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">The type of item is not yet considered here.</exception>
        public void AddItemWithThisOrModifiedName(IProjectItem item)
        {
            if (null == item)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (item is Altaxo.Main.Properties.ProjectFolderPropertyDocument propertyDoc)
            {
                if (!ProjectFolderProperties.ContainsAnyName(propertyDoc.Name))
                {
                    ProjectFolderProperties.Add(propertyDoc); // if not existing, then add the new property document
                }
                else
                {
                    ProjectFolderProperties[propertyDoc.Name].PropertyBagNotNull.MergePropertiesFrom(propertyDoc.PropertyBag, true); // if existing, then merge the properties into the existing bag
                }
            }
            else // normal case
            {
                var coll = GetCollectionForProjectItemType(item.GetType());

                if (item.Name == null || item.Name == string.Empty)
                {
                    item.Name = coll.FindNewItemName();
                }
                else if (coll.ContainsAnyName(item.Name))
                {
                    item.Name = coll.FindNewItemName(item.Name);
                }

                coll.Add(item);
            }
        }
Example #2
0
        /// <summary>
        /// Adds the provided project item to the Altaxo project, for instance a table or a graph, to the project. For <see cref="T:Altaxo.Main.Properties.ProjectFolderPropertyDocument"/>s,
        /// if a document with the same name is already present, the properties are merged.
        /// </summary>
        /// <param name="item">The item to add.</param>
        /// <exception cref="System.ArgumentNullException">item</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">The type of item is not yet considered here.</exception>
        public void AddItem(IProjectItem item)
        {
            if (null == item)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (item is Altaxo.Main.Properties.ProjectFolderPropertyDocument propDoc)
            {
                if (!ProjectFolderProperties.Contains(propDoc.Name))
                {
                    ProjectFolderProperties.Add(propDoc); // if not existing, then add the new property document
                }
                else
                {
                    ProjectFolderProperties[propDoc.Name].PropertyBagNotNull.MergePropertiesFrom(propDoc.PropertyBag, true); // if existing, then merge the properties into the existing bag
                }
            }
            else
            {
                var coll = GetCollectionForProjectItemType(item.GetType());
                coll.Add(item);
            }
        }