Esempio n. 1
0
        /// <summary>
        /// Copyies one item to another folder by cloning the item.
        /// </summary>
        /// <param name="item">Item to copy. Has to be either a <see cref="ProjectFolder"/>, or a project item (<see cref="IProjectItem"/>).</param>
        /// <param name="destinationFolderName">Destination folder name.</param>
        /// <param name="ReportProxies">If not null, this argument is used to relocate references to other items (e.g. columns) to point to the destination folder.</param>
        /// <param name="overwriteExistingItemsOfSameType">If true, any item with the same name and same type will be replaced by the copied item. (if false, a new name is found for the copied item which not conflicts with the existing items).</param>
        public void CopyItemToFolder(object item, string destinationFolderName, DocNodeProxyReporter ReportProxies, bool overwriteExistingItemsOfSameType)
        {
            ProjectFolder.ThrowExceptionOnInvalidFullFolderPath(destinationFolderName);

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (item is ProjectFolder projFolder)
            {
                var    orgName  = projFolder.Name;
                string destName = ProjectFolder.Combine(destinationFolderName, ProjectFolder.GetFoldersLastFolderPart(orgName));
                foreach (var subitem in GetItemsInFolderAndSubfolders(orgName))
                {
                    var oldItemFolder = ProjectFolder.GetFolderPart(subitem.Name);
                    var newItemFolder = oldItemFolder.Replace(orgName, destName);
                    CopyItemToFolder(subitem, newItemFolder, ReportProxies, overwriteExistingItemsOfSameType);
                }
            }
            else if (item is IProjectItem projectItem)
            {
                var orgName    = projectItem.Name;
                var clonedItem = (IProjectItem)projectItem.Clone();
                clonedItem.Name = ProjectFolder.Combine(destinationFolderName, ProjectFolder.GetNamePart(orgName));

                if (overwriteExistingItemsOfSameType)
                {
                    var existingItem = AltaxoDocument.TryGetExistingItemWithSameTypeAndName(clonedItem);
                    if (null != existingItem)
                    {
                        Current.ProjectService.DeleteDocument(existingItem, true);
                    }
                }

                AltaxoDocument.AddItem(clonedItem);

                if (null != ReportProxies)
                {
                    clonedItem.VisitDocumentReferences(ReportProxies);
                }
            }
            else
            {
                throw new NotImplementedException(string.Format("The item of type {0} can not be copied", item.GetType()));
            }
        }
Esempio n. 2
0
        protected void CopyGraphToNewDocument(GraphDocumentBase oldGraph, bool ensureEmbeddedObjectRenderingOptionsStoredInGraph)
        {
            var newGraph = (GraphDocumentBase)oldGraph.Clone();

            newGraph.Name = oldGraph.Name;
            _document.AddItem(newGraph);

            if (ensureEmbeddedObjectRenderingOptionsStoredInGraph)
            {
                var clipboardRenderingOptions = Altaxo.PropertyExtensions.GetPropertyValue(oldGraph, ClipboardRenderingOptions.PropertyKeyClipboardRenderingOptions, () => new ClipboardRenderingOptions());
                var embeddedRenderingOptions  = Altaxo.PropertyExtensions.GetPropertyValue(oldGraph, EmbeddedObjectRenderingOptions.PropertyKeyEmbeddedObjectRenderingOptions, () => null);

                // if embeddedRenderingOptions exists explicitely, they should be used. Else the clipboard options can be used.
                var clonedOptions = null != embeddedRenderingOptions?embeddedRenderingOptions.Clone() : new EmbeddedObjectRenderingOptions(clipboardRenderingOptions);

                newGraph.PropertyBagNotNull.SetValue(EmbeddedObjectRenderingOptions.PropertyKeyEmbeddedObjectRenderingOptions, clonedOptions);
            }
        }