Beispiel #1
0
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            using (NewFileDialog nfd = new NewFileDialog())
            {
                Size newDocSize = appWorkspace.GetNewDocumentSize();

                if (Utility.IsClipboardImageAvailable())
                {
                    try
                    {
                        Utility.GCFullCollect();
                        IDataObject clipData = System.Windows.Forms.Clipboard.GetDataObject();

                        using (Image clipImage = (Image)clipData.GetData(DataFormats.Bitmap))
                        {
                            int width2  = clipImage.Width;
                            int height2 = clipImage.Height;
                            newDocSize = new Size(width2, height2);
                        }
                    }

                    catch (Exception ex)
                    {
                        if (ex is OutOfMemoryException ||
                            ex is ExternalException ||
                            ex is NullReferenceException)
                        {
                            // ignore
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                nfd.OriginalSize      = new Size(newDocSize.Width, newDocSize.Height);
                nfd.ConstrainToAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatioNF, false);

                DialogResult dr = nfd.ShowDialog(appWorkspace);

                if (dr == DialogResult.OK)
                {
                    bool success = appWorkspace.CreateBlankDocumentInNewWorkspace(new Size(nfd.ImageWidth, nfd.ImageHeight), false);

                    if (success)
                    {
                        appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
                        Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatioNF, nfd.ConstrainToAspect);
                    }
                }
            }
        }
Beispiel #2
0
 public override void PerformAction(AppWorkspace appWorkspace)
 {
     if (appWorkspace.CanSetActiveWorkspace)
     {
         using (NewFileDialog dialog = new NewFileDialog())
         {
             SizeInt32?clipboardImageSize;
             SizeInt32 newDocumentSize = appWorkspace.GetNewDocumentSize();
             using (new WaitCursorChanger(appWorkspace))
             {
                 CleanupManager.RequestCleanup();
                 try
                 {
                     IPdnDataObject dataObject = PdnClipboard.GetDataObject();
                     clipboardImageSize = ClipboardUtil.GetClipboardImageSize(appWorkspace, dataObject);
                     dataObject         = null;
                 }
                 catch (Exception)
                 {
                     clipboardImageSize = null;
                 }
                 CleanupManager.RequestCleanup();
             }
             if (clipboardImageSize.HasValue)
             {
                 newDocumentSize = clipboardImageSize.Value;
             }
             dialog.OriginalSize      = new Size(newDocumentSize.Width, newDocumentSize.Height);
             dialog.OriginalDpuUnit   = AppSettings.Instance.Workspace.LastNonPixelUnits.Value;
             dialog.OriginalDpu       = Document.GetDefaultDpu(dialog.OriginalDpuUnit);
             dialog.Units             = dialog.OriginalDpuUnit;
             dialog.Resolution        = dialog.OriginalDpu;
             dialog.ConstrainToAspect = AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value;
             if ((((dialog.ShowDialog(appWorkspace) == DialogResult.OK) && (dialog.ImageWidth > 0)) && ((dialog.ImageHeight > 0) && dialog.Resolution.IsFinite())) && (dialog.Resolution > 0.0))
             {
                 SizeInt32 size = new SizeInt32(dialog.ImageWidth, dialog.ImageHeight);
                 if (appWorkspace.CreateBlankDocumentInNewWorkspace(size, dialog.Units, dialog.Resolution, false))
                 {
                     appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
                     AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value = dialog.ConstrainToAspect;
                     if (dialog.Units != MeasurementUnit.Pixel)
                     {
                         AppSettings.Instance.Workspace.LastNonPixelUnits.Value = dialog.Units;
                     }
                     if (appWorkspace.Units != MeasurementUnit.Pixel)
                     {
                         appWorkspace.Units = dialog.Units;
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            using (NewFileDialog nfd = new NewFileDialog())
            {
                Size newDocSize = appWorkspace.GetNewDocumentSize();

                if (Utility.IsClipboardImageAvailable())
                {
                    try
                    {
                        Utility.GCFullCollect();
                        IDataObject clipData = System.Windows.Forms.Clipboard.GetDataObject();

                        using (Image clipImage = (Image)clipData.GetData(DataFormats.Bitmap))
                        {
                            int width2 = clipImage.Width;
                            int height2 = clipImage.Height;
                            newDocSize = new Size(width2, height2);
                        }
                    }

                    catch (Exception ex)
                    {
                        if (ex is OutOfMemoryException ||
                            ex is ExternalException ||
                            ex is NullReferenceException)
                        {
                            // ignore
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                nfd.OriginalSize = new Size(newDocSize.Width, newDocSize.Height);
                nfd.OriginalDpuUnit = SettingNames.GetLastNonPixelUnits();
                nfd.OriginalDpu = Document.GetDefaultDpu(nfd.OriginalDpuUnit);
                nfd.Units = nfd.OriginalDpuUnit;
                nfd.Resolution = nfd.OriginalDpu;
                nfd.ConstrainToAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatioNF, false);

                DialogResult dr = nfd.ShowDialog(appWorkspace);

                if (dr == DialogResult.OK)
                {
                    bool success = appWorkspace.CreateBlankDocumentInNewWorkspace(new Size(nfd.ImageWidth, nfd.ImageHeight), nfd.Units, nfd.Resolution, false);

                    if (success)
                    {
                        appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
                        Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatioNF, nfd.ConstrainToAspect);

                        if (nfd.Units != MeasurementUnit.Pixel)
                        {
                            Settings.CurrentUser.SetString(SettingNames.LastNonPixelUnits, nfd.Units.ToString());
                        }

                        if (appWorkspace.Units != MeasurementUnit.Pixel)
                        {
                            appWorkspace.Units = nfd.Units;
                        }
                    }
                }
            }
        }