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) { } } }
protected override void OnDropDownOpening(EventArgs e) { bool flag; bool flag2; bool flag3; IPdnDataObject dataObject; if (base.AppWorkspace.ActiveDocumentWorkspace == null) { flag = false; flag2 = false; this.menuEditSelectAll.Enabled = false; } else { flag = !base.AppWorkspace.ActiveDocumentWorkspace.Selection.IsEmpty; flag2 = base.AppWorkspace.ActiveDocumentWorkspace.ActiveLayer is BitmapLayer; this.menuEditSelectAll.Enabled = true; } this.menuEditCopy.Enabled = flag; this.menuEditCopyMerged.Enabled = flag; this.menuEditCut.Enabled = flag & flag2; this.menuEditEraseSelection.Enabled = flag; this.menuEditFillSelection.Enabled = flag; this.menuEditInvertSelection.Enabled = flag; this.menuEditDeselect.Enabled = flag; try { dataObject = PdnClipboard.GetDataObject(); flag3 = ClipboardUtil.IsClipboardImageMaybeAvailable(base.AppWorkspace, dataObject); } catch (Exception) { flag3 = false; dataObject = null; } this.menuEditPaste.Enabled = flag3 && (base.AppWorkspace.ActiveDocumentWorkspace > null); if ((!this.menuEditPaste.Enabled && (dataObject != null)) && ((base.AppWorkspace.ActiveDocumentWorkspace != null) && (base.AppWorkspace.ActiveDocumentWorkspace.Tool != null))) { bool flag4; try { base.AppWorkspace.ActiveDocumentWorkspace.Tool.PerformPasteQuery(dataObject, out flag4); } catch (ExternalException) { flag4 = false; } if (flag4) { this.menuEditPaste.Enabled = true; } } this.menuEditPasteInToNewLayer.Enabled = flag3 && (base.AppWorkspace.ActiveDocumentWorkspace > null); this.menuEditPasteInToNewImage.Enabled = flag3; if (base.AppWorkspace.ActiveDocumentWorkspace != null) { this.menuEditUndo.Enabled = base.AppWorkspace.ActiveDocumentWorkspace.History.UndoStack.Count > 1; this.menuEditRedo.Enabled = base.AppWorkspace.ActiveDocumentWorkspace.History.RedoStack.Count > 0; } else { this.menuEditUndo.Enabled = false; this.menuEditRedo.Enabled = false; } base.OnDropDownOpening(e); }