Example #1
0
        private void OnLanguageChangedFromSettingsDialog(CultureInfo oldLanguage)
        {
            CultureInfo parent    = AppSettings.Instance.UI.Language.Value;
            Icon        icon      = PdnResources.GetImageResource("Icons.MenuUtilitiesLanguageIcon.png").Reference.ToIcon();
            string      str       = PdnResources.GetString("ConfirmLanguageDialog.Title");
            Image       image     = null;
            string      str2      = PdnResources.GetString("ConfirmLanguageDialog.IntroText");
            Image       reference = PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference;
            string      format    = PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ExplanationText.Format");
            CultureInfo info2     = new CultureInfo("en-US");

            if (parent.Equals(info2))
            {
                parent = parent.Parent;
            }
            string     nativeName      = parent.NativeName;
            string     explanationText = string.Format(format, nativeName);
            TaskButton button          = new TaskButton(reference, PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ActionText"), explanationText);
            TaskButton button2         = new TaskButton(PdnResources.GetImageResource("Icons.CancelIcon.png").Reference, PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ActionText"), PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ExplanationText"));
            int        num             = (TaskDialog.DefaultPixelWidth96Dpi * 5) / 4;
            TaskDialog dialog2         = new TaskDialog {
                Icon                  = icon,
                Title                 = str,
                TaskImage             = image,
                ScaleTaskImageWithDpi = true,
                IntroText             = str2
            };

            dialog2.TaskButtons     = new TaskButton[] { button, button2 };
            dialog2.AcceptButton    = button;
            dialog2.CancelButton    = button2;
            dialog2.PixelWidth96Dpi = num;
            TaskDialog dialog = dialog2;

            if (dialog.Show(this.AppWorkspace) == button)
            {
                if (ShellUtil.IsActivityQueuedForRestart)
                {
                    MessageBoxUtil.ErrorBox(this.AppWorkspace, PdnResources.GetString("Effect.PluginErrorDialog.CantQueue2ndRestart"));
                }
                else
                {
                    CloseAllWorkspacesAction action = new CloseAllWorkspacesAction();
                    action.PerformAction(this.AppWorkspace);
                    if (!action.Cancelled)
                    {
                        ShellUtil.RestartApplication();
                        Startup.CloseApplication();
                    }
                }
            }
            else
            {
                AppSettings.Instance.UI.Language.Value = oldLanguage;
            }
        }
Example #2
0
 public static void ShowWiaError(IWin32Window owner)
 {
     if (OS.OSType == OSType.Server)
     {
         MessageBoxUtil.ErrorBox(owner, PdnResources.GetString("WIA.Error.EnableMe"));
     }
     else
     {
         MessageBoxUtil.ErrorBox(owner, PdnResources.GetString("WIA.Error.UnableToLoad"));
     }
 }
Example #3
0
        protected override void OnUIDragEnd(object sender, PaintDotNet.UI.Input.MouseEventArgs e)
        {
            if (this.isHandlingDrag)
            {
                if (e.Source is UIElement)
                {
                    PointDouble mouseCenterPt = BrushToolBase <CloneStampTool, CloneStampToolChanges, CloneStampToolUI> .GetMouseCenterPt(e.GetPosition(base.UI), base.CanvasView.CanvasHairWidth);

                    if (this.GetStaticData().anchorOffsetMode == AnchorOffsetMode.Absolute)
                    {
                        this.GetStaticData().anchorOffset = (VectorDouble)mouseCenterPt;
                        this.UpdateAnchor();
                    }
                    else if (this.GetStaticData().anchorOffsetMode == AnchorOffsetMode.NotSet)
                    {
                        string message = PdnResources.GetString("CloneStampTool.Error.TriedToDrawWithoutAnchor.Text");
                        MessageBoxUtil.ErrorBox(base.DocumentWorkspace, message);
                    }
                }
                e.Handled           = true;
                this.isHandlingDrag = false;
            }
            base.OnUIDragEnd(sender, e);
        }
Example #4
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);
        }
Example #5
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 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);
        }