public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            string[]       fileNames;
            string         startingDir = Path.GetDirectoryName(documentWorkspace.FilePath);
            DialogResult   result      = DocumentWorkspace.ChooseFiles(documentWorkspace, out fileNames, true, startingDir);
            HistoryMemento retHA       = null;

            if (result == DialogResult.OK)
            {
                Type oldToolType = documentWorkspace.GetToolType();
                documentWorkspace.SetTool(null);

                retHA = ImportMultipleFiles(documentWorkspace, fileNames);

                Type newToolType;
                if (retHA != null)
                {
                    CompoundHistoryMemento cha = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { retHA });
                    retHA       = cha;
                    newToolType = typeof(Tools.MoveTool);
                }
                else
                {
                    newToolType = oldToolType;
                }

                documentWorkspace.SetToolFromType(newToolType);
            }

            return(retHA);
        }
Beispiel #2
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            string[]       strArray;
            string         directoryName = Path.GetDirectoryName(documentWorkspace.FilePath);
            DialogResult   result        = DocumentWorkspace.ChooseFiles(documentWorkspace, out strArray, true, directoryName);
            HistoryMemento memento       = null;

            if (result == DialogResult.OK)
            {
                System.Type type2;
                System.Type toolType = documentWorkspace.GetToolType();
                documentWorkspace.ClearTool();
                memento = this.ImportMultipleFiles(documentWorkspace, strArray);
                if (memento != null)
                {
                    HistoryMemento[]       actions  = new HistoryMemento[] { memento };
                    CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, StaticImage, actions);
                    memento = memento2;
                    type2   = typeof(MoveSelectedPixelsTool);
                }
                else
                {
                    type2 = toolType;
                }
                documentWorkspace.SetToolFromType(type2);
            }
            return(memento);
        }
Beispiel #3
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            mouseDown = false;

            switch (AppEnvironment.ColorPickerClickBehavior)
            {
            case ColorPickerClickBehavior.NoToolSwitch:
                break;

            case ColorPickerClickBehavior.SwitchToLastTool:
                DocumentWorkspace.SetToolFromType(DocumentWorkspace.PreviousActiveToolType);
                break;

            case ColorPickerClickBehavior.SwitchToPencilTool:
                DocumentWorkspace.SetToolFromType(typeof(PencilTool));
                break;

            default:
                throw new System.ComponentModel.InvalidEnumArgumentException();
            }
        }
Beispiel #4
0
 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 HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            string[] fileNames;
            string startingDir = Path.GetDirectoryName(documentWorkspace.FilePath);
            DialogResult result = DocumentWorkspace.ChooseFiles(documentWorkspace, out fileNames, true, startingDir);
            HistoryMemento retHA = null;

            if (result == DialogResult.OK)
            {
                Type oldToolType = documentWorkspace.GetToolType();
                documentWorkspace.SetTool(null);

                retHA = ImportMultipleFiles(documentWorkspace, fileNames);

                Type newToolType;
                if (retHA != null)
                {
                    CompoundHistoryMemento cha = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { retHA });
                    retHA = cha;
                    newToolType = typeof(Tools.MoveTool);
                }
                else
                {
                    newToolType = oldToolType;
                }

                documentWorkspace.SetToolFromType(newToolType);
            }

            return retHA;
        }