Ejemplo n.º 1
0
        //!!!!по сути не надо указывать documentWindow
        public static void SelectComponentsInMainObjectsWindow(DocumentWindow documentWindow, Component[] components)
        //public static void SelectComponentsInMainObjectsWindow( DocumentInstance document, Component[] components )
        {
            if (documentWindow == null || components.Length == 0)
            {
                return;
            }

            var window = FindWindow <ObjectsWindow>();

            if (window != null && window.Visible)
            {
                var panel = window.GetPanel(documentWindow);
                if (panel != null)
                {
                    var browser = panel.control as ContentBrowser;
                    if (browser != null)
                    {
                        ContentBrowserUtility.SelectComponentItems(browser, components);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        bool CreateObject()
        {
            creationData.ClearCreatedObjects();

            //!!!!в окнах/окне делать активным после создания

            //creationData.selectedType = SelectedType;
            //creationData.replaceSelectedTypeFunction?.Invoke( this );

            //!!!!
            //create objects
            {
                creationData.beforeCreateObjectsFunction?.Invoke(this, SelectedType);

                //default creation behaviour
                if (creationData.createdObjects == null)
                {
                    creationData.createdObjects = new List <object>();

                    if (creationData.initParentObjects != null)
                    {
                        foreach (var parentObject in creationData.initParentObjects)
                        {
                            var parentComponent = parentObject as Component;

                            object obj;
                            if (parentComponent != null)
                            {
                                var insertIndex = EditorUtility.GetNewObjectInsertIndex(parentComponent, SelectedType);
                                obj = parentComponent.CreateComponent(SelectedType, insertIndex, false);
                            }
                            else
                            {
                                obj = SelectedType.InvokeInstance(null);
                            }

                            creationData.createdObjects.Add(obj);
                            creationData.createdObjectsToApplySettings.Add(obj);
                            var c = obj as Component;
                            if (c != null)
                            {
                                creationData.createdComponentsOnTopLevel.Add(c);
                            }
                        }
                    }
                    else
                    {
                        var obj = SelectedType.InvokeInstance(null);

                        creationData.createdObjects.Add(obj);
                        creationData.createdObjectsToApplySettings.Add(obj);
                        var c = obj as Component;
                        if (c != null)
                        {
                            creationData.createdComponentsOnTopLevel.Add(c);
                        }
                    }
                }
            }

            //!!!!
            //no created objects
            if (creationData.createdObjects.Count == 0)
            {
                //!!!!
                return(false);
            }

            string realFileName = "";

            if (IsFileCreation())
            {
                realFileName = VirtualPathUtility.GetRealPathByVirtual(textBoxName.Text);
            }

            //create folder for file creation
            if (IsFileCreation())
            {
                var directoryName = Path.GetDirectoryName(realFileName);
                if (!Directory.Exists(directoryName))
                {
                    try
                    {
                        Directory.CreateDirectory(directoryName);
                    }
                    catch (Exception e)
                    {
                        Log.Warning(e.Message);
                        return(false);
                    }
                }
            }

            //init settings of objects
            bool disableFileCreation = false;

            foreach (var createdObject in creationData.createdObjectsToApplySettings)
            {
                if (!ApplyCreationSettingsToObject(createdObject, ref disableFileCreation))
                {
                    return(false);
                }
            }

            //action before enabled
            creationData.additionActionBeforeEnabled?.Invoke(this);

            //finalization of creation
            foreach (var component in creationData.createdComponentsOnTopLevel)
            {
                component.Enabled = true;
            }

            creationData.additionActionAfterEnabled?.Invoke(this);
            //foreach( var obj in createdObjects )
            //	creationData.additionActionAfterEnabled?.Invoke( this, obj, newObjectsFromAdditionActions );

            //file creation. save to file
            if (IsFileCreation())
            {
                //!!!!проверки
                //!!!!!!!overwrite

                if (creationData.createdComponentsOnTopLevel.Count == 1 && !disableFileCreation)
                {
                    var createdComponent = creationData.createdComponentsOnTopLevel[0];
                    if (!ComponentUtility.SaveComponentToFile(createdComponent, realFileName, null, out string error))
                    {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //!!!!
                            Log.Warning(error);
                            return(false);
                        }
                    }
                }

                //Dispose created objects for file creation mode
                foreach (var obj in creationData.createdObjects)
                {
                    var d = obj as IDisposable;
                    if (d != null)
                    {
                        d.Dispose();
                    }
                }
            }

            //update document
            if (!IsFileCreation())
            {
                //update document
                //!!!!!
                var document = creationData.initDocumentWindow.Document;
                if (document != null)
                {
                    //!!!!только компоненты?

                    var action = new UndoActionComponentCreateDelete(document, creationData.createdComponentsOnTopLevel, true);

                    //List<Component> created = new List<Component>();
                    //created.AddRange( createdComponents );
                    //foreach( var obj in newObjectsFromAdditionActions )
                    //{
                    //	var component = obj as Component;
                    //	if( component != null )
                    //		created.Add( component );
                    //}
                    //var action = new UndoActionComponentCreateDelete( created, true );
                    document.UndoSystem.CommitAction(action);

                    document.Modified = true;
                }
                else
                {
                    //!!!!надо ли?
                    Log.Warning("impl");
                }
            }

            //select and open
            if (IsFileCreation())
            {
                //!!!!не обязательно основное окно

                EditorAPI.GetRestartApplication(out var needRestart, out _);
                if (needRestart)
                {
                    EditorSettingsSerialization.OpenFileAtStartup = realFileName;
                }
                else
                {
                    //select new file in Resources window
                    EditorAPI.SelectFilesOrDirectoriesInMainResourcesWindow(new string[] { realFileName });

                    //open file
                    EditorAPI.OpenFileAsDocument(realFileName, true, true);
                }
            }
            else
            {
                //select created components
                if (creationData.createdFromContentBrowser != null)
                {
                    var creator = creationData.createdFromContentBrowser;
                    if (creator.IsHandleCreated && !creator.IsDisposed)
                    {
                        ContentBrowserUtility.SelectComponentItems(creator, creationData.createdComponentsOnTopLevel.ToArray());
                    }
                }
                else
                {
                    EditorAPI.SelectComponentsInMainObjectsWindow(creationData.initDocumentWindow, creationData.createdComponentsOnTopLevel.ToArray());
                }

                //open editor
                if (creationData.createdComponentsOnTopLevel.Count == 1)
                {
                    var component = creationData.createdComponentsOnTopLevel[0];

                    if (!component.EditorReadOnlyInHierarchy)
                    {
                        //!!!!пока так
                        if (component is Component_FlowGraph || component is Component_CSharpScript)
                        {
                            EditorAPI.OpenDocumentWindowForObject(creationData.initDocumentWindow.Document, component);
                        }
                    }
                    //if( EditorAPI.IsDocumentObjectSupport( component ) && !component.EditorReadOnlyInHierarchy )
                    //	EditorAPI.OpenDocumentWindowForObject( creationData.initDocumentWindow.Document, component );
                }
            }

            //finish creation
            creationData.ClearCreatedObjects();

            return(true);
        }
Ejemplo n.º 3
0
        private void kryptonButtonSearch_Click(object sender, EventArgs e)
        {
            var rootComponent = Browser.RootObject as Component;

            if (rootComponent == null)
            {
                return;
            }

            string namePattern = kryptonTextBoxFilterByName.Text.Trim();

            if (namePattern.Length > 0 && namePattern[namePattern.Length - 1] != '*')
            {
                namePattern += '*';
            }

            var toSelect = new ESet <Component>();

            if (ModifierKeys.HasFlag(Keys.Shift))
            {
                foreach (var item in Browser.SelectedItems.OfType <ContentBrowserItem_Component>())
                {
                    toSelect.Add(item.Component);
                }
            }

            //EntityType selectedType = TypeSelected;

            var components = new List <Component>(256);

            components.Add(rootComponent);
            components.AddRange(rootComponent.GetComponents(checkChildren: true));

            var equalNamePattern = namePattern;

            if (equalNamePattern.Length > 0)
            {
                equalNamePattern = equalNamePattern.Substring(0, equalNamePattern.Length - 1);
            }

            foreach (var component in components)
            {
                //filter by name
                if (IsSearchPatternMatch(component.Name, namePattern) || component.Name == equalNamePattern)
                {
                    ////filter by type
                    //if( selectedType != null && entity.Type != selectedType )
                    //	continue;

                    ////filter by class
                    //if( comboBoxClass.SelectedItem != null && selectedType == null )
                    //{
                    //	ClassTypeItem classTypeItem = (ClassTypeItem)comboBoxClass.SelectedItem;
                    //	if( !classTypeItem.classType.IsAssignableFrom( entity.GetType() ) )
                    //		continue;
                    //}

                    toSelect.AddWithCheckAlreadyContained(component);
                }
            }

            ContentBrowserUtility.SelectComponentItems(Browser, toSelect.ToArray());
        }