/// <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> /// Saves the state of the main window into a zipped file. /// </summary> /// <param name="zippedStream">The file stream of the zip file.</param> /// <param name="info">The serialization info used to serialize the state of the main window.</param> public void SaveWindowStateToZippedFile(ZipArchive zippedStream, Altaxo.Serialization.Xml.XmlStreamSerializationInfo info) { var errorText = new System.Text.StringBuilder(); { // first, we save our own state var zipEntry = zippedStream.CreateEntry("Workbench/MainWindow.xml", 0); try { using (var zipEntryStream = zipEntry.Open()) { info.BeginWriting(zipEntryStream); info.AddValue("MainWindow", Current.Workbench.CreateMemento()); info.EndWriting(); } } catch (Exception exc) { errorText.Append(exc.ToString()); } } // second, we save all workbench windows into the Workbench/Views var selectedViewsMemento = new Altaxo.Gui.Workbench.ViewStatesMemento(); int i = 0; foreach (IViewContent ctrl in Current.Workbench.ViewContentCollection) { if (info.IsSerializable(ctrl.ModelObject)) { i++; var entryName = "Workbench/Views/View" + i.ToString() + ".xml"; if (ctrl.IsSelected) { selectedViewsMemento.SelectedView_EntryName = entryName; } var zipEntry = zippedStream.CreateEntry(entryName, 0); try { using (var zipEntryStream = zipEntry.Open()) { info.BeginWriting(zipEntryStream); info.AddValue("ViewContentModel", ctrl.ModelObject); info.EndWriting(); } } catch (Exception exc) { errorText.Append(exc.ToString()); } } } { // Save the states of the views var zipEntry = zippedStream.CreateEntry("Workbench/ViewStates.xml", 0); try { using (var zipEntryStream = zipEntry.Open()) { info.BeginWriting(zipEntryStream); info.AddValue("ViewStates", selectedViewsMemento); info.EndWriting(); } } catch (Exception exc) { errorText.Append(exc.ToString()); } } if (errorText.Length != 0) { throw new ApplicationException(errorText.ToString()); } }