Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public string[] GetSupportedFiles(IDataObject dataObject)
        {
            SafeDataObject safeDataObject = new SafeDataObject(dataObject);
            List <string>  strs           = new List <string>();

            string[] data = (string[])safeDataObject.GetData(DataFormats.FileDrop);
            if (data != null)
            {
                string[] strArrays = data;
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string   str     = strArrays[i];
                    IProject project = this.projectManager.ItemSelectionSet.SelectedProjects.SingleOrNull <IProject>();
                    if (project != null && this.IsDocumentTypeSupported(project.GetDocumentType(str)))
                    {
                        strs.Add(str);
                    }
                }
            }
            ItemSelectionSet itemSelectionSets = (ItemSelectionSet)safeDataObject.GetData("BlendProjectItem");

            if (itemSelectionSets != null)
            {
                foreach (IProjectItem selection in itemSelectionSets.Selection)
                {
                    if (!this.IsDocumentTypeSupported(selection.DocumentType))
                    {
                        continue;
                    }
                    strs.Add(selection.DocumentReference.Path);
                }
            }
            return(strs.ToArray());
        }
Ejemplo n.º 3
0
        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
                        });
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public static bool FirstDataOfType <T>(SafeDataObject data, ref T result)
 {
     using (IEnumerator <T> enumerator = DragSourceHelper.DataOfType <T>(data).GetEnumerator())
     {
         if (enumerator.MoveNext())
         {
             T current = enumerator.Current;
             result = current;
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 6
0
 public static IEnumerable <T> DataOfType <T>(SafeDataObject data)
 {
     if (data != null)
     {
         T result = default(T);
         foreach (string format in data.GetFormats())
         {
             if (DragSourceHelper.InternalDataOfType <T>(data.GetData(format), ref result))
             {
                 yield return(result);
             }
         }
     }
 }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        protected virtual bool OnDrop(DragEventArgs args)
        {
            SafeDataObject dataObject = new SafeDataObject(args.Data);

            if (PasteCommand.CanPasteData(dataObject))
            {
                using (SceneEditTransaction editTransaction = this.ActiveSceneViewModel.CreateEditTransaction(StringTable.UndoUnitPaste))
                {
                    ICollection <SceneNode> nodes = PasteCommand.PasteData(this.ActiveSceneViewModel, dataObject);
                    if (nodes.Count > 0)
                    {
                        this.ActiveSceneViewModel.ClearSelections();
                        this.ActiveSceneViewModel.SelectNodes(nodes);
                    }
                    editTransaction.Commit();
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
 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();
     }
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 public static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject, ISceneInsertionPoint insertionPoint, out bool canceledPasteOperation)
 {
     return(PasteCommand.PasteData(viewModel, dataObject, insertionPoint, false, out canceledPasteOperation));
 }
Ejemplo n.º 14
0
        public static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject)
        {
            bool canceledPasteOperation;

            return(PasteCommand.PasteData(viewModel, dataObject, viewModel.ActiveSceneInsertionPoint, viewModel.LockedInsertionPoint == null, out canceledPasteOperation));
        }