Exemple #1
0
        public void PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento memento;

            if (documentWorkspace.Selection.IsEmpty)
            {
                memento = null;
            }
            else
            {
                CopyToClipboardAction action = new CopyToClipboardAction(documentWorkspace);
                if (!action.PerformAction())
                {
                    memento = null;
                }
                else
                {
                    using (new PushNullToolMode(documentWorkspace))
                    {
                        HistoryMemento         memento2 = new EraseSelectionFunction().Execute(documentWorkspace);
                        HistoryMemento[]       actions  = new HistoryMemento[] { memento2 };
                        CompoundHistoryMemento memento3 = new CompoundHistoryMemento(StaticName, StaticImage, actions);
                        memento = memento3;
                    }
                }
            }
            if (memento != null)
            {
                documentWorkspace.History.PushNewMemento(memento);
            }
        }
Exemple #2
0
        public void PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento finalHM;

            if (documentWorkspace.Selection.IsEmpty)
            {
                finalHM = null;
            }
            else
            {
                CopyToClipboardAction ctca = new CopyToClipboardAction(documentWorkspace);
                bool result = ctca.PerformAction();

                if (!result)
                {
                    finalHM = null;
                }
                else
                {
                    using (new PushNullToolMode(documentWorkspace))
                    {
                        EraseSelectionFunction esa = new EraseSelectionFunction();
                        HistoryMemento         hm  = esa.Execute(documentWorkspace);

                        CompoundHistoryMemento chm = new CompoundHistoryMemento(
                            StaticName,
                            StaticImage,
                            new HistoryMemento[] { hm });

                        finalHM = chm;
                    }
                }
            }

            if (finalHM != null)
            {
                documentWorkspace.History.PushNewMemento(finalHM);
            }
        }
Exemple #3
0
        public void PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento finalHM;

            if (documentWorkspace.Selection.IsEmpty)
            {
                finalHM = null;
            }
            else
            {
                CopyToClipboardAction ctca = new CopyToClipboardAction(documentWorkspace);
                bool result = ctca.PerformAction();

                if (!result)
                {
                    finalHM = null;
                }
                else
                {
                    using (new PushNullToolMode(documentWorkspace))
                    {
                        EraseSelectionFunction esa = new EraseSelectionFunction();
                        HistoryMemento hm = esa.Execute(documentWorkspace);

                        CompoundHistoryMemento chm = new CompoundHistoryMemento(
                            StaticName,
                            StaticImage,
                            new HistoryMemento[] { hm });

                        finalHM = chm;
                    }
                }
            }

            if (finalHM != null)
            {
                documentWorkspace.History.PushNewMemento(finalHM);
            }
        }
Exemple #4
0
        private void CommonActionsStrip_ButtonClick(object sender, EventArgs<CommonAction> e)
        {
            CommonAction ca = e.Data;

            switch (ca)
            {
                case CommonAction.New:
                    PerformAction(new NewImageAction());
                    break;

                case CommonAction.Open:
                    PerformAction(new OpenFileAction());
                    break;

                case CommonAction.Save:
                    if (ActiveDocumentWorkspace != null)
                    {
                        ActiveDocumentWorkspace.DoSave();
                    }
                    break;

                case CommonAction.Print:
                    if (ActiveDocumentWorkspace != null)
                    {
                        PrintAction pa = new PrintAction();
                        ActiveDocumentWorkspace.PerformAction(pa);
                    }
                    break;

                case CommonAction.Cut:
                    if (ActiveDocumentWorkspace != null)
                    {
                        CutAction cutAction = new CutAction();
                        cutAction.PerformAction(ActiveDocumentWorkspace);
                    }

                    break;

                case CommonAction.Copy:
                    if (ActiveDocumentWorkspace != null)
                    {
                        CopyToClipboardAction ctca = new CopyToClipboardAction(ActiveDocumentWorkspace);
                        ctca.PerformAction();
                    }
                    break;

                case CommonAction.Paste:
                    if (ActiveDocumentWorkspace != null)
                    {
                        PasteAction pa = new PasteAction(ActiveDocumentWorkspace);
                        pa.PerformAction();
                    }

                    break;

                case CommonAction.CropToSelection:
                    if (ActiveDocumentWorkspace != null)
                    {
                        using (new PushNullToolMode(ActiveDocumentWorkspace))
                        {
                            ActiveDocumentWorkspace.ExecuteFunction(new CropToSelectionFunction());
                        }
                    }

                    break;

                case CommonAction.Deselect:
                    if (ActiveDocumentWorkspace != null)
                    {
                        ActiveDocumentWorkspace.ExecuteFunction(new DeselectFunction());
                    }
                    break;

                case CommonAction.Undo:
                    if (ActiveDocumentWorkspace != null)
                    {
                        ActiveDocumentWorkspace.PerformAction(new HistoryUndoAction());
                    }
                    break;

                case CommonAction.Redo:
                    if (ActiveDocumentWorkspace != null)
                    {
                        ActiveDocumentWorkspace.PerformAction(new HistoryRedoAction());
                    }
                    break;

                default:
                    throw new InvalidEnumArgumentException("e.Data");
            }

            if (ActiveDocumentWorkspace != null)
            {
                ActiveDocumentWorkspace.Focus();
            }
        }