123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using PaintDotNet.Base.CommTool;
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Windows.Forms;
- namespace PaintDotNet.Actions
- {
- internal sealed class CloseWorkspaceAction : AppWorkspaceAction
- {
- private DocumentWorkspace closeMe;
- private bool cancelled;
- public bool Cancelled
- {
- get
- {
- return this.cancelled;
- }
- }
- public override void PerformAction(AppWorkspace appWorkspace)
- {
- if (appWorkspace == null)
- {
- throw new ArgumentNullException("appWorkspace");
- }
- appWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll();
- DocumentWorkspace dw;
- if (this.closeMe == null)
- {
- if (appWorkspace.toRemoveDocumentWorkspaceIndex >= 0 && appWorkspace.toRemoveDocumentWorkspaceIndex < appWorkspace.DocumentWorkspaces.Length)
- {
- dw = appWorkspace.DocumentWorkspaces[appWorkspace.toRemoveDocumentWorkspaceIndex];
- appWorkspace.toRemoveDocumentWorkspaceIndex = -1;
- }
- else
- 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") + "( Y )",
- PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText"));
- TaskButton dontSaveTB = new TaskButton(
- PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference,
- PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText") + "( N )",
- PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText"));
- TaskButton cancelTB = new TaskButton(
- PdnResources.GetImageResource("Icons.CancelIcon.png").Reference,
- PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText") + "( ESC )",
- 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));
- }**/
- Image taskImage = DrawRulerHelper.ResizeImage(appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap(), 115, 86, Base.Enum.ThumbnailMode.Cut);
- Form mainForm = appWorkspace.FindForm();
- if (mainForm != null)
- {
- PdnBaseForm asPDF = mainForm as PdnBaseForm;
- if (asPDF != null)
- {
- 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,
- false,
- 0,
- out bool unuse);
- if (clickedTB == saveTB)
- {
- if (dw.DoSaveNew())
- {
- this.cancelled = false;
- if(!dw.IsDisposed)
- appWorkspace.RemoveDocumentWorkspace(dw);
- }
- else
- {
- this.cancelled = true;
- }
- }
- else if (clickedTB == dontSaveTB)
- {
- this.cancelled = false;
- if (!dw.IsDisposed)
- appWorkspace.RemoveDocumentWorkspace(dw);
- }
- else
- {
- this.cancelled = true;
- }
- }
- }
- Utility.GCFullCollect();
- }
- public CloseWorkspaceAction()
- : this(null)
- {
- }
- public CloseWorkspaceAction(DocumentWorkspace closeMe)
- {
- this.closeMe = closeMe;
- this.cancelled = false;
- }
- }
- }
|