コード例 #1
0
ファイル: EffectMenuBase.cs プロジェクト: cyberjaxx/OpenPDN
        private void InvalidateTimer_Tick(object sender, System.EventArgs e)
        {
            if (AppWorkspace.FindForm().WindowState == FormWindowState.Minimized)
            {
                return;
            }

            if (ProgressRegions == null)
            {
                return;
            }

            lock (ProgressRegions)
            {
                int min = ProgressRegionsStartIndex;
                int max;

                for (max = min; max < ProgressRegions.Length; ++max)
                {
                    if (ProgressRegions[max] == null)
                    {
                        break;
                    }
                }

                if (min != max)
                {
                    using (PdnRegion updateRegion = PdnRegion.CreateEmpty())
                    {
                        for (int i = min; i < max; ++i)
                        {
                            updateRegion.Union(ProgressRegions[i]);
                        }

                        using (PdnRegion simplified = Utility.SimplifyAndInflateRegion(updateRegion))
                        {
                            AppWorkspace.ActiveDocumentWorkspace.ActiveLayer.Invalidate(simplified);
                        }

                        ProgressRegionsStartIndex = max;
                    }
                }

                double progress = 100.0 * (double)max / (double)ProgressRegions.Length;
                AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(progress);
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        private void OnStateBegin(object sender, EventArgs <State> e)
        {
            if (e.Data is Updates.UpdateAvailableState && this.updatesDialog == null)
            {
                bool showDialogNow = true;

                // If no other modal window is on top of us, then go ahead and present
                // the updates dialog. Otherwise, set a timer to check every few seconds
                // and only when there's no other dialog sitting on top of us will we
                // present the dialog.

                Form        ourForm = AppWorkspace.FindForm();
                PdnBaseForm asPBF   = ourForm as PdnBaseForm;

                if (asPBF != null)
                {
                    if (!asPBF.IsCurrentModalForm)
                    {
                        showDialogNow = false;
                    }
                }

                if (showDialogNow)
                {
                    ShowUpdatesDialog();
                }
                else
                {
                    if (this.retryDialogTimer != null)
                    {
                        this.retryDialogTimer.Enabled = false;
                        this.retryDialogTimer.Dispose();
                        this.retryDialogTimer = null;
                    }

                    this.retryDialogTimer          = new System.Windows.Forms.Timer();
                    this.retryDialogTimer.Interval = 3000;

                    this.retryDialogTimer.Tick +=
                        delegate(object sender2, EventArgs e2)
                    {
                        bool done = false;

                        if (IsDisposed)
                        {
                            done = true;
                        }

                        Form        ourForm2 = AppWorkspace.FindForm();
                        PdnBaseForm asPBF2   = ourForm2 as PdnBaseForm;

                        if (asPBF2 == null)
                        {
                            done = true;
                        }
                        else
                        {
                            if (this.updatesDialog != null)
                            {
                                // Updates dialog is already visible.
                                done = true;
                            }
                            else if (asPBF2.IsCurrentModalForm && asPBF2.Enabled)
                            {
                                ShowUpdatesDialog();
                                done = true;
                            }
                        }

                        if (done && this.retryDialogTimer != null)
                        {
                            this.retryDialogTimer.Enabled = false;
                            this.retryDialogTimer.Dispose();
                            this.retryDialogTimer = null;
                        }
                    };

                    this.retryDialogTimer.Enabled = true;
                }
            }
            else if (e.Data is Updates.ReadyToCheckState)
            {
                if (this.updatesDialog == null)
                {
                    DisposeUpdates();
                }
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
            }
        }