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); } } }
public virtual object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent) { ProjectItemClipboardList s = null != o ? (ProjectItemClipboardList)o : new ProjectItemClipboardList(); s.BaseFolder = info.GetString("BaseFolder"); s.RelocateReferences = info.GetNullableBoolean("RelocateReferences"); s.TryToKeepInternalReferences = info.GetNullableBoolean("TryToKeepInternalReferences"); int count = info.OpenArray("Items"); s._projectItems = new List <IProjectItem>(); for (int i = 0; i < count; ++i) { s._projectItems.Add((IProjectItem)info.GetValue("e", s)); } info.CloseArray(count); return(s); }
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); } }