Ejemplo n.º 1
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());
        }
        public static void SetSelection(this IServiceProvider source, IDocumentItem item)
        {
            ItemSelectionSet itemSelectionSets = source.SelectionSet();

            if (itemSelectionSets != null)
            {
                itemSelectionSets.SetSelection(item);
            }
        }
        public static IEnumerable <IDocumentItem> Selection(this IServiceProvider source)
        {
            ItemSelectionSet itemSelectionSets = source.SelectionSet();

            if (itemSelectionSets == null)
            {
                return(Enumerable.Empty <IDocumentItem>());
            }
            return(itemSelectionSets.Selection.ToArray <IDocumentItem>());
        }
        public static IEnumerable <IProject> SelectedProjects(this IServiceProvider source)
        {
            ItemSelectionSet itemSelectionSets = source.SelectionSet();

            if (itemSelectionSets == null)
            {
                return(Enumerable.Empty <IProject>());
            }
            return(itemSelectionSets.SelectedProjects.ToArray <IProject>());
        }
Ejemplo n.º 5
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);
        }