public override void PerformAction(AppWorkspace appWorkspace) { if (!appWorkspace.CanSetActiveWorkspace) { this.cancelled = true; return; } DocumentWorkspace activeDocumentWorkspace = appWorkspace.ActiveDocumentWorkspace; int?nullable = null; try { nullable = new int?(appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency); appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = 0; } catch (NullReferenceException) { } List <DocumentWorkspace> unsavedDocs = new List <DocumentWorkspace>(); foreach (DocumentWorkspace workspace2 in appWorkspace.DocumentWorkspaces) { if ((workspace2.Document != null) && workspace2.Document.Dirty) { unsavedDocs.Add(workspace2); } } if (unsavedDocs.Count == 1) { CloseWorkspaceAction action = new CloseWorkspaceAction(unsavedDocs[0]); action.PerformAction(appWorkspace); this.cancelled = action.Cancelled; } else if (unsavedDocs.Count > 1) { using (UnsavedChangesDialog dialog = new UnsavedChangesDialog()) {
private bool ProcessMessage(string message) { ArgumentAction action; string actionParm; bool result; result = SplitMessage(message, out action, out actionParm); if (!result) { return true; } switch (action) { case ArgumentAction.NoOp: result = true; break; case ArgumentAction.Open: Activate(); if (IsCurrentModalForm && Enabled) { result = this.appWorkspace.OpenFileInNewWorkspace(actionParm); } break; case ArgumentAction.Print: Activate(); if (IsCurrentModalForm && Enabled) { result = this.appWorkspace.OpenFileInNewWorkspace(actionParm); if (result) { DocumentWorkspace dw = this.appWorkspace.ActiveDocumentWorkspace; PrintAction pa = new PrintAction(); dw.PerformAction(pa); CloseWorkspaceAction cwa = new CloseWorkspaceAction(dw); this.appWorkspace.PerformAction(cwa); if (this.appWorkspace.DocumentWorkspaces.Length == 0) { Startup.CloseApplication(); } } } break; default: throw new InvalidEnumArgumentException(); } return result; }
private void DocumentStrip_DocumentTabClicked( object sender, EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e) { switch (e.Data.Second) { case DocumentClickAction.Select: this.ActiveDocumentWorkspace = e.Data.First; break; case DocumentClickAction.Close: CloseWorkspaceAction cwa = new CloseWorkspaceAction(e.Data.First); PerformAction(cwa); break; default: throw new NotImplementedException("Code for DocumentClickAction." + e.Data.Second.ToString() + " not implemented"); } Update(); }
public override void PerformAction(AppWorkspace appWorkspace) { int oldLatency = appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency; appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = 0; List<DocumentWorkspace> unsavedDocs = new List<DocumentWorkspace>(); foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces) { if (dw.Document != null && dw.Document.Dirty) { unsavedDocs.Add(dw); } } if (unsavedDocs.Count == 1) { CloseWorkspaceAction cwa = new CloseWorkspaceAction(unsavedDocs[0]); cwa.PerformAction(appWorkspace); this.cancelled = cwa.Cancelled; } else if (unsavedDocs.Count > 1) { using (UnsavedChangesDialog dialog = new UnsavedChangesDialog()) { dialog.DocumentClicked += delegate(object sender, EventArgs<DocumentWorkspace> e2) { appWorkspace.ActiveDocumentWorkspace = e2.Data; }; dialog.Documents = unsavedDocs.ToArray(); if (appWorkspace.ActiveDocumentWorkspace.Document.Dirty) { dialog.SelectedDocument = appWorkspace.ActiveDocumentWorkspace; } Form mainForm = appWorkspace.FindForm(); if (mainForm != null) { PdnBaseForm asPDF = mainForm as PdnBaseForm; if (asPDF != null) { asPDF.RestoreWindow(); } } DialogResult dr = Utility.ShowDialog(dialog, appWorkspace); switch (dr) { case DialogResult.Yes: { foreach (DocumentWorkspace dw in unsavedDocs) { appWorkspace.ActiveDocumentWorkspace = dw; bool result = dw.DoSave(); if (result) { appWorkspace.RemoveDocumentWorkspace(dw); } else { this.cancelled = true; break; } } } break; case DialogResult.No: this.cancelled = false; break; case DialogResult.Cancel: this.cancelled = true; break; default: throw new InvalidEnumArgumentException(); } } appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = oldLatency; } if (!this.cancelled) { UI.SuspendControlPainting(appWorkspace); foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces) { appWorkspace.RemoveDocumentWorkspace(dw); } UI.ResumeControlPainting(appWorkspace); appWorkspace.Invalidate(true); } }
public override void PerformAction(AppWorkspace appWorkspace) { DocumentWorkspace originalDW = appWorkspace.ActiveDocumentWorkspace; int oldLatency = 10; try { oldLatency = appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency; appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = 0; } catch (NullReferenceException) { // See bug #2544 } List <DocumentWorkspace> unsavedDocs = new List <DocumentWorkspace>(); foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces) { if (dw.Document != null && dw.Document.Dirty) { unsavedDocs.Add(dw); } } if (unsavedDocs.Count == 1) { CloseWorkspaceAction cwa = new CloseWorkspaceAction(unsavedDocs[0]); cwa.PerformAction(appWorkspace); this.cancelled = cwa.Cancelled; } else if (unsavedDocs.Count > 1) { using (UnsavedChangesDialog dialog = new UnsavedChangesDialog()) { dialog.DocumentClicked += (s, e2) => { appWorkspace.ActiveDocumentWorkspace = e2.Data; }; dialog.Documents = unsavedDocs.ToArray(); if (appWorkspace.ActiveDocumentWorkspace.Document.Dirty) { dialog.SelectedDocument = appWorkspace.ActiveDocumentWorkspace; } Form mainForm = appWorkspace.FindForm(); if (mainForm != null) { PdnBaseForm asPDF = mainForm as PdnBaseForm; if (asPDF != null) { asPDF.RestoreWindow(); } } DialogResult dr = Utility.ShowDialog(dialog, appWorkspace); switch (dr) { case DialogResult.Yes: { foreach (DocumentWorkspace dw in unsavedDocs) { appWorkspace.ActiveDocumentWorkspace = dw; bool result = dw.DoSave(); if (result) { appWorkspace.RemoveDocumentWorkspace(dw); } else { this.cancelled = true; break; } } } break; case DialogResult.No: this.cancelled = false; break; case DialogResult.Cancel: this.cancelled = true; break; default: throw new InvalidEnumArgumentException(); } } } try { appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = oldLatency; } catch (NullReferenceException) { // See bug #2544 } if (this.cancelled) { if (appWorkspace.ActiveDocumentWorkspace != originalDW && !originalDW.IsDisposed) { appWorkspace.ActiveDocumentWorkspace = originalDW; } } else { UI.SuspendControlPainting(appWorkspace); foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces) { appWorkspace.RemoveDocumentWorkspace(dw); } UI.ResumeControlPainting(appWorkspace); appWorkspace.Invalidate(true); } }