/// <summary> /// Determines if a folder can be renamed. /// </summary> /// <param name="oldFolderName">Name of an existing folder.</param> /// <param name="newFolderName">New name of the folder.</param> /// <returns>True if the folder can be renamed, i.e. if none of the new item names conflicts with an existing item name.</returns> public bool CanRenameFolder(string oldFolderName, string newFolderName) { ProjectFolder.ThrowExceptionOnInvalidFullFolderPath(oldFolderName); ProjectFolder.ThrowExceptionOnInvalidFullFolderPath(newFolderName); var oldList = GetItemsInFolderAndSubfolders(oldFolderName); var itemHashSet = new HashSet <object>(oldList); int oldFolderNameLength = oldFolderName == null ? 0 : oldFolderName.Length; foreach (var item in oldList) { if (item is IProjectItem projItem) { string oldName = projItem.Name; string newName = (newFolderName ?? string.Empty) + oldName.Substring(oldFolderNameLength); var coll = AltaxoDocument.GetCollectionForProjectItemType(projItem.GetType()); if (coll.ContainsAnyName(newName) && !itemHashSet.Contains(coll[newName])) { return(false); } } else { throw new NotImplementedException("Unknown item type encountered: " + item.GetType().ToString()); } } return(true); }
public GraphDocumentDataObject(GraphDocumentBase graphDocument, ProjectFileComObject fileComObject, ComManager comManager) : base(comManager) { ComDebug.ReportInfo("{0} constructor.", GetType().Name); _dataAdviseHolder = new ManagedDataAdviseHolder(); _graphDocumentName = graphDocument.Name; _graphDocumentSize = graphDocument.Size; _graphExportOptions = graphDocument.GetPropertyValue(ClipboardRenderingOptions.PropertyKeyClipboardRenderingOptions, () => new ClipboardRenderingOptions()).Clone(); var embeddedRenderingOptions = graphDocument.GetPropertyValue(EmbeddedObjectRenderingOptions.PropertyKeyEmbeddedObjectRenderingOptions, () => null); if (null != embeddedRenderingOptions) { _graphExportOptions.CopyFrom(embeddedRenderingOptions); // merge embedded rendering options } if ((_graphExportOptions.RenderEnhancedMetafile && _graphExportOptions.RenderEnhancedMetafileAsVectorFormat) || (_graphExportOptions.RenderDropFile && _graphExportOptions.DropFileImageFormat == System.Drawing.Imaging.ImageFormat.Emf) ) { if (graphDocument is Altaxo.Graph.Gdi.GraphDocument) { _graphDocumentMetafileImage = GraphDocumentExportActions.RenderAsEnhancedMetafileVectorFormat((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions); } } if (null == _graphDocumentMetafileImage || _graphExportOptions.RenderBitmap || _graphExportOptions.RenderWindowsMetafile || (_graphExportOptions.RenderEnhancedMetafile && !_graphExportOptions.RenderEnhancedMetafileAsVectorFormat) || _graphExportOptions.RenderDropFile) { if (graphDocument is Altaxo.Graph.Gdi.GraphDocument) { _graphDocumentBitmapImage = GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor); } else if (graphDocument is Altaxo.Graph.Graph3D.GraphDocument) { _graphDocumentBitmapImage = Altaxo.Graph.Graph3D.GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Graph3D.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor); } else { throw new NotImplementedException(); } } if (_graphExportOptions.RenderEmbeddedObject) { var miniProjectBuilder = new Altaxo.Graph.Procedures.MiniProjectBuilder(); _altaxoMiniProject = miniProjectBuilder.GetMiniProject(graphDocument, true); } else { _altaxoMiniProject = null; } }
public static void InternalSaveMiniProject(IStorage pStgSave, AltaxoDocument projectToSave, string graphDocumentName) { ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject BEGIN"); try { Exception saveEx = null; Ole32Func.WriteClassStg(pStgSave, typeof(GraphDocumentEmbeddedComObject).GUID); // Store the version of this assembly { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); Version version = assembly.GetName().Version; using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoVersion", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { string text = version.ToString(); byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(text); stream.Write(nameBytes, 0, nameBytes.Length); } } // Store the name of the item using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoGraphName", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(graphDocumentName); stream.Write(nameBytes, 0, nameBytes.Length); } // Store the project using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoProjectZip", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { using (var zippedStream = new System.IO.Compression.ZipArchive(stream, System.IO.Compression.ZipArchiveMode.Create)) { var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); projectToSave.SaveToZippedFile(zippedStream, info); } stream.Close(); } if (null != saveEx) { throw saveEx; } } catch (Exception ex) { ComDebug.ReportError("InternalSaveMiniProject, Exception ", ex); } finally { Marshal.ReleaseComObject(pStgSave); } ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject END"); }
private void info_DeserializationFinished(Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object documentRoot) { info.DeserializationFinished -= new Altaxo.Serialization.Xml.XmlDeserializationCallbackEventHandler(info_DeserializationFinished); if (documentRoot is AltaxoDocument) { AltaxoDocument doc = documentRoot as AltaxoDocument; // add this script to the collection of scripts doc.FitFunctionScripts.Add(_deserializedObject); } }
private void Initialize(AltaxoDocument doc) { _directories.Clear(); _directories.Add(ProjectFolder.RootFolderName, new HashSet <object>()); // Root folder foreach (var coll in doc.ProjectItemCollections) { foreach (var v in coll.ProjectItems) { ItemAdded(v, v.Name, EventFiring.Suppressed); } } EhSelfChanged(Main.NamedObjectCollectionChangedEventArgs.FromMultipleChanges()); }
/// <summary> /// Creates the instance of project folders, tracking the provided Altaxo project. /// </summary> /// <param name="doc">Altaxo project.</param> public ProjectFolders(AltaxoDocument doc) { if (null == doc) { throw new ArgumentNullException(); } foreach (var coll in doc.ProjectItemCollections) { coll.CollectionChanged += EhItemCollectionChanged; } Initialize(doc); _parent = doc; // Parent last because we dont want the changes above to be monitored by the parent }
/// <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())); } }
/// <summary> /// Opens a Altaxo project from a project file (without asking the user). /// </summary> /// <param name="filename"></param> private void Load(string filename) { System.Text.StringBuilder errorText = new System.Text.StringBuilder(); System.IO.FileStream myStream = new System.IO.FileStream(filename, System.IO.FileMode.Open); ZipFile zipFile = new ZipFile(myStream); Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); AltaxoDocument newdocument = new AltaxoDocument(); ZipFileWrapper zipFileWrapper = new ZipFileWrapper(zipFile); try { newdocument.RestoreFromZippedFile(zipFileWrapper, info); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { Current.Workbench.CloseAllViews(); this.CurrentOpenProject = newdocument; RestoreWindowStateFromZippedFile(zipFile, info, newdocument); this.CurrentOpenProject.IsDirty = false; } catch (Exception exc) { errorText.Append(exc.ToString()); System.Windows.Forms.MessageBox.Show(Current.MainWindow, errorText.ToString(), "An error occured"); } finally { myStream.Close(); } if (errorText.Length != 0) { throw new ApplicationException(errorText.ToString()); } }
/// <summary> /// Move items in a list to another folder. /// </summary> /// <param name="list">List of items to move. Momentarily the item types <see cref="Altaxo.Data.DataTable"/>, <see cref="Altaxo.Graph.Gdi.GraphDocument"/> and <see cref="ProjectFolder"/></param> are supported. /// <param name="newFolderName">Name of the folder where to move the items into.</param> public void MoveItemsToFolder(IList <object> list, string newFolderName) { ProjectFolder.ThrowExceptionOnInvalidFullFolderPath(newFolderName); foreach (object item in list) { if (item is ProjectFolder projFolder) { string moveToFolder = ProjectFolder.Combine(newFolderName, Main.ProjectFolder.GetFoldersLastFolderPart(projFolder.Name)); RenameFolder(projFolder.Name, moveToFolder); } else if (item is Altaxo.Main.Properties.ProjectFolderPropertyDocument propDoc) { string newName = Main.ProjectFolder.Combine(newFolderName, Main.ProjectFolder.GetNamePart(propDoc.Name)); if (AltaxoDocument.ProjectFolderProperties.Contains(newName)) { // Project folders are unique for the specific folder, we can not simply rename it to another name // Thus I decided here to merge the moved property bag with the already existing property bag var existingDoc = AltaxoDocument.ProjectFolderProperties[newName]; existingDoc.PropertyBagNotNull.MergePropertiesFrom(propDoc.PropertyBagNotNull, true); } else { propDoc.Name = newName; } } else if (item is IProjectItem projItem) { var coll = AltaxoDocument.GetCollectionForProjectItemType(item.GetType()); var newName = Main.ProjectFolder.Combine(newFolderName, Main.ProjectFolder.GetNamePart(projItem.Name)); if (coll.ContainsAnyName(newName)) { newName = coll.FindNewItemName(newName); } projItem.Name = newName; } } }
public GraphDocumentDataObject(GraphDocumentBase graphDocument, ProjectFileComObject fileComObject, ComManager comManager) : base(comManager) { ComDebug.ReportInfo("{0} constructor.", this.GetType().Name); _dataAdviseHolder = new ManagedDataAdviseHolder(); _graphDocumentName = graphDocument.Name; _graphDocumentSize = graphDocument.Size; _graphExportOptions = graphDocument.GetPropertyValue(ClipboardRenderingOptions.PropertyKeyClipboardRenderingOptions, () => new ClipboardRenderingOptions()).Clone(); var embeddedRenderingOptions = graphDocument.GetPropertyValue(EmbeddedObjectRenderingOptions.PropertyKeyEmbeddedObjectRenderingOptions, () => null); if (null != embeddedRenderingOptions) _graphExportOptions.CopyFrom(embeddedRenderingOptions); // merge embedded rendering options if ((_graphExportOptions.RenderEnhancedMetafile && _graphExportOptions.RenderEnhancedMetafileAsVectorFormat) || (_graphExportOptions.RenderDropFile && _graphExportOptions.DropFileImageFormat == System.Drawing.Imaging.ImageFormat.Emf) ) { if (graphDocument is Altaxo.Graph.Gdi.GraphDocument) _graphDocumentMetafileImage = GraphDocumentExportActions.RenderAsEnhancedMetafileVectorFormat((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions); } if (null == _graphDocumentMetafileImage || _graphExportOptions.RenderBitmap || _graphExportOptions.RenderWindowsMetafile || (_graphExportOptions.RenderEnhancedMetafile && !_graphExportOptions.RenderEnhancedMetafileAsVectorFormat) || _graphExportOptions.RenderDropFile) { if (graphDocument is Altaxo.Graph.Gdi.GraphDocument) _graphDocumentBitmapImage = GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor); else if (graphDocument is Altaxo.Graph.Graph3D.GraphDocument) _graphDocumentBitmapImage = Altaxo.Graph.Graph3D.GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Graph3D.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor); else throw new NotImplementedException(); } if (_graphExportOptions.RenderEmbeddedObject) { var miniProjectBuilder = new Altaxo.Graph.Procedures.MiniProjectBuilder(); _altaxoMiniProject = miniProjectBuilder.GetMiniProject(graphDocument, true); } else { _altaxoMiniProject = null; } }
public DataTableCollection(AltaxoDocument parent) : base(parent) { }
/// <summary> /// Restores the state of the main window from a zipped Altaxo project file. /// </summary> /// <param name="zipFile">The zip file where the state file can be found into.</param> /// <param name="info">The deserialization info used to retrieve the data.</param> /// <param name="restoredDoc">The previously (also from the zip file!) restored Altaxo document.</param> public void RestoreWindowStateFromZippedFile(ZipArchive zipFile, Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info, AltaxoDocument restoredDoc) { var restoredDocModels = new List <(object Document, string ZipEntryName)>(); var restoredPadModels = new List <object>(); Altaxo.Gui.Workbench.ViewStatesMemento selectedViewsMemento = null; foreach (var zipEntry in zipFile.Entries) { try { if (zipEntry.FullName.StartsWith("Workbench/Views/")) { using (var zipinpstream = zipEntry.Open()) { info.BeginReading(zipinpstream); object readedobject = info.GetValue("ViewContentModel", null); restoredDocModels.Add((readedobject, zipEntry.FullName)); info.EndReading(); } } else if (zipEntry.FullName.StartsWith("Workbench/Pads/")) { using (var zipinpstream = zipEntry.Open()) { info.BeginReading(zipinpstream); object readedobject = info.GetValue("Model", null); if (readedobject != null) { restoredPadModels.Add(readedobject); } else { } info.EndReading(); } } else if (zipEntry.FullName == "Workbench/ViewStates.xml") { using (var zipinpstream = zipEntry.Open()) { info.BeginReading(zipinpstream); selectedViewsMemento = info.GetValue("ViewStates", null) as Altaxo.Gui.Workbench.ViewStatesMemento; info.EndReading(); } } } catch (Exception ex) { Current.Console.WriteLine("Exception during serialization of {0}, message: {1}", zipEntry.FullName, ex.Message); } } info.AnnounceDeserializationEnd(restoredDoc, false); info.AnnounceDeserializationEnd(restoredDoc, false); // now give all restored controllers a view and show them in the Main view foreach ((object doc, string entryName) in restoredDocModels) { var isSelected = entryName == selectedViewsMemento?.SelectedView_EntryName; Current.Workbench.ShowView(doc, isSelected); } foreach (var o in restoredPadModels) { var content = (IPadContent)Current.Gui.GetControllerAndControl(new object[] { o }, typeof(IPadContent)); if (null != content) { Current.Workbench.ShowPad(content, false); } } }
/// <summary> /// Opens a Altaxo project from a stream. Any existing old project will be closed without confirmation. /// </summary> /// <param name="myStream">The stream from which to load the project.</param> /// <param name="filename">Either the filename of the file which stored the document, or null (e.g. myStream is a MemoryStream).</param> protected override string InternalLoadProjectFromStream(System.IO.Stream myStream, string filename) { var errorText = new System.Text.StringBuilder(); var oldProject = CurrentOpenProject; if (null != oldProject) { OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosing)); } try { Current.Workbench.CloseAllViews(); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { SetCurrentProject(null, string.Empty); } catch (Exception exc) { errorText.Append(exc.ToString()); } // Old project is now closed if (null != oldProject) { OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosed)); } // Now open new project OnProjectChanged(new ProjectEventArgs(null, filename, ProjectEventKind.ProjectOpening)); ZipArchive zipFile = null; ; AltaxoDocument newdocument = null; ; Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info; try { newdocument = new AltaxoDocument(); zipFile = new ZipArchive(myStream, ZipArchiveMode.Read); info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); } catch (Exception exc) { errorText.Append(exc.ToString()); return(errorText.ToString()); // this is unrecoverable - we must return } try { using (var suspendToken = newdocument.SuspendGetToken()) { newdocument.RestoreFromZippedFile(zipFile, info); } } catch (Exception exc) { errorText.Append(exc.ToString()); } try { SetCurrentProject(newdocument, filename); RestoreWindowStateFromZippedFile(zipFile, info, newdocument); info.AnnounceDeserializationEnd(newdocument, true); // Final call to deserialization end CurrentOpenProject.IsDirty = false; info.AnnounceDeserializationHasCompletelyFinished(); // Annonce completly finished deserialization, activate data sources of the Altaxo document OnProjectChanged(new ProjectEventArgs(CurrentOpenProject, filename, ProjectEventKind.ProjectOpened)); } catch (Exception exc) { errorText.Append(exc.ToString()); } return(errorText.ToString()); }
public GraphDocumentCollection(AltaxoDocument parent) { this.m_Parent = parent; }
public ProjectFolderPropertyDocumentCollection(AltaxoDocument parent) : base(parent) { }
protected void Initialize() { _document = new AltaxoDocument(); _tablesToChange = new Dictionary<AbsoluteDocumentPath, DataTable>(); _columnsToChange = new Dictionary<DataColumn, DataTable>(); }
protected void Initialize() { _document = new AltaxoDocument(); _tablesToChange = new Dictionary <AbsoluteDocumentPath, DataTable>(); _columnsToChange = new Dictionary <DataColumn, DataTable>(); }
public static void InternalSaveMiniProject(IStorage pStgSave, AltaxoDocument projectToSave, string graphDocumentName) { ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject BEGIN"); try { Exception saveEx = null; Ole32Func.WriteClassStg(pStgSave, typeof(GraphDocumentEmbeddedComObject).GUID); // Store the version of this assembly { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); Version version = assembly.GetName().Version; using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoVersion", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { string text = version.ToString(); byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(text); stream.Write(nameBytes, 0, nameBytes.Length); } } // Store the name of the item using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoGraphName", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(graphDocumentName); stream.Write(nameBytes, 0, nameBytes.Length); } // Store the project using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoProjectZip", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { using (var zippedStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(stream)) { var zippedStreamWrapper = new Altaxo.Main.ZipOutputStreamWrapper(zippedStream); var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); projectToSave.SaveToZippedFile(zippedStreamWrapper, info); zippedStream.Close(); } stream.Close(); } if (null != saveEx) throw saveEx; } catch (Exception ex) { ComDebug.ReportError("InternalSaveMiniProject, Exception ", ex); } finally { Marshal.ReleaseComObject(pStgSave); } ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject END"); }
/// <summary> /// Restores the state of the main window from a zipped Altaxo project file. /// </summary> /// <param name="zipFile">The zip file where the state file can be found into.</param> /// <param name="info">The deserialization info used to retrieve the data.</param> /// <param name="restoredDoc">The previously (also from the zip file!) restored Altaxo document.</param> public void RestoreWindowStateFromZippedFile(ZipFile zipFile, Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info, AltaxoDocument restoredDoc) { System.Collections.ArrayList restoredControllers = new System.Collections.ArrayList(); foreach (ZipEntry zipEntry in zipFile) { if (!zipEntry.IsDirectory && zipEntry.Name.StartsWith("Workbench/Views/")) { System.IO.Stream zipinpstream = zipFile.GetInputStream(zipEntry); info.BeginReading(zipinpstream); object readedobject = info.GetValue("Table", this); if (readedobject is ICSharpCode.SharpDevelop.Gui.IViewContent) restoredControllers.Add(readedobject); info.EndReading(); } } info.AnnounceDeserializationEnd(restoredDoc); info.AnnounceDeserializationEnd(this); // now give all restored controllers a view and show them in the Main view foreach (IViewContent viewcontent in restoredControllers) { IMVCControllerWrapper wrapper = viewcontent as IMVCControllerWrapper; if (wrapper != null && wrapper.MVCController.ViewObject==null) Current.Gui.FindAndAttachControlTo(wrapper.MVCController); if (viewcontent.Control != null) { Current.Workbench.ShowView(viewcontent); } } }
public TextDocumentCollection(AltaxoDocument parent) : base(parent) { }
public void CreateInitialDocument() { if (null != _currentProject) throw new InvalidOperationException("There should be no document before creating the initial document"); OnProjectChanged(new ProjectEventArgs(null, null, ProjectEventKind.ProjectOpening)); var newProject = new AltaxoDocument(); SetCurrentProject(newProject, null); OnProjectChanged(new ProjectEventArgs(newProject, null, ProjectEventKind.ProjectOpened)); }
/// <summary> /// Opens a Altaxo project from a stream. Any existing old project will be closed without confirmation. /// </summary> /// <param name="myStream">The stream from which to load the project.</param> /// <param name="filename">Either the filename of the file which stored the document, or null (e.g. myStream is a MemoryStream).</param> private string InternalLoadProjectFromStream(System.IO.Stream myStream, string filename) { var errorText = new System.Text.StringBuilder(); var oldProject = CurrentOpenProject; if (null != oldProject) OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosing)); try { Current.Workbench.CloseAllViews(); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { this.SetCurrentProject(null, string.Empty); } catch (Exception exc) { errorText.Append(exc.ToString()); } // Old project is now closed if (null != oldProject) OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosed)); // Now open new project OnProjectChanged(new ProjectEventArgs(null, filename, ProjectEventKind.ProjectOpening)); ZipFile zipFile = null; ; AltaxoDocument newdocument = null; ; Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info; ZipFileWrapper zipFileWrapper; try { newdocument = new AltaxoDocument(); zipFile = new ZipFile(myStream); info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); zipFileWrapper = new ZipFileWrapper(zipFile); } catch (Exception exc) { errorText.Append(exc.ToString()); return errorText.ToString(); // this is unrecoverable - we must return } try { using (var suspendToken = newdocument.SuspendGetToken()) { newdocument.RestoreFromZippedFile(zipFileWrapper, info); } } catch (Exception exc) { errorText.Append(exc.ToString()); } try { this.SetCurrentProject(newdocument, filename); RestoreWindowStateFromZippedFile(zipFile, info, newdocument); info.AnnounceDeserializationEnd(newdocument, true); // Final call to deserialization end this.CurrentOpenProject.IsDirty = false; info.AnnounceDeserializationHasCompletelyFinished(); // Annonce completly finished deserialization, activate data sources of the Altaxo document OnProjectChanged(new ProjectEventArgs(this.CurrentOpenProject, filename, ProjectEventKind.ProjectOpened)); } catch (Exception exc) { errorText.Append(exc.ToString()); } return errorText.ToString(); }
/// <summary> /// Restores the state of the main window from a zipped Altaxo project file. /// </summary> /// <param name="zipFile">The zip file where the state file can be found into.</param> /// <param name="info">The deserialization info used to retrieve the data.</param> /// <param name="restoredDoc">The previously (also from the zip file!) restored Altaxo document.</param> public void RestoreWindowStateFromZippedFile(ZipFile zipFile, Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info, AltaxoDocument restoredDoc) { System.Collections.ArrayList restoredControllers = new System.Collections.ArrayList(); foreach (ZipEntry zipEntry in zipFile) { if (!zipEntry.IsDirectory && zipEntry.Name.StartsWith("Workbench/Views/")) { System.IO.Stream zipinpstream = zipFile.GetInputStream(zipEntry); info.BeginReading(zipinpstream); object readedobject = info.GetValue("Table", null); if (readedobject is ICSharpCode.SharpDevelop.Gui.IViewContent) restoredControllers.Add(readedobject); else if (readedobject is GraphViewLayout) restoredControllers.Add(readedobject); else if (readedobject is Altaxo.Graph.Graph3D.GuiModels.GraphViewOptions) restoredControllers.Add(readedobject); else if (readedobject is Altaxo.Worksheet.WorksheetViewLayout) restoredControllers.Add(readedobject); info.EndReading(); } } info.AnnounceDeserializationEnd(restoredDoc, false); info.AnnounceDeserializationEnd(restoredDoc, false); // now give all restored controllers a view and show them in the Main view foreach (object o in restoredControllers) { if (o is GraphViewLayout) { var ctrl = new GraphControllerWpf(); ctrl.InitializeDocument(o as GraphViewLayout); Current.Gui.FindAndAttachControlTo(ctrl); Current.Workbench.ShowView(new Altaxo.Gui.SharpDevelop.SDGraphViewContent(ctrl)); } else if (o is Altaxo.Graph.Graph3D.GuiModels.GraphViewOptions) { var so = (o as Altaxo.Graph.Graph3D.GuiModels.GraphViewOptions); if (so.GraphDocument != null) { var viewContent = this.OpenOrCreateViewContentForDocument(so.GraphDocument) as IMVCANController; if (null != viewContent) viewContent.InitializeDocument(so); } } else if (o is Altaxo.Worksheet.WorksheetViewLayout) { var wksViewLayout = (Altaxo.Worksheet.WorksheetViewLayout)o; if (null != wksViewLayout.WorksheetLayout && null != wksViewLayout.WorksheetLayout.DataTable) { var ctrl = new Altaxo.Gui.Worksheet.Viewing.WorksheetControllerWpf(); ctrl.InitializeDocument(wksViewLayout); Current.Gui.FindAndAttachControlTo(ctrl); Current.Workbench.ShowView(new Altaxo.Gui.SharpDevelop.SDWorksheetViewContent(ctrl)); } } else if (o is IViewContent) { var viewcontent = o as IViewContent; IMVCControllerWrapper wrapper = viewcontent as IMVCControllerWrapper; if (wrapper != null && wrapper.MVCController.ViewObject == null) Current.Gui.FindAndAttachControlTo(wrapper.MVCController); if (viewcontent.Control != null) { Current.Workbench.ShowView(viewcontent); } } } }
public GraphDocumentCollection(AltaxoDocument parent, SortedDictionary <string, IProjectItem> commonDictionaryForGraphs) : base(parent) { _itemsByName = commonDictionaryForGraphs ?? throw new ArgumentNullException(nameof(commonDictionaryForGraphs)); }
public DataTableCollection(AltaxoDocument _parent) { this.m_Parent = _parent; }
/// <summary> /// Opens a Altaxo project from a project file (without asking the user). /// </summary> /// <param name="filename"></param> private void Load(string filename) { System.Text.StringBuilder errorText = new System.Text.StringBuilder(); System.IO.FileStream myStream = new System.IO.FileStream(filename, System.IO.FileMode.Open); ZipFile zipFile = new ZipFile(myStream); Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); AltaxoDocument newdocument = new AltaxoDocument(); ZipFileWrapper zipFileWrapper = new ZipFileWrapper(zipFile); try { newdocument.RestoreFromZippedFile(zipFileWrapper, info); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { Current.Workbench.CloseAllViews(); this.CurrentOpenProject = newdocument; RestoreWindowStateFromZippedFile(zipFile, info, newdocument); this.CurrentOpenProject.IsDirty = false; } catch (Exception exc) { errorText.Append(exc.ToString()); System.Windows.Forms.MessageBox.Show(Current.MainWindow, errorText.ToString(), "An error occured"); } finally { myStream.Close(); } if (errorText.Length != 0) throw new ApplicationException(errorText.ToString()); }
/// <summary> /// Move the provided items from the old folder to a new folder. This is done by renaming all items in the given list by /// starting with the new folder name. /// </summary> /// <param name="oldFolderName">Name of the existing folder.</param> /// <param name="newFolderName">New name of the folder.</param> /// <param name="items">List of items that should be renamed.</param> public void MoveItemsToNewFolder(string oldFolderName, string newFolderName, IEnumerable <IProjectItem> items) { ProjectFolder.ThrowExceptionOnInvalidFullFolderPath(oldFolderName); ProjectFolder.ThrowExceptionOnInvalidFullFolderPath(newFolderName); // The algorithm tries to continuously rename items that could be renamed // If no more items could be renamed, the rest of the items is renamed with a unique generated name using the new name as basis // Suspend all items var suspendTokensOfProjectItems = items.Select(item => item.SuspendGetToken()).ToArray(); var itemList = new List <IProjectItem>(items); SortItemsByDependencies(itemList); // items that have no dependencies should now be first in the list (thus also the first to be renamed) // first, we rename all items to unique names var oldNameDictionary = new Dictionary <IProjectItem, string>(); // stores the old names of the items foreach (var item in itemList) { oldNameDictionary[item] = item.Name; item.Name = Guid.NewGuid().ToString() + "\\"; // this name should be new, the backslash is to allow also folder property documents to be renamed. } int oldFolderNameLength = oldFolderName == null ? 0 : oldFolderName.Length; var itemsRenamed = new HashSet <IProjectItem>(); foreach (var item in itemList) { string oldName = oldNameDictionary[item]; string newName = (newFolderName == null ? "" : newFolderName) + oldName.Substring(oldFolderNameLength); if (item is Main.Properties.ProjectFolderPropertyDocument propDoc) { var coll = AltaxoDocument.ProjectFolderProperties; if (!coll.ContainsAnyName(newName)) { item.Name = newName; } else // we integrate the properties in the other properties { var oldProps = coll[newName].PropertyBagNotNull; var propsToMerge = propDoc.PropertyBagNotNull; oldProps.MergePropertiesFrom(propsToMerge, false); } } else // normal case { var coll = AltaxoDocument.GetCollectionForProjectItemType(item.GetType()); if (!coll.ContainsAnyName(newName)) { item.Name = newName; } else { item.Name = coll.FindNewItemName(newName); } } } // end foreach item // Resume all items suspendTokensOfProjectItems.ForEachDo(token => token.Dispose()); }
public DataTableCollection(AltaxoDocument _parent) { this.m_Parent = _parent; }
/// <summary> /// Restores the state of the main window from a zipped Altaxo project file. /// </summary> /// <param name="zipFile">The zip file where the state file can be found into.</param> /// <param name="info">The deserialization info used to retrieve the data.</param> /// <param name="restoredDoc">The previously (also from the zip file!) restored Altaxo document.</param> public void RestoreWindowStateFromZippedFile(ZipFile zipFile, Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info, AltaxoDocument restoredDoc) { System.Collections.ArrayList restoredControllers = new System.Collections.ArrayList(); foreach (ZipEntry zipEntry in zipFile) { if (!zipEntry.IsDirectory && zipEntry.Name.StartsWith("Workbench/Views/")) { System.IO.Stream zipinpstream = zipFile.GetInputStream(zipEntry); info.BeginReading(zipinpstream); object readedobject = info.GetValue("Table", this); if (readedobject is ICSharpCode.SharpDevelop.Gui.IViewContent) { restoredControllers.Add(readedobject); } info.EndReading(); } } info.AnnounceDeserializationEnd(restoredDoc); info.AnnounceDeserializationEnd(this); // now give all restored controllers a view and show them in the Main view foreach (IViewContent viewcontent in restoredControllers) { IMVCControllerWrapper wrapper = viewcontent as IMVCControllerWrapper; if (wrapper != null && wrapper.MVCController.ViewObject == null) { Current.Gui.FindAndAttachControlTo(wrapper.MVCController); } if (viewcontent.Control != null) { Current.Workbench.ShowView(viewcontent); } } }