Beispiel #1
0
        private HistoryMemento DoCanvasResize(DocumentWorkspace documentWorkspace, Size newLayerSize)
        {
            Document document;
            int      activeLayerIndex = documentWorkspace.ActiveLayerIndex;
            Size     newSize          = new Size(Math.Max(newLayerSize.Width, documentWorkspace.Document.Width), Math.Max(newLayerSize.Height, documentWorkspace.Document.Height));

            try
            {
                using (new WaitCursorChanger(documentWorkspace))
                {
                    CleanupManager.RequestCleanup();
                    document = CanvasSizeAction.ResizeDocument(documentWorkspace.Document, newSize, AnchorEdge.TopLeft, documentWorkspace.ToolSettings.SecondaryColor.Value);
                }
            }
            catch (OutOfMemoryException exception)
            {
                ExceptionDialog.ShowErrorDialog(documentWorkspace, PdnResources.GetString("ImportFromFileAction.AskForCanvasResize.OutOfMemory"), exception);
                document = null;
            }
            if (document == null)
            {
                return(null);
            }
            HistoryMemento memento = new ReplaceDocumentHistoryMemento(string.Empty, null, documentWorkspace);

            using (new WaitCursorChanger(documentWorkspace))
            {
                documentWorkspace.Document = document;
            }
            documentWorkspace.ActiveLayer = (Layer)documentWorkspace.Document.Layers[activeLayerIndex];
            return(memento);
        }
Beispiel #2
0
        private HistoryMemento ImportOneLayer(DocumentWorkspace documentWorkspace, BitmapLayer layer)
        {
            SegmentedList <HistoryMemento> items = new SegmentedList <HistoryMemento>();
            bool flag = true;

            if (flag && !documentWorkspace.Selection.IsEmpty)
            {
                HistoryMemento item = new DeselectFunction().Execute(documentWorkspace);
                items.Add(item);
            }
            if (flag && ((layer.Width > documentWorkspace.Document.Width) || (layer.Height > documentWorkspace.Document.Height)))
            {
                HistoryMemento memento3 = this.DoCanvasResize(documentWorkspace, layer.Size);
                if (memento3 == null)
                {
                    flag = false;
                }
                else
                {
                    items.Add(memento3);
                }
            }
            if (flag && (layer.Size != documentWorkspace.Document.Size))
            {
                BitmapLayer layer2;
                try
                {
                    using (new WaitCursorChanger(documentWorkspace))
                    {
                        CleanupManager.RequestCleanup();
                        layer2 = CanvasSizeAction.ResizeLayer(layer, documentWorkspace.Document.Size, AnchorEdge.TopLeft, ColorBgra.White.NewAlpha(0));
                    }
                }
                catch (OutOfMemoryException exception)
                {
                    ExceptionDialog.ShowErrorDialog(documentWorkspace, PdnResources.GetString("ImportFromFileAction.ImportOneLayer.OutOfMemory"), exception);
                    flag   = false;
                    layer2 = null;
                }
                if (layer2 != null)
                {
                    layer.Dispose();
                    layer = layer2;
                }
            }
            if (flag)
            {
                NewLayerHistoryMemento memento4 = new NewLayerHistoryMemento(string.Empty, null, documentWorkspace, documentWorkspace.Document.Layers.Count);
                documentWorkspace.Document.Layers.Add(layer);
                items.Add(memento4);
            }
            if (flag)
            {
                return(new CompoundHistoryMemento(string.Empty, null, items.ToArrayEx <HistoryMemento>()));
            }
            this.Rollback(items);
            return(null);
        }
Beispiel #3
0
 internal static void ShowStartupError(Exception ex, string message = null, bool mustTerminate = true)
 {
     ExceptionDialog.ShowErrorDialog(
         ex,
         Core.Application.NameAndVersionWithRevision,
         Environment.OSVersion.VersionString,
         message,
         Constants.GoogleGroupUrl,
         mustTerminate);
 }
Beispiel #4
0
 public void Finish(IUpdatesServiceHost host)
 {
     if (!this.finishing)
     {
         try
         {
             if (this.haveFinished)
             {
                 throw new ApplicationException("already called Finish()");
             }
             this.finishing    = true;
             this.haveFinished = true;
             bool flag      = Security.VerifySignedFile(base.StateMachine.UIContext, this.installerPath, false, false);
             bool cancelled = false;
             host.CloseAllWorkspaces(out cancelled);
             if (flag && !cancelled)
             {
                 AppSettings.Instance.Updates.PackageFileName.Value = this.installerPath;
                 if (string.Compare(Path.GetExtension(this.installerPath), ".exe", true) == 0)
                 {
                     ShellUtil.IsActivityQueuedForRestart = false;
                     Form parent = new Form {
                         BackColor = Color.Red
                     };
                     parent.TransparencyKey = parent.BackColor;
                     parent.ShowInTaskbar   = false;
                     parent.FormBorderStyle = FormBorderStyle.None;
                     parent.StartPosition   = FormStartPosition.CenterScreen;
                     parent.Show();
                     try
                     {
                         ShellUtil.Execute(parent, this.installerPath, "/skipConfig /restartPdnOnExit", ExecutePrivilege.RequireAdmin, ExecuteWaitType.ReturnImmediately);
                     }
                     catch (Exception exception)
                     {
                         ExceptionDialog.ShowErrorDialog(parent, exception);
                     }
                     parent.Close();
                     Startup.CloseApplication();
                 }
             }
             else
             {
                 FileSystem.TryDeleteFile(this.installerPath);
             }
         }
         finally
         {
             this.finishing = false;
         }
     }
 }
Beispiel #5
0
        private void OnLanguageChanged(object sender, ValueChangedEventArgs <CultureInfo> e)
        {
            List <TupleStruct <string, string> > list = new List <TupleStruct <string, string> >();
            object sync = this.Sync;

            lock (sync)
            {
                string b = this.TryGetUserFilesPath();
                if ((this.currentUserFilesPath != null) && (b != null))
                {
                    if (!string.Equals(this.currentUserFilesPath, b, StringComparison.InvariantCultureIgnoreCase))
                    {
                        list.Add(TupleStruct.Create <string, string>(this.currentUserFilesPath, b));
                        this.currentUserFilesPath = b;
                    }
                    foreach (string str2 in this.resNameToSubDirNameMap.Keys.ToArrayEx <string>())
                    {
                        string a    = this.resNameToSubDirNameMap[str2];
                        string str4 = PdnResources.GetString(str2);
                        if (!string.Equals(a, str4, StringComparison.InvariantCultureIgnoreCase))
                        {
                            string str5 = Path.Combine(b, a);
                            string str6 = Path.Combine(b, str4);
                            this.resNameToSubDirNameMap[str2] = str4;
                            list.Add(TupleStruct.Create <string, string>(str5, str6));
                        }
                    }
                }
            }
            foreach (TupleStruct <string, string> struct2 in list)
            {
                string path = struct2.Item1;
                string str8 = struct2.Item2;
                try
                {
                    if (Directory.Exists(path) && !Directory.Exists(str8))
                    {
                        Directory.Move(path, str8);
                    }
                }
                catch (Exception exception)
                {
                    ExceptionDialog.ShowErrorDialog(null, exception);
                }
            }
        }
Beispiel #6
0
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            string email    = "*****@*****.**";
            string subject  = string.Format(PdnResources.GetString("SendFeedback.Email.Subject.Format"), PdnInfo.FullAppName);
            string body     = PdnResources.GetString("SendFeedback.Email.Body");
            string fileName = this.GetEmailLaunchString(email, subject, body);

            fileName = fileName.Substring(0, Math.Min(0x400, fileName.Length));
            try
            {
                Process.Start(fileName);
            }
            catch (Exception exception)
            {
                ExceptionDialog.ShowErrorDialog(appWorkspace, PdnResources.GetString("SendFeedbackAction.Error"), exception);
            }
        }
Beispiel #7
0
 public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
 {
     if (!ScanningAndPrinting.CanPrint)
     {
         ShowWiaError(documentWorkspace);
         return(null);
     }
     using (new PushNullToolMode(documentWorkspace))
     {
         Surface surface = documentWorkspace.BorrowScratchSurface(base.GetType().Name + ".PerformAction()");
         try
         {
             surface.Clear();
             RenderArgs args = new RenderArgs(surface);
             documentWorkspace.QueueUpdate();
             using (new WaitCursorChanger(documentWorkspace))
             {
                 args.Surface.Clear(ColorBgra.White);
                 documentWorkspace.Document.Render(args, false);
             }
             string filename = Path.GetTempFileName() + ".bmp";
             args.Bitmap.Save(filename, ImageFormat.Bmp);
             try
             {
                 ScanningAndPrinting.Print(documentWorkspace, filename);
             }
             catch (Exception)
             {
                 ShowWiaError(documentWorkspace);
             }
             bool flag = FileSystem.TryDeleteFile(filename);
         }
         catch (Exception exception)
         {
             ExceptionDialog.ShowErrorDialog(documentWorkspace, exception);
         }
         finally
         {
             documentWorkspace.ReturnScratchSurface(surface);
         }
     }
     return(null);
 }
Beispiel #8
0
        private TransactedToolUndoCommitHistoryMemento <TDerived, TChanges> TryCommitChanges()
        {
            ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >();
            this.VerifyState(TransactedToolState.Dirty);
            OperationCanceledException exception = null;
            TransactedToolUndoCommitHistoryMemento <TDerived, TChanges> memento = null;
            TChanges changes = this.Changes.Clone();

            try
            {
                this.drawingSettingValuesBackup = null;
                HistoryMemento innerCommitHM = this.CommitChangesInner(changes);
                if (innerCommitHM == null)
                {
                    throw new InternalErrorException($"CommitChangesInner() returned null (Tool={base.GetType().Name})");
                }
                memento = new TransactedToolUndoCommitHistoryMemento <TDerived, TChanges>(base.DocumentWorkspace, changes, innerCommitHM);
            }
            catch (OperationCanceledException exception2)
            {
                exception = exception2;
            }
            if (exception != null)
            {
                this.VerifyState(TransactedToolState.Dirty);
                ExceptionDialog.ShowErrorDialog(base.DocumentWorkspace, exception.InnerException ?? exception);
                return(null);
            }
            this.VerifyState(TransactedToolState.Idle);
            if (this.changes != null)
            {
                throw new InternalErrorException($"this.Changes is not null (Tool={base.GetType().Name})");
            }
            if (this.changesBeforeEditing != null)
            {
                throw new InternalErrorException($"this.changesBeforeEditing is not null (Tool={base.GetType().Name})");
            }
            return(memento);
        }
        private void EndCreateSelectionOnUIThread(Result <GeometryList> result)
        {
            ((AsyncSelectionToolBase <TDerived, TChanges>) this).VerifyAccess <AsyncSelectionToolBase <TDerived, TChanges> >();
            this.isCreatingSelection    = false;
            this.createSelectionChanges = default(TChanges);
            DisposableUtil.Free <AsyncSelectionToolCreateGeometryContext>(ref this.createSelectionContext);
            DisposableUtil.Free <ManualResetEvent>(ref this.endCreateSelectionEvent);
            this.endCreateSelectionCallback = null;
            if (!base.IsCommitting && ((this.State == TransactedToolState.Inactive) || !base.Active))
            {
                if (result.NeedsObservation)
                {
                    result.Observe();
                }
                return;
            }
            if (result.IsError && (result.Error is OperationCanceledException))
            {
                this.createSelectionCancellationToken.Cancel();
            }
            bool isCancellationRequested = this.createSelectionCancellationToken.IsCancellationRequested;

            DisposableUtil.Free <CancellationTokenSource>(ref this.createSelectionCancellationToken);
            if (this.needToRecreateSelection)
            {
                this.needToRecreateSelection = false;
                this.InvalidateSelection();
            }
            else if (isCancellationRequested)
            {
                base.DocumentWorkspace.AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(new double?((double)100));
                base.DocumentWorkspace.AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
            }
            else
            {
                if (result.IsError)
                {
                    base.DocumentWorkspace.AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(new double?((double)100));
                    base.DocumentWorkspace.AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
                    ExceptionDialog.ShowErrorDialog(base.DocumentWorkspace, result.Error);
                    using (new PresentationBasedTool <TDerived, TChanges> .AllowSelectionChangesScope((TDerived)this))
                    {
                        using (base.Selection.UseChangeScope())
                        {
                            base.Selection.Reset();
                            goto Label_0222;
                        }
                    }
                }
                GeometryList geometry = result.Value;
                using (new PresentationBasedTool <TDerived, TChanges> .AllowSelectionChangesScope((TDerived)this))
                {
                    using (base.Selection.UseChangeScope())
                    {
                        base.Selection.SetContinuation(geometry, SelectionCombineMode.Replace);
                        base.Selection.CommitContinuation();
                    }
                }
                base.DocumentWorkspace.AppWorkspace.Widgets.StatusBarProgress.SetProgressStatusBar(new double?((double)100));
                base.DocumentWorkspace.AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
            }
Label_0222:
            base.InvalidateStatus();
        }
Beispiel #10
0
        private static Document ResizeDocument(DocumentWorkspace documentWorkspace, AnchorEdge initialAnchor, ColorBgra background, bool loadAndSaveMaintainAspect, bool saveAnchor)
        {
            Document document2;

            CleanupManager.RequestCleanup();
            IWin32Window owner    = documentWorkspace;
            Document     document = documentWorkspace.Document;
            Size         size     = document.Size;

            using (CanvasSizeDialog dialog = new CanvasSizeDialog())
            {
                bool flag;
                if (loadAndSaveMaintainAspect)
                {
                    flag = AppSettings.Instance.Workspace.LastMaintainAspectRatioCS.Value;
                }
                else
                {
                    flag = false;
                }
                dialog.OriginalSize      = document.Size;
                dialog.OriginalDpuUnit   = document.DpuUnit;
                dialog.OriginalDpu       = document.DpuX;
                dialog.ImageWidth        = size.Width;
                dialog.ImageHeight       = size.Height;
                dialog.LayerCount        = document.Layers.Count;
                dialog.AnchorEdge        = initialAnchor;
                dialog.Units             = dialog.OriginalDpuUnit;
                dialog.Resolution        = document.DpuX;
                dialog.Units             = AppSettings.Instance.Workspace.LastNonPixelUnits.Value;
                dialog.ConstrainToAspect = flag;
                DialogResult    result     = dialog.ShowDialog(owner);
                Size            newSize    = new Size(dialog.ImageWidth, dialog.ImageHeight);
                MeasurementUnit units      = dialog.Units;
                double          resolution = dialog.Resolution;
                if (result == DialogResult.Cancel)
                {
                    return(null);
                }
                if (loadAndSaveMaintainAspect)
                {
                    AppSettings.Instance.Workspace.LastMaintainAspectRatioCS.Value = dialog.ConstrainToAspect;
                }
                if (saveAnchor)
                {
                    AppSettings.Instance.Workspace.LastCanvasSizeAnchorEdge.Value = dialog.AnchorEdge;
                }
                if (((newSize == document.Size) && (units == document.DpuUnit)) && (resolution == document.DpuX))
                {
                    document2 = null;
                }
                else
                {
                    try
                    {
                        documentWorkspace.FlushTool();
                        CleanupManager.RequestCleanup();
                        Document document3 = ResizeDocument(document, newSize, dialog.AnchorEdge, background);
                        document3.DpuUnit = units;
                        document3.DpuX    = resolution;
                        document3.DpuY    = resolution;
                        document2         = document3;
                    }
                    catch (OutOfMemoryException exception)
                    {
                        ExceptionDialog.ShowErrorDialog(owner, PdnResources.GetString("CanvasSizeAction.ResizeDocument.OutOfMemory"), exception.ToString());
                        document2 = null;
                    }
                    catch (Exception)
                    {
                        document2 = null;
                    }
                }
            }
            return(document2);
        }
        public static HistoryFunctionResult ApplyFunction(this DocumentWorkspace dw, HistoryFunction function)
        {
            HistoryFunctionResult successNoOp;
            bool flag = false;

            if ((function.ActionFlags & ActionFlags.KeepToolActive) != ActionFlags.KeepToolActive)
            {
                dw.PushNullTool();
                dw.Update();
                flag = true;
            }
            try
            {
                using (new WaitCursorChanger(dw))
                {
                    string         localizedErrorText;
                    HistoryMemento memento   = null;
                    Exception      exception = null;
                    try
                    {
                        memento = function.Execute(dw);
                        if (memento == null)
                        {
                            successNoOp = HistoryFunctionResult.SuccessNoOp;
                        }
                        else
                        {
                            successNoOp = HistoryFunctionResult.Success;
                        }
                        localizedErrorText = null;
                    }
                    catch (HistoryFunctionNonFatalException exception2)
                    {
                        exception = exception2;
                        if (exception2.InnerException is OutOfMemoryException)
                        {
                            successNoOp = HistoryFunctionResult.OutOfMemory;
                        }
                        else
                        {
                            successNoOp = HistoryFunctionResult.NonFatalError;
                        }
                        if (exception2.LocalizedErrorText != null)
                        {
                            localizedErrorText = exception2.LocalizedErrorText;
                        }
                        else if (exception2.InnerException is OutOfMemoryException)
                        {
                            localizedErrorText = PdnResources.GetString("ExecuteFunction.GenericOutOfMemory");
                        }
                        else
                        {
                            localizedErrorText = PdnResources.GetString("ExecuteFunction.GenericError");
                        }
                    }
                    if ((localizedErrorText != null) && (exception != null))
                    {
                        ExceptionDialog.ShowErrorDialog(dw, localizedErrorText, exception);
                    }
                    else if ((localizedErrorText != null) && (exception == null))
                    {
                        MessageBoxUtil.ErrorBox(dw, localizedErrorText);
                    }
                    if (memento != null)
                    {
                        dw.History.PushNewMemento(memento);
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    dw.PopNullTool();
                }
            }
            return(successNoOp);
        }
 public void ShowErrorDialog(IWin32Window owner, Exception exception)
 {
     ExceptionDialog.ShowErrorDialog(owner, exception);
 }
 public void ShowErrorDialog(IWin32Window owner, [Optional] string message, string exceptionText)
 {
     ExceptionDialog.ShowErrorDialog(owner, message, exceptionText);
 }
Beispiel #14
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)
         {
         }
     }
 }
Beispiel #15
0
 public override void PerformAction(AppWorkspace appWorkspace)
 {
     if (appWorkspace.CanSetActiveWorkspace)
     {
         if (!ScanningAndPrinting.CanScan)
         {
             ShowWiaError(appWorkspace);
         }
         else
         {
             ScanResult userCancelled;
             string     fileName = Path.ChangeExtension(FileSystem.GetTempFileName(), ".bmp");
             try
             {
                 userCancelled = ScanningAndPrinting.Scan(appWorkspace, fileName);
             }
             catch (Exception)
             {
                 userCancelled = ScanResult.UserCancelled;
             }
             if (userCancelled == ScanResult.Success)
             {
                 string str2 = null;
                 try
                 {
                     Image    image;
                     Document document;
                     try
                     {
                         using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                         {
                             image = Image.FromStream(stream, false, true);
                         }
                     }
                     catch (FileNotFoundException)
                     {
                         str2 = PdnResources.GetString("LoadImage.Error.FileNotFoundException");
                         throw;
                     }
                     catch (OutOfMemoryException)
                     {
                         str2 = PdnResources.GetString("LoadImage.Error.OutOfMemoryException");
                         throw;
                     }
                     catch (Exception)
                     {
                         str2 = string.Empty;
                         throw;
                     }
                     try
                     {
                         document = Document.FromGdipImage(image, false);
                     }
                     catch (OutOfMemoryException)
                     {
                         str2 = PdnResources.GetString("LoadImage.Error.OutOfMemoryException");
                         throw;
                     }
                     catch (Exception)
                     {
                         str2 = string.Empty;
                         throw;
                     }
                     finally
                     {
                         image.Dispose();
                         image = null;
                     }
                     DocumentWorkspace workspace = appWorkspace.AddNewDocumentWorkspace();
                     try
                     {
                         workspace.Document = document;
                     }
                     catch (OutOfMemoryException)
                     {
                         str2 = PdnResources.GetString("LoadImage.Error.OutOfMemoryException");
                         throw;
                     }
                     document = null;
                     workspace.SetDocumentSaveOptions(null, null, null);
                     workspace.History.ClearAll();
                     HistoryMemento memento = new NullHistoryMemento(PdnResources.GetString("AcquireImageAction.Name"), PdnResources.GetImageResource("Icons.MenuLayersAddNewLayerIcon.png"));
                     workspace.History.PushNewMemento(memento);
                     appWorkspace.ActiveDocumentWorkspace = workspace;
                     try
                     {
                         File.Delete(fileName);
                     }
                     catch (Exception)
                     {
                     }
                 }
                 catch (Exception exception)
                 {
                     if (str2 == null)
                     {
                         throw;
                     }
                     if (string.IsNullOrEmpty(str2))
                     {
                         ExceptionDialog.ShowErrorDialog(appWorkspace, exception);
                     }
                     else
                     {
                         ExceptionDialog.ShowErrorDialog(appWorkspace, str2, exception);
                     }
                 }
             }
         }
     }
 }
Beispiel #16
0
        private bool PerformActionImpl()
        {
            PointInt32 num2;
            RectInt32  num3;

            if (this.clipData == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        CleanupManager.RequestCleanup();
                        this.clipData = PdnClipboard.GetDataObject();
                    }
                }
                catch (OutOfMemoryException exception)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception);
                    return(false);
                }
                catch (Exception exception2)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2);
                    return(false);
                }
            }
            bool handled = false;

            if (this.documentWorkspace.Tool != null)
            {
                this.documentWorkspace.Tool.PerformPaste(this.clipData, out handled);
            }
            if (handled)
            {
                return(true);
            }
            if (this.maskedSurface == null)
            {
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        this.maskedSurface = ClipboardUtil.GetClipboardImage(this.documentWorkspace, this.clipData);
                    }
                }
                catch (OutOfMemoryException exception3)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception3);
                    return(false);
                }
                catch (Exception exception4)
                {
                    ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception4);
                    return(false);
                }
            }
            if (this.maskedSurface == null)
            {
                MessageBoxUtil.ErrorBox(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.NoImage"));
                return(false);
            }
            RectInt32 cachedGeometryMaskScansBounds = this.maskedSurface.GetCachedGeometryMaskScansBounds();

            if ((cachedGeometryMaskScansBounds.Width > this.documentWorkspace.Document.Width) || (cachedGeometryMaskScansBounds.Height > this.documentWorkspace.Document.Height))
            {
                Surface surface;
                try
                {
                    using (new WaitCursorChanger(this.documentWorkspace))
                    {
                        surface = CreateThumbnail(this.maskedSurface);
                    }
                }
                catch (OutOfMemoryException)
                {
                    surface = null;
                }
                DialogResult result           = ShowExpandCanvasTaskDialog(this.documentWorkspace, surface);
                int          activeLayerIndex = this.documentWorkspace.ActiveLayerIndex;
                ColorBgra    background       = this.documentWorkspace.ToolSettings.SecondaryColor.Value;
                if (result != DialogResult.Cancel)
                {
                    if (result != DialogResult.Yes)
                    {
                        if (result != DialogResult.No)
                        {
                            throw ExceptionUtil.InvalidEnumArgumentException <DialogResult>(result, "dr");
                        }
                        goto Label_031D;
                    }
                    using (new PushNullToolMode(this.documentWorkspace))
                    {
                        int      width    = Math.Max(cachedGeometryMaskScansBounds.Width, this.documentWorkspace.Document.Width);
                        Size     newSize  = new Size(width, Math.Max(cachedGeometryMaskScansBounds.Height, this.documentWorkspace.Document.Height));
                        Document document = CanvasSizeAction.ResizeDocument(this.documentWorkspace.Document, newSize, AnchorEdge.TopLeft, background);
                        if (document == null)
                        {
                            return(false);
                        }
                        SelectionHistoryMemento       memento  = new SelectionHistoryMemento(null, null, this.documentWorkspace);
                        ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, this.documentWorkspace);
                        this.documentWorkspace.Document = document;
                        HistoryMemento[]       actions  = new HistoryMemento[] { memento, memento2 };
                        CompoundHistoryMemento memento3 = new CompoundHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, actions);
                        this.documentWorkspace.History.PushNewMemento(memento3);
                        this.documentWorkspace.ActiveLayer = (Layer)this.documentWorkspace.Document.Layers[activeLayerIndex];
                        goto Label_031D;
                    }
                }
                return(false);
            }
Label_031D:
            num3 = this.documentWorkspace.Document.Bounds();
            RectDouble visibleDocumentRect = this.documentWorkspace.VisibleDocumentRect;
            RectInt32? nullable            = visibleDocumentRect.Int32Inset();
            RectDouble num5 = nullable.HasValue ? ((RectDouble)nullable.Value) : visibleDocumentRect;
            RectInt32  num6 = num5.Int32Bound;

            if (num5.Contains(cachedGeometryMaskScansBounds))
            {
                num2 = new PointInt32(0, 0);
            }
            else
            {
                int num12;
                int num13;
                int num16;
                int num17;
                if (cachedGeometryMaskScansBounds.X < num5.Left)
                {
                    num12 = -cachedGeometryMaskScansBounds.X + num6.X;
                }
                else if (cachedGeometryMaskScansBounds.Right > num6.Right)
                {
                    num12 = (-cachedGeometryMaskScansBounds.X + num6.Right) - cachedGeometryMaskScansBounds.Width;
                }
                else
                {
                    num12 = 0;
                }
                if (cachedGeometryMaskScansBounds.Y < num5.Top)
                {
                    num13 = -cachedGeometryMaskScansBounds.Y + num6.Y;
                }
                else if (cachedGeometryMaskScansBounds.Bottom > num6.Bottom)
                {
                    num13 = (-cachedGeometryMaskScansBounds.Y + num6.Bottom) - cachedGeometryMaskScansBounds.Height;
                }
                else
                {
                    num13 = 0;
                }
                PointInt32 num14 = new PointInt32(num12, num13);
                RectInt32  num15 = new RectInt32(cachedGeometryMaskScansBounds.X + num14.X, cachedGeometryMaskScansBounds.Y + num14.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num15.X < 0)
                {
                    num16 = num12 - num15.X;
                }
                else
                {
                    num16 = num12;
                }
                if (num15.Y < 0)
                {
                    num17 = num13 - num15.Y;
                }
                else
                {
                    num17 = num13;
                }
                PointInt32 num18 = new PointInt32(num16, num17);
                RectInt32  rect  = new RectInt32(cachedGeometryMaskScansBounds.X + num18.X, cachedGeometryMaskScansBounds.Y + num18.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
                if (num3.Contains(rect))
                {
                    num2 = num18;
                }
                else
                {
                    PointInt32 num20 = num18;
                    if (rect.Right > num3.Right)
                    {
                        int num21 = rect.Right - num3.Right;
                        int num22 = Math.Min(num21, rect.Left);
                        num20.X -= num22;
                    }
                    if (rect.Bottom > num3.Bottom)
                    {
                        int num23 = rect.Bottom - num3.Bottom;
                        int num24 = Math.Min(num23, rect.Top);
                        num20.Y -= num24;
                    }
                    num2 = num20;
                }
            }
            RectInt32 b           = this.documentWorkspace.VisibleDocumentRect.Int32Bound;
            RectInt32 a           = new RectInt32(cachedGeometryMaskScansBounds.X + num2.X, cachedGeometryMaskScansBounds.Y + num2.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height);
            bool      hasZeroArea = RectInt32.Intersect(a, b).HasZeroArea;

            MoveTool.BeginPaste(this.documentWorkspace, PdnResources.GetString("CommonAction.Paste"), PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png"), this.maskedSurface.SurfaceReadOnly, this.maskedSurface.GeometryMask, num2);
            if (hasZeroArea)
            {
                PointInt32  num25 = new PointInt32(b.Left + (b.Width / 2), b.Top + (b.Height / 2));
                PointInt32  num26 = new PointInt32(a.Left + (a.Width / 2), a.Top + (a.Height / 2));
                SizeInt32   num27 = new SizeInt32(num26.X - num25.X, num26.Y - num25.Y);
                PointDouble documentScrollPosition = this.documentWorkspace.DocumentScrollPosition;
                PointDouble num29 = new PointDouble(documentScrollPosition.X + num27.Width, documentScrollPosition.Y + num27.Height);
                this.documentWorkspace.DocumentScrollPosition = num29;
            }
            return(true);
        }
        public bool PerformAction()
        {
            bool flag = true;

            if (!this.QueryCanPerformAction())
            {
                return(false);
            }
            try
            {
                using (new WaitCursorChanger(this.documentWorkspace))
                {
                    IRenderer <ColorBgra>   source             = this.GetSource();
                    RectInt32               num                = source.Bounds <ColorBgra>();
                    GeometryList            cachedClippingMask = this.documentWorkspace.Selection.GetCachedClippingMask();
                    RectInt32               a = cachedClippingMask.Bounds.Int32Bound;
                    IRenderer <ColorAlpha8> cachedClippingMaskRenderer = this.documentWorkspace.Selection.GetCachedClippingMaskRenderer(this.documentWorkspace.ToolSettings.Selection.RenderingQuality.Value);
                    RectInt32               sourceRect = RectInt32.Intersect(a, source.Bounds <ColorBgra>());
                    IRenderer <ColorBgra>   renderer3  = new ClippedRenderer <ColorBgra>(source, sourceRect);
                    IRenderer <ColorAlpha8> alpha      = new ClippedRenderer <ColorAlpha8>(cachedClippingMaskRenderer, sourceRect);
                    IRenderer <ColorBgra>   sourceRHS  = new MultiplyAlphaChannelRendererBgra32(renderer3, alpha);
                    IRenderer <ColorBgra>   sourceLHS  = new SolidColorRendererBgra(sourceRHS.Width, sourceRHS.Height, ColorBgra.White);
                    IRenderer <ColorBgra>   renderer   = new BlendRendererBgra(sourceLHS, CompositionOps.Normal.Static, sourceRHS);
                    if ((a.Width > 0) && (a.Height > 0))
                    {
                        int num5 = 10;
                        while (num5 >= 0)
                        {
                            try
                            {
                                try
                                {
                                    using (Clipboard.Transaction transaction = Clipboard.Open(this.documentWorkspace))
                                    {
                                        transaction.Empty();
                                        using (MaskedSurface surface = MaskedSurface.CopyFrom(source, cachedClippingMask))
                                        {
                                            transaction.AddManagedData(surface);
                                            using (Surface surface2 = surface.Surface.CreateWindow(new Rectangle(0, 0, a.Width, a.Height)))
                                            {
                                                sourceRHS.Parallelize <ColorBgra>(TilingStrategy.Tiles, 7, WorkItemQueuePriority.Normal).Render <ColorBgra>(surface2);
                                                using (Bitmap copyBitmap = surface2.CreateAliasedBitmap(true))
                                                {
                                                    transaction.AddRawNativeData("PNG", delegate(Stream dstStream) {
                                                        copyBitmap.Save(dstStream, ImageFormat.Png);
                                                    });
                                                }
                                                renderer.Parallelize <ColorBgra>(TilingStrategy.Tiles, 7, WorkItemQueuePriority.Normal).Render <ColorBgra>(surface2);
                                                using (Bitmap bitmap = surface2.CreateAliasedBitmap(false))
                                                {
                                                    transaction.AddDibV5(bitmap);
                                                }
                                            }
                                            goto Label_0292;
                                        }
                                    }
                                }
                                catch (Exception exception)
                                {
                                    if (num5 == 0)
                                    {
                                        flag = false;
                                        ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.TransferToClipboard"), exception.ToString());
                                    }
                                    else
                                    {
                                        CleanupManager.RequestCleanup();
                                        CleanupManager.WaitForPendingCleanup(50);
                                        Thread.Sleep(50);
                                    }
                                }
                                continue;
                            }
                            finally
                            {
                                num5--;
                            }
                        }
                    }
                }
            }
            catch (OutOfMemoryException exception2)
            {
                flag = false;
                ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.OutOfMemory"), exception2.ToString());
            }
            catch (Exception exception3)
            {
                flag = false;
                ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.Generic"), exception3.ToString());
            }
Label_0292:
            CleanupManager.RequestCleanup();
            return(flag);
        }