private void CloseWorkspace(AppWorkspace appWorkspace, DocumentWorkspace dw) { if (dw != null) { if (dw.Document == null) { appWorkspace.RemoveDocumentWorkspace(dw); } else if (!dw.Document.Dirty) { appWorkspace.RemoveDocumentWorkspace(dw); } else { appWorkspace.ActiveDocumentWorkspace = dw; TaskButton button = new TaskButton(PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText")); TaskButton button2 = new TaskButton(PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText")); TaskButton button3 = new TaskButton(PdnResources.GetImageResource("Icons.CancelIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText")); string str = PdnResources.GetString("CloseWorkspaceAction.Title"); string str3 = string.Format(PdnResources.GetString("CloseWorkspaceAction.IntroText.Format"), dw.GetFileFriendlyName()); int thumbEdgeLength = UIUtil.ScaleWidth(80); SizeInt32 num = ThumbnailHelpers.ComputeThumbnailSize(dw.Document.Size(), thumbEdgeLength); SizeInt32 fullThumbSize = new SizeInt32(num.Width + 4, num.Height + 4); bool animating = true; Image finalThumb = null; Action <Image> animationEvent = null; Image[] busyAnimationFrames = AnimatedResources.Working; Image[] busyAnimationThumbs = new Image[busyAnimationFrames.Length]; int animationHz = 50; Stopwatch timing = new Stopwatch(); timing.Start(); long elapsedTicks = timing.ElapsedTicks; using (System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer()) {
public override void PerformAction(AppWorkspace appWorkspace) { if (appWorkspace == null) { throw new ArgumentNullException("appWorkspace"); } DocumentWorkspace dw; if (this.closeMe == null) { dw = appWorkspace.ActiveDocumentWorkspace; } else { dw = this.closeMe; } if (dw != null) { if (dw.Document == null) { appWorkspace.RemoveDocumentWorkspace(dw); } else if (!dw.Document.Dirty) { appWorkspace.RemoveDocumentWorkspace(dw); } else { appWorkspace.ActiveDocumentWorkspace = dw; TaskButton saveTB = new TaskButton( PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText")); TaskButton dontSaveTB = new TaskButton( PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText")); TaskButton cancelTB = new TaskButton( PdnResources.GetImageResource("Icons.CancelIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText")); string title = PdnResources.GetString("CloseWorkspaceAction.Title"); string introTextFormat = PdnResources.GetString("CloseWorkspaceAction.IntroText.Format"); string introText = string.Format(introTextFormat, dw.GetFriendlyName()); Image thumb = appWorkspace.GetDocumentWorkspaceThumbnail(dw); if (thumb == null) { thumb = new Bitmap(32, 32); } Bitmap taskImage = new Bitmap(thumb.Width + 2, thumb.Height + 2, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(taskImage)) { g.Clear(Color.Transparent); g.DrawImage( thumb, new Rectangle(1, 1, thumb.Width, thumb.Height), new Rectangle(0, 0, thumb.Width, thumb.Height), GraphicsUnit.Pixel); Utility.DrawDropShadow1px(g, new Rectangle(0, 0, taskImage.Width, taskImage.Height)); } Form mainForm = appWorkspace.FindForm(); if (mainForm != null) { if (mainForm is PdnBaseForm asPDF) { asPDF.RestoreWindow(); } } Icon warningIcon; ImageResource warningIconImageRes = PdnResources.GetImageResource("Icons.WarningIcon.png"); if (warningIconImageRes != null) { Image warningIconImage = warningIconImageRes.Reference; warningIcon = Utility.ImageToIcon(warningIconImage, false); } else { warningIcon = null; } TaskButton clickedTB = TaskDialog.Show( appWorkspace, warningIcon, title, taskImage, false, introText, new TaskButton[] { saveTB, dontSaveTB, cancelTB }, saveTB, cancelTB, 340); if (clickedTB == saveTB) { if (dw.DoSave()) { this.Cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.Cancelled = true; } } else if (clickedTB == dontSaveTB) { this.Cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.Cancelled = true; } } } Utility.GCFullCollect(); }
public override void PerformAction(AppWorkspace appWorkspace) { if (appWorkspace.CanSetActiveWorkspace) { try { SizeInt32? nullable; IPdnDataObject dataObject; MaskedSurface clipboardImage; try { using (new WaitCursorChanger(appWorkspace)) { CleanupManager.RequestCleanup(); dataObject = PdnClipboard.GetDataObject(); if (ClipboardUtil.IsClipboardImageMaybeAvailable(appWorkspace, dataObject)) { clipboardImage = ClipboardUtil.GetClipboardImage(appWorkspace, dataObject); if (clipboardImage != null) { nullable = new SizeInt32?(clipboardImage.GetCachedGeometryMaskScansBounds().Size); } else { nullable = null; } } else { clipboardImage = null; nullable = null; } } } catch (OutOfMemoryException exception) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception); return; } catch (Exception exception2) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2); return; } if (!nullable.HasValue) { MessageBoxUtil.ErrorBox(appWorkspace, PdnResources.GetString("PasteInToNewImageAction.Error.NoClipboardImage")); } else { Type defaultToolType; SizeInt32 size = nullable.Value; Document document = null; if ((appWorkspace.ActiveDocumentWorkspace != null) && (appWorkspace.ActiveDocumentWorkspace.Tool != null)) { defaultToolType = appWorkspace.ActiveDocumentWorkspace.Tool.GetType(); } else { defaultToolType = appWorkspace.DefaultToolType; } using (new WaitCursorChanger(appWorkspace)) { document = new Document(size); DocumentWorkspace documentWorkspace = appWorkspace.AddNewDocumentWorkspace(); documentWorkspace.Document = document; documentWorkspace.History.PushNewMemento(new NullHistoryMemento(string.Empty, null)); PasteInToNewLayerAction action = new PasteInToNewLayerAction(documentWorkspace, dataObject, clipboardImage); if (action.PerformAction()) { using (new PushNullToolMode(documentWorkspace)) { documentWorkspace.Selection.Reset(); documentWorkspace.SetDocumentSaveOptions(null, null, null); documentWorkspace.History.ClearAll(); documentWorkspace.History.PushNewMemento(new NullHistoryMemento(PdnResources.GetString("Menu.Edit.PasteInToNewImage.Text"), PdnResources.GetImageResource("Icons.MenuEditPasteInToNewImageIcon.png"))); appWorkspace.ActiveDocumentWorkspace = documentWorkspace; } documentWorkspace.SetToolFromType(defaultToolType); } else { appWorkspace.RemoveDocumentWorkspace(documentWorkspace); document.Dispose(); } } } } catch (ExternalException exception3) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.TransferError"), exception3); } catch (OutOfMemoryException exception4) { ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.OutOfMemory"), exception4); } catch (ThreadStateException) { } } }
public override void PerformAction(AppWorkspace appWorkspace) { DocumentWorkspace dw; if (this.closeMe == null) { dw = appWorkspace.ActiveDocumentWorkspace; } else { dw = this.closeMe; } if (dw != null) { if (dw.Document == null) { appWorkspace.RemoveDocumentWorkspace(dw); } else if (!dw.Document.Dirty) { appWorkspace.RemoveDocumentWorkspace(dw); } else { appWorkspace.ActiveDocumentWorkspace = dw; TaskButton saveTB = new TaskButton( ImageResource.Get("Icons.MenuFileSaveIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText")); TaskButton dontSaveTB = new TaskButton( ImageResource.Get("Icons.MenuFileCloseIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText")); TaskButton cancelTB = new TaskButton( ImageResource.Get("Icons.CancelIcon.png").Reference, PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"), PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText")); string title = PdnResources.GetString("CloseWorkspaceAction.Title"); string introTextFormat = PdnResources.GetString("CloseWorkspaceAction.IntroText.Format"); string introText = string.Format(introTextFormat, dw.GetFriendlyName()); Image thumb = appWorkspace.GetDocumentWorkspaceThumbnail(dw); Bitmap taskImage = new Bitmap(thumb.Width + 2, thumb.Height + 2, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(taskImage)) { g.Clear(Color.Transparent); g.DrawImage( thumb, new Rectangle(1, 1, thumb.Width, thumb.Height), new Rectangle(0, 0, thumb.Width, thumb.Height), GraphicsUnit.Pixel); Utility.DrawDropShadow1px(g, new Rectangle(0, 0, taskImage.Width, taskImage.Height)); } Form mainForm = appWorkspace.FindForm(); if (mainForm != null) { PdnBaseForm asPDF = mainForm as PdnBaseForm; if (asPDF != null) { asPDF.RestoreWindow(); } } TaskButton clickedTB = TaskDialog.Show( appWorkspace, Utility.ImageToIcon(ImageResource.Get("Icons.WarningIcon.png").Reference, false), title, taskImage, false, introText, new TaskButton[] { saveTB, dontSaveTB, cancelTB }, saveTB, cancelTB, 340); if (clickedTB == saveTB) { if (dw.DoSave()) { this.cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.cancelled = true; } } else if (clickedTB == dontSaveTB) { this.cancelled = false; appWorkspace.RemoveDocumentWorkspace(dw); } else { this.cancelled = true; } } } Utility.GCFullCollect(); }
public override void PerformAction(AppWorkspace appWorkspace) { try { IDataObject pasted; Image image; using (new WaitCursorChanger(appWorkspace)) { Utility.GCFullCollect(); pasted = Clipboard.GetDataObject(); image = (Image)pasted.GetData(DataFormats.Bitmap); } if (image == null) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("PasteInToNewImageAction.Error.NoClipboardImage")); } else { Size newSize = image.Size; image.Dispose(); image = null; pasted = null; Document document = null; using (new WaitCursorChanger(appWorkspace)) { document = new Document(newSize); DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace(); dw.Document = document; dw.History.PushNewMemento(new NullHistoryMemento(string.Empty, null)); PasteInToNewLayerAction pitnla = new PasteInToNewLayerAction(dw); bool result = pitnla.PerformAction(); if (result) { dw.Selection.Reset(); dw.SetDocumentSaveOptions(null, null, null); dw.History.ClearAll(); dw.History.PushNewMemento( new NullHistoryMemento( PdnResources.GetString("NewImageAction.Name"), PdnResources.GetImageResource("Icons.MenuLayersAddNewLayerIcon.png"))); appWorkspace.ActiveDocumentWorkspace = dw; } else { appWorkspace.RemoveDocumentWorkspace(dw); document.Dispose(); } } } } catch (ExternalException) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.TransferError")); return; } catch (OutOfMemoryException) { Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.OutOfMemory")); return; } catch (ThreadStateException) { // The ApartmentState property of the application is not set to ApartmentState.STA // I don't think this one will ever happen, seeing as how Main is tagged with the // STA attribute. return; } }
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); } }