private CutBuffer.ProjectCopyInformation GetCopyInformation() { CutBuffer.ProjectCopyInformation projectCopyInformation = null; SafeDataObject safeDataObject = SafeDataObject.FromClipboard(); if (safeDataObject != null) { if (safeDataObject.GetDataPresent(typeof(CutBuffer.ProjectCopyInformation))) { CutBuffer.ProjectCopyInformation data = safeDataObject.GetData(typeof(CutBuffer.ProjectCopyInformation)) as CutBuffer.ProjectCopyInformation; if (data != null) { projectCopyInformation = new CutBuffer.ProjectCopyInformation(data); } } if (projectCopyInformation == null && safeDataObject.GetDataPresent(DataFormats.FileDrop)) { string[] strArrays = safeDataObject.GetData(DataFormats.FileDrop) as string[]; if (strArrays != null) { projectCopyInformation = new CutBuffer.ProjectCopyInformation(false, null, strArrays); } } if (projectCopyInformation == null && safeDataObject.GetDataPresent(typeof(string[]))) { string[] data1 = safeDataObject.GetData(typeof(string[])) as string[]; if (data1 != null) { projectCopyInformation = new CutBuffer.ProjectCopyInformation(false, null, data1); } } if (projectCopyInformation == null && safeDataObject.GetDataPresent(typeof(string))) { string str = safeDataObject.GetData(typeof(string)) as string; if (str != null) { string[] strArrays1 = new string[] { str }; projectCopyInformation = new CutBuffer.ProjectCopyInformation(false, null, strArrays1); } } } return(projectCopyInformation); }
private void PasteResource() { int index = -1; ResourceContainer container = (ResourceContainer)null; if (this.resourceManager.SelectedResourceContainers.Count == 1) { container = this.resourceManager.SelectedResourceContainers[0]; index = container.ResourceItems.Count; } else if (this.resourceManager.SelectedResourceItems.Count == 1) { ResourceItem resourceItem = this.resourceManager.SelectedResourceItems[0]; container = resourceItem.Container; index = container.ResourceItems.IndexOf(resourceItem) + 1; } SafeDataObject dataObject = SafeDataObject.FromClipboard(); if (index < 0) { return; } SceneViewModel viewModel = container.ViewModel; PastePackage pastePackage = PastePackage.FromData(viewModel, dataObject); if (pastePackage != null) { if (pastePackage.Elements.Count > 0) { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteResourcesFailedElementsFoundDialogMessage); } else { IDictionary <DocumentNode, string> imageMap = (IDictionary <DocumentNode, string>) new Dictionary <DocumentNode, string>(); foreach (SceneNode sceneNode in pastePackage.Resources) { foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel)) { imageMap.Add(keyValuePair); } } using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitPaste)) { Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PasteResources(pastePackage, imageMap, ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld, container.Node, index, true); editTransaction.Commit(); } } } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { DesignerContext designerContext = viewModel.DesignerContext; IDocumentType[] supportedDocumentTypes = new IDocumentType[1] { designerContext.DocumentTypeManager.DocumentTypes[DocumentTypeNamesHelper.Image] }; string[] supportedFiles = new FileDropUtility(designerContext.ProjectManager, (FrameworkElement)null, supportedDocumentTypes).GetSupportedFiles(ClipboardService.GetDataObject()); if (supportedFiles.Length > 0) { foreach (IProjectItem projectItem in designerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)supportedFiles, (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo() { SourcePath = file })))) { this.CreateImageBrushResource(container, projectItem); } } else { designerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else { if (!dataObject.GetDataPresent(DataFormats.Bitmap)) { return; } IProject project = EnumerableExtensions.SingleOrNull <IProject>(this.projectManager.ItemSelectionSet.SelectedProjects); if (project == null) { return; } IProjectItem projectItem = CutBuffer.AddImageDataFromClipboard(this.projectManager, project); this.CreateImageBrushResource(container, projectItem); } }
public override void Execute() { using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitPaste)) { this.SceneViewModel.GetActiveSceneInsertionPoint(new InsertionPointContext(false)); if (this.SceneViewModel.TextSelectionSet.IsActive) { try { this.SceneViewModel.TextSelectionSet.TextEditProxy.EditingElement.Paste(); } catch (ArgumentException ex) { this.SceneViewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteTextFailedDialogMessage); } } else { ICollection <SceneNode> nodes = PasteCommand.PasteData(this.SceneViewModel, SafeDataObject.FromClipboard()); if (nodes.Count > 0) { this.SceneViewModel.ClearSelections(); this.SceneViewModel.SelectNodes(nodes); } } editTransaction.Commit(); } }