public static void RestoreSession(String file, Session session) { try { Globals.MainForm.RestoringContents = true; Globals.MainForm.CloseAllDocuments(false); if (!Globals.MainForm.CloseAllCanceled) { DataEvent te = new DataEvent(EventType.RestoreSession, file, session); EventManager.DispatchEvent(Globals.MainForm, te); if (!te.Handled) { for (Int32 i = 0; i < session.Files.Count; i++) { String fileToOpen = session.Files[i]; if (File.Exists(fileToOpen)) Globals.MainForm.OpenEditableDocument(fileToOpen); } if (Globals.MainForm.Documents.Length == 0) { NotifyEvent ne = new NotifyEvent(EventType.FileEmpty); EventManager.DispatchEvent(Globals.MainForm, ne); if (!ne.Handled) Globals.MainForm.New(null, null); } DocumentManager.ActivateDocument(session.Index); } } Globals.MainForm.RestoringContents = false; } catch (Exception ex) { ErrorManager.ShowError(ex); } }
public static void SaveSession(String file, Session session) { try { ObjectSerializer.Serialize(file, session); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
/// <summary> /// Loads and restores the saved session /// </summary> public static void RestoreSession(String file, SessionType type) { try { Session session = new Session(); session = (Session)ObjectSerializer.Deserialize(file, session); if (session.Files == null) session.Files = new List<string>(); session.Type = type; // set the type here... RestoreSession(file, session); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
/// <summary> /// Restores the previous document docks /// </summary> private static void RestoreDocks(Session session) { try { DockPane prevPane; for (Int32 i = 0; i < session.Nested.Count; i++) { NestedDock nestedDock = session.Nested[i]; DockContent dockContent = DocumentManager.FindDocument(nestedDock.FileName) as DockContent; if (dockContent != null && nestedDock.NestIndex > -1) { if (dockContent.DockPanel.Panes.Count > nestedDock.PaneIndex) { prevPane = dockContent.DockPanel.Panes[nestedDock.PaneIndex]; dockContent.DockTo(prevPane, DockStyle.Fill, -1); } else if (dockContent.DockPanel.Panes.Count > nestedDock.NestIndex) { DockStyle ds = DockStyle.Right; prevPane = dockContent.DockPanel.Panes[nestedDock.NestIndex]; if (nestedDock.Alignment == DockAlignment.Top) ds = DockStyle.Top; else if (nestedDock.Alignment == DockAlignment.Left) ds = DockStyle.Left; else if (nestedDock.Alignment == DockAlignment.Bottom) ds = DockStyle.Bottom; dockContent.DockTo(prevPane, ds, -1, nestedDock.Proportion); } } } } catch { /* No errors please... */ } }
/// <summary> /// Gets a session from the current documents /// </summary> public static Session GetCurrentSession() { Session session = new Session(); ITabbedDocument[] documents = Globals.MainForm.Documents; for (Int32 i = 0; i < documents.Length; i++) { ITabbedDocument document = documents[i]; if (document.IsEditable && !document.IsUntitled) { if (document == Globals.CurrentDocument) { session.Index = i; } session.Files.Add(document.FileName); AddDocumentDock(document, session); } else session.Files.Add(document.Text); } return session; }
/// <summary> /// Adds the document's dock state to the session /// </summary> public static void AddDocumentDock(ITabbedDocument document, Session session) { try { DockContent content = document as DockContent; double prop = content.Pane.NestedDockingStatus.Proportion; DockAlignment align = content.Pane.NestedDockingStatus.Alignment; Int32 paneIndex = content.DockPanel.Panes.IndexOf(content.Pane); Int32 nestIndex = content.DockPanel.Panes.IndexOf(content.Pane.NestedDockingStatus.PreviousPane); if (nestIndex > -1) { NestedDock dock = new NestedDock(document.FileName, nestIndex, paneIndex, align, prop); session.Nested.Add(dock); } } catch { /* No errors please... */ } }