예제 #1
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);
                }
            }
        }
예제 #2
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);
			}
		}