public WorkspaceWidgets(AppWorkspace workspace) { this.workspace = workspace; }
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); } }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.defaultButton = new System.Windows.Forms.Button(); this.appWorkspace = new PaintDotNet.AppWorkspace(); this.floaterOpacityTimer = new System.Windows.Forms.Timer(this.components); this.deferredInitializationTimer = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // // appWorkspace // this.appWorkspace.Dock = System.Windows.Forms.DockStyle.Fill; this.appWorkspace.Location = new System.Drawing.Point(0, 0); this.appWorkspace.Name = "appWorkspace"; this.appWorkspace.Size = new System.Drawing.Size(752, 648); this.appWorkspace.TabIndex = 2; this.appWorkspace.ActiveDocumentWorkspaceChanging += new EventHandler(AppWorkspace_ActiveDocumentWorkspaceChanging); this.appWorkspace.ActiveDocumentWorkspaceChanged += new EventHandler(AppWorkspace_ActiveDocumentWorkspaceChanged); // // floaterOpacityTimer // this.floaterOpacityTimer.Enabled = false; this.floaterOpacityTimer.Interval = 25; this.floaterOpacityTimer.Tick += new System.EventHandler(this.FloaterOpacityTimer_Tick); // // deferredInitializationTimer // this.deferredInitializationTimer.Interval = 250; this.deferredInitializationTimer.Tick += new EventHandler(DeferredInitialization); // // defaultButton // this.defaultButton.Size = new System.Drawing.Size(1, 1); this.defaultButton.Text = ""; this.defaultButton.Location = new Point(-100, -100); this.defaultButton.TabStop = false; this.defaultButton.Click += new EventHandler(DefaultButton_Click); // // MainForm // this.AllowDrop = true; this.AutoScaleDimensions = new SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(950, 738); this.Controls.Add(this.appWorkspace); this.Controls.Add(this.defaultButton); this.AcceptButton = this.defaultButton; this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation; this.ForceActiveTitleBar = true; this.KeyPreview = true; this.Controls.SetChildIndex(this.appWorkspace, 0); this.ResumeLayout(false); this.PerformLayout(); }
public abstract void PerformAction(AppWorkspace appWorkspace);