예제 #1
0
        /// <summary>
        /// Moves the selected list items to a folder that is asked for by a dialog.
        /// </summary>
        /// <param name="ctrl">Project browse controller.</param>
        public static void CopySelectedListItemsToMultipleFolders(this ProjectBrowseController ctrl)
        {
            var list = ctrl.GetSelectedListItems();

            bool areDocumentsFromOneFolder = ctrl.IsProjectFolderSelected(out var originalFolderName);

            var dlgDoc = new Altaxo.Gui.ProjectBrowser.CopyItemsToMultipleFolderData
            {
                RelocateReferences = true
            };

            if (!Current.Gui.ShowDialog(ref dlgDoc, "Select folders to copy to", false))
            {
                return;
            }

            foreach (var newFolderName in dlgDoc.FoldersToCopyTo)
            {
                DocNodePathReplacementOptions relocateOptions = null;
                if (true == dlgDoc.RelocateReferences)
                {
                    relocateOptions = new DocNodePathReplacementOptions();
                    relocateOptions.AddPathReplacementsForAllProjectItemTypes(originalFolderName, newFolderName);
                }
                Current.Project.Folders.CopyItemsToFolder(list, newFolderName, null != relocateOptions ? relocateOptions.Visit : (DocNodeProxyReporter)null, dlgDoc.OverwriteExistingItems);
            }
        }
예제 #2
0
        /// <summary>
        /// Copy the items given in the list (tables and graphs) to a folder, which is selected by the user via a dialog box.
        /// </summary>
        /// <param name="list">List of items to delete.</param>
        /// <param name="areDocumentsFromOneFolder">If true, the list contains objects origination from only one project folder (or from subfolders of that folder). In this case the paramenter <c>originalSourceFolder</c> contains the original project folder from which the items should be copied.</param>
        /// <param name="originalSourceFolder">Original folder from which the items originate (only valid if <c>areDocumentsFromOneFolder</c> is true.</param>
        public static void CopyDocuments(IList <object> list, bool areDocumentsFromOneFolder, string originalSourceFolder)
        {
            var names = Current.Project.Folders.GetSubfoldersAsDisplayFolderNameStringListSorted(ProjectFolder.RootFolderName, true);

            names.Insert(0, rootFolderDisplayName);
            var choices = new TextChoice(names.ToArray(), 0, true)
            {
                Description = "Choose or enter the folder to copy the items into:"
            };

            if (!Current.Gui.ShowDialog(ref choices, "Folder choice", false))
            {
                return;
            }
            string newFolderName = rootFolderDisplayName == choices.Text ? ProjectFolder.RootFolderName : ProjectFolder.ConvertDisplayFolderNameToFolderName(choices.Text);

            DocNodePathReplacementOptions relocateOptions = null;

            if (areDocumentsFromOneFolder)
            {
                var relocateData = Current.Gui.YesNoCancelMessageBox("Do you want to relocate the references in the copied plots so that they point to the destination folder?", "Question", null);
                if (null == relocateData)
                {
                    return;
                }

                if (true == relocateData)
                {
                    relocateOptions = new DocNodePathReplacementOptions();
                    relocateOptions.AddPathReplacementsForAllProjectItemTypes(originalSourceFolder, newFolderName);
                }
            }

            Current.Project.Folders.CopyItemsToFolder(list, newFolderName, null != relocateOptions ? relocateOptions.Visit : (DocNodeProxyReporter)null, false);
        }
예제 #3
0
        public static void PasteItems(string targetFolder, ProjectItemClipboardList list)
        {
            // first we have to make sure that list has values set for TryToKeepInternalReferences and RelocateReferences -- otherwise we have to show a dialog
            if (list.TryToKeepInternalReferences == null || list.RelocateReferences == null)
            {
                var options = new ProjectItemsPasteOptions {
                    TryToKeepInternalReferences = list.TryToKeepInternalReferences, RelocateReferences = list.RelocateReferences
                };

                if (!Current.Gui.ShowDialog(ref options, "Paste options", false))
                {
                    return;
                }

                list.TryToKeepInternalReferences = options.TryToKeepInternalReferences;
                list.RelocateReferences          = options.RelocateReferences;
            }

            if (!(list.TryToKeepInternalReferences.HasValue))
            {
                throw new InvalidProgramException();
            }
            if (!(list.RelocateReferences.HasValue))
            {
                throw new InvalidProgramException();
            }

            var relocationData = new DocNodePathReplacementOptions();

            foreach (IProjectItem item in list.ProjectItems)
            {
                var oldName = item.Name;
                var newName = GetRelocatedName(oldName, list.BaseFolder, targetFolder);
                var oldPath = Current.Project.GetDocumentPathForProjectItem(item);

                item.Name = newName;
                Current.Project.AddItem(item);
                if (list.TryToKeepInternalReferences.Value)
                {
                    var newPath = Current.Project.GetDocumentPathForProjectItem(item);
                    relocationData.AddProjectItemReplacement(oldPath, newPath); // when trying to keep the references, we use the name the table gets after added to the collection (it can have changed during this operation).
                }
            }

            if (list.RelocateReferences.Value && targetFolder != null)
            {
                string sourceFolder = list.BaseFolder ?? ProjectFolder.RootFolderName;
                relocationData.AddPathReplacementsForAllProjectItemTypes(sourceFolder, targetFolder);
            }

            if (list.TryToKeepInternalReferences.Value || list.RelocateReferences.Value)
            {
                foreach (IProjectItem item in list.ProjectItems)
                {
                    item.VisitDocumentReferences(relocationData.Visit);
                }
            }
        }
예제 #4
0
		public static void PasteItems(string targetFolder, ProjectItemClipboardList list)
		{
			// first we have to make sure that list has values set for TryToKeepInternalReferences and RelocateReferences -- otherwise we have to show a dialog
			if (list.TryToKeepInternalReferences == null || list.RelocateReferences == null)
			{
				ProjectItemsPasteOptions options = new ProjectItemsPasteOptions { TryToKeepInternalReferences = list.TryToKeepInternalReferences, RelocateReferences = list.RelocateReferences };

				if (!Current.Gui.ShowDialog(ref options, "Paste options", false))
					return;

				list.TryToKeepInternalReferences = options.TryToKeepInternalReferences;
				list.RelocateReferences = options.RelocateReferences;
			}

			if (!(list.TryToKeepInternalReferences.HasValue)) throw new InvalidProgramException();
			if (!(list.RelocateReferences.HasValue)) throw new InvalidProgramException();

			var relocationData = new DocNodePathReplacementOptions();

			foreach (IProjectItem item in list.ProjectItems)
			{
				var oldName = item.Name;
				var newName = GetRelocatedName(oldName, list.BaseFolder, targetFolder);
				var oldPath = AltaxoDocument.GetDocumentPathForProjectItem(item);

				item.Name = newName;
				Current.Project.AddItem(item);
				if (list.TryToKeepInternalReferences.Value)
				{
					var newPath = AltaxoDocument.GetDocumentPathForProjectItem(item);
					relocationData.AddProjectItemReplacement(oldPath, newPath); // when trying to keep the references, we use the name the table gets after added to the collection (it can have changed during this operation).
				}
			}

			if (list.RelocateReferences.Value && targetFolder != null)
			{
				string sourceFolder = list.BaseFolder ?? ProjectFolder.RootFolderName;
				relocationData.AddPathReplacementsForAllProjectItemTypes(sourceFolder, targetFolder);
			}

			if (list.TryToKeepInternalReferences.Value || list.RelocateReferences.Value)
			{
				foreach (IProjectItem item in list.ProjectItems)
					item.VisitDocumentReferences(relocationData.Visit);
			}
		}