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())
                {
        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);
            }
        }