protected override bool OnDragOver(DragEventArgs args) { base.OnDragOver(args); bool flag = true; SafeDataObject safeDataObject = new SafeDataObject(args.Data); if (safeDataObject.GetDataPresent(DataFormats.FileDrop)) { if (this.dropUtility.GetSupportedFiles(args.Data).Length > 0) { flag = false; } } else if (safeDataObject.GetDataPresent("BlendProjectItem")) { foreach (IProjectItem projectItem in ((ItemSelectionSet)safeDataObject.GetData("BlendProjectItem")).Selection) { if (projectItem.DocumentType.CanInsertTo(projectItem, (IView)this.ActiveView)) { flag = false; break; } } } if (flag) { args.Effects = DragDropEffects.None; } args.Handled = true; return(true); }
public static bool CanPasteData(SafeDataObject dataObject) { bool flag = false; if (dataObject != null) { flag = dataObject.GetDataPresent(Container.DataFormat.Name) || dataObject.GetDataPresent(DataFormats.Bitmap) || dataObject.GetDataPresent(DataFormats.FileDrop); } return(flag); }
protected override void OnDrop(DragEventArgs e) { SafeDataObject safeDataObject = new SafeDataObject(e.Data); if (safeDataObject != null && safeDataObject.GetDataPresent(DataFormats.FileDrop)) { string[] supportedFiles = this.dropUtility.GetSupportedFiles(e.Data); List <string> strs = new List <string>(); string[] strArrays = supportedFiles; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; if (((new FileInfo(str)).Attributes & FileAttributes.Directory) != FileAttributes.Directory) { strs.Add(str); } } if (strs.Count > 0) { IProject project = this.Services.ProjectManager().ItemSelectionSet.SelectedProjects.SingleOrNull <IProject>(); if (project != null) { project.AddItems( from item in strs select new DocumentCreationInfo() { SourcePath = item }); } } } }
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); }
protected override bool OnDrop(DragEventArgs args) { ISceneInsertionPoint dropInsertionPoint = this.DragDropInsertionPoint; Point position = args.GetPosition((IInputElement)this.ActiveView.ViewRootContainer); this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, (BaseFrameworkElement)null, (IList <BaseFrameworkElement>)null); Point point = this.ToolBehaviorContext.SnappingEngine.SnapPoint(position, EdgeFlags.All); Point dropPoint = this.ActiveView.TransformPointFromRoot(dropInsertionPoint.SceneElement, point); this.ToolBehaviorContext.SnappingEngine.Stop(); SafeDataObject safeDataObject = new SafeDataObject(args.Data); using (TemporaryCursor.SetWaitCursor()) { if (safeDataObject.GetDataPresent(DataFormats.FileDrop)) { FileDropToolBehavior.AddItemsToDocument(this.ActiveView, this.ActiveSceneViewModel.DesignerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>) this.dropUtility.GetSupportedFiles(args.Data), (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo() { SourcePath = file }))), dropPoint, dropInsertionPoint); } else if (safeDataObject.GetDataPresent("BlendProjectItem")) { ItemSelectionSet itemSelectionSet = (ItemSelectionSet)safeDataObject.GetData("BlendProjectItem"); using (SceneEditTransaction editTransaction = this.ActiveSceneViewModel.CreateEditTransaction(StringTable.DropProjectItemIntoSceneUndo)) { foreach (IProjectItem projectItem in itemSelectionSet.Selection) { FileDropToolBehavior.AddToDocument(this.ActiveView, projectItem, dropPoint, dropInsertionPoint); } editTransaction.Commit(); } } } if (!this.IsSuspended) { this.PopSelf(); } return(true); }
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); } }
private static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject, ISceneInsertionPoint insertionPoint, bool allowInsertionPointChange, out bool canceledPasteOperation) { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.PasteElements); canceledPasteOperation = false; List <SceneNode> list = new List <SceneNode>(); PastePackage pastePackage = PastePackage.FromData(viewModel, dataObject); if (pastePackage != null) { if (allowInsertionPointChange) { insertionPoint = PasteCommand.ComputeNewInsertionPoint(viewModel, insertionPoint, pastePackage); } if (!PasteCommand.CanAddMultipleElements(insertionPoint.SceneElement, pastePackage.Elements.Count)) { string name = insertionPoint.SceneElement.TargetType.Name; viewModel.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PasteMultipleInSingleContainerError, new object[1] { (object)name })); } else if (pastePackage.Elements.Count == 0 && pastePackage.Storyboards.Count == 0 && pastePackage.Resources.Count > 0) { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedNoElementsDialogMessage); } else { IDictionary <DocumentNode, string> imageMap = (IDictionary <DocumentNode, string>) new Dictionary <DocumentNode, string>(); foreach (SceneNode sceneNode in pastePackage.Elements) { foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel)) { imageMap.Add(keyValuePair); } } 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); } } int index = 0; ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(viewModel.RootNode.DocumentNode); if (resourcesCollection != null && resourcesCollection.Resources != null && resourcesCollection.Resources.SupportsChildren) { index = resourcesCollection.Resources.Children.Count; } if (Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PasteResources(pastePackage, imageMap, ResourceConflictResolution.UseExisting | ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld, viewModel.RootNode, index, false)) { ILayoutDesigner designerForParent = viewModel.GetLayoutDesignerForParent(insertionPoint.SceneElement, true); List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater = new List <PasteCommand.DelayedElementTranslationInfo>(pastePackage.Elements.Count); string copyElementToken = pastePackage.ClipboardCopyElementToken; foreach (SceneElement element in pastePackage.Elements) { SceneElement sceneElement = PasteCommand.PasteElement(viewModel, element, elementsToTranslateLater, insertionPoint); if (sceneElement != null) { Microsoft.Expression.DesignSurface.Utility.ResourceHelper.UpdateImageReferences(sceneElement.DocumentNode, imageMap, pastePackage, viewModel); list.Add((SceneNode)sceneElement); sceneElement.ClearValue(DesignTimeProperties.CopyTokenProperty); } } if (copyElementToken != null) { pastePackage.SetGlobalCopyElementToken(copyElementToken); PastePackage.PasteSelectionChangePending = true; } foreach (SceneNode childProperty in pastePackage.ChildPropertyNodes) { PasteCommand.PasteChildProperty(viewModel, childProperty, (IList <SceneNode>)list); } foreach (StoryboardTimelineSceneNode storyboard in pastePackage.Storyboards) { PasteCommand.PasteStoryboard(viewModel, storyboard, (IList <SceneNode>)list); } viewModel.Document.OnUpdatedEditTransaction(); viewModel.DefaultView.UpdateLayout(); using (viewModel.ForceBaseValue()) { Rect empty = Rect.Empty; foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater) { empty.Union(elementTranslationInfo.Bounds); } foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater) { elementTranslationInfo.UpdateTranslation(designerForParent, empty); } } } else { canceledPasteOperation = true; } } } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { DesignerContext designerContext = viewModel.DesignerContext; string[] supportedFiles = FileDropToolBehavior.CreateImageOrMediaDrop(designerContext).GetSupportedFiles(ClipboardService.GetDataObject()); if (supportedFiles.Length > 0) { IEnumerable <IProjectItem> importedItems = designerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)supportedFiles, (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo() { SourcePath = file }))); FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, importedItems, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint); } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else if (dataObject.GetDataPresent(DataFormats.Bitmap)) { DesignerContext designerContext = viewModel.DesignerContext; IProjectItem projectItem = CutBuffer.AddImageDataFromClipboard(designerContext.ProjectManager, designerContext.ActiveProject); if (projectItem != null) { FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, (IEnumerable <IProjectItem>) new List <IProjectItem>() { projectItem }, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint); } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } return((ICollection <SceneNode>)list); }