Exemplo n.º 1
0
        void CreateObjects()
        {
            ContentBrowserUtility.AllContentBrowsers_SuspendChildrenChangedEvent();
            ESet <ComponentHierarchyController> controllersToProcessDelayedOperations = new ESet <ComponentHierarchyController>();

            try
            {
                foreach (var obj in Objects)
                {
                    //!!!!?
                    if (obj.Disposed)
                    {
                        continue;
                    }

                    dataToRestore.TryGetValue(obj, out RestoreData data);
                    if (data != null)
                    {
                        dataToRestore.Remove(obj);

                        data.parent.AddComponent(obj, data.insertIndex);

                        if (obj.ParentRoot?.HierarchyController != null)
                        {
                            controllersToProcessDelayedOperations.AddWithCheckAlreadyContained(obj.ParentRoot?.HierarchyController);
                        }
                    }
                }
            }
            finally
            {
                foreach (var c in controllersToProcessDelayedOperations)
                {
                    c.ProcessDelayedOperations();
                }
                ContentBrowserUtility.AllContentBrowsers_ResumeChildrenChangedEvent();
            }
        }
Exemplo n.º 2
0
        void DeleteObjects()
        {
            ContentBrowserUtility.AllContentBrowsers_SuspendChildrenChangedEvent();
            ESet <ComponentHierarchyController> controllersToProcessDelayedOperations = new ESet <ComponentHierarchyController>();

            List <Component> deleted = new List <Component>();

            try
            {
                foreach (var obj in Objects)
                {
                    var parent = obj.Parent;
                    if (parent != null)
                    {
                        RestoreData data = new RestoreData();
                        data.parent      = parent;
                        data.insertIndex = parent.Components.IndexOf(obj);

                        dataToRestore[obj] = data;

                        obj.RemoveFromParent(true);

                        deleted.Add(obj);

                        if (obj.ParentRoot?.HierarchyController != null)
                        {
                            controllersToProcessDelayedOperations.AddWithCheckAlreadyContained(obj.ParentRoot?.HierarchyController);
                        }
                    }
                }
            }
            finally
            {
                foreach (var c in controllersToProcessDelayedOperations)
                {
                    c.ProcessDelayedOperations();
                }
                ContentBrowserUtility.AllContentBrowsers_ResumeChildrenChangedEvent();
            }

            //update selected objects for document windows
            if (document != null)
            {
                foreach (var window in EditorAPI.GetAllDocumentWindowsOfDocument(document))
                {
                    var  selectedObjects = new ESet <object>(window.SelectedObjectsSet);
                    bool updated         = false;

                    foreach (var obj in deleted)
                    {
                        if (selectedObjects.Remove(obj))
                        {
                            updated = true;
                        }
                    }

                    if (updated)
                    {
                        window.SelectObjects(selectedObjects);
                    }
                }
            }
            //!!!!так?
            //!!!!!!как-то слишком низкоуровнего из-за documentWindow?
            //if( SettingsWindow.Instance != null )
            //{
            //	SettingsWindow.PanelData panel = SettingsWindow.Instance.SelectedPanel;
            //	if( panel != null )
            //	{
            //		var selectedObjects = new ESet<object>( SettingsWindow.Instance.SelectedObjectsSet );

            //		foreach( var obj in deleted )
            //			selectedObjects.Remove( obj );

            //		if( !ESet<object>.IsEqual( selectedObjects, SettingsWindow.Instance.SelectedObjectsSet ) )
            //			SettingsWindow.Instance.SelectObjects( panel.documentWindow, selectedObjects );
            //	}
            //}
        }