Beispiel #1
0
        private void CreateEntityTreeNodes()
        {
            for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++)
            {
                EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i];

                EntityTreeNode entityTreeNode = GlueState.Self.Find.EntityTreeNode(entitySave.Name);
                entityTreeNode.UpdateReferencedTreeNodes();
            }
        }
        private void CreateEntityTreeNodes()
        {
            //ProjectManager.GlueProjectSave.Entities[78].NamedObjects[9].UpdateCustomProperties();


            // Let's make this faster.
            //foreach (EntitySave entity in ProjectManager.GlueProjectSave.Entities)
            // Actually, the contained functions may show popups, and if 2 simultaneous popups
            // are shown, one can cancel the other out and this can cause Glue to freeze. This means
            // we can't parallel foreah it
            //Parallel.ForEach(ProjectManager.GlueProjectSave.Entities, (entity) =>
            foreach (EntitySave entity in ProjectManager.GlueProjectSave.Entities)
            {
                entity.UpdateCustomProperties();
                entity.UpdateFromBaseType();
            }

            for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++)
            {
                EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i];
                // This is so fast that we no longer need to show the
                // user details - and not doing it will make things even faster
                //SetInitWindowText("Creating Entity: " + entitySave.Name);

                EntityTreeNode entityTreeNode = GlueState.Self.Find.EntityTreeNode(entitySave.Name);

                #region If there is no EntityTreeNode

                if (entityTreeNode == null)
                {
                    // See if the file exists
                    string fileToSearchFor = FileManager.RelativeDirectory + entitySave.Name + ".cs";

                    if (System.IO.File.Exists(fileToSearchFor))
                    {
                        // If we got here that means there's probably not a build item for this file
                        MessageBox.Show("The Glue project has the following Entity:\n" + entitySave.Name + "\n" +
                                        "but this file is not part of Visual Studio.  This file may have been removed manually or " +
                                        "there may have been some saving error.  You should close Glue, manually add this and the Generated file " +
                                        "to Visual Studio, then restart Glue.");
                        MainGlueWindow.Self.HasErrorOccurred = true;
                    }
                    else
                    {
                        MultiButtonMessageBox mbmb = new MultiButtonMessageBox();

                        mbmb.MessageText = "Could not find the file name\n\n" + fileToSearchFor + "\n\nwhich is used by the entity\n\n" + entitySave.Name + "\n\n" +
                                           "What would you like to do?";


                        mbmb.AddButton("Create a new custom code file", DialogResult.Yes);
                        mbmb.AddButton("Delete this Entity", DialogResult.No);
                        mbmb.AddButton("Do nothing.  The Entity will not show up in Glue until this problem is fixed.", DialogResult.Cancel);

                        DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self);

                        switch (result)
                        {
                        case DialogResult.Yes:
                            if (entityTreeNode == null)
                            {
                                entityTreeNode = ElementViewWindow.AddEntity(entitySave);
                            }

                            CodeWriter.GenerateAndAddElementCustomCode(entitySave);

                            //entityTreeNode.GenerateCode(ProjectManager.EntityTemplateCode);

                            break;

                        case DialogResult.No:
                            ProjectManager.GlueProjectSave.Entities.RemoveAt(i);
                            i--;
                            continue;

                        //break;
                        case DialogResult.Cancel:
                            // do nothing
                            continue;

                            //break;
                        }

                        System.Windows.Forms.MessageBox.Show("Could not create the EntitySave for " + entitySave.Name +
                                                             " because the following file doesn't exist\n\n" + fileToSearchFor);
                    }
                    //mGlueProjectSave.Entities.RemoveAt(i);
                    //i--;
                }

                #endregion


                entityTreeNode.EntitySave = entitySave;

                CheckForMissingCustomFile(entityTreeNode);


                entityTreeNode.UpdateReferencedTreeNodes();

                // moved above
                //entityTreeNode.EntitySave.UpdateCustomProperties();
                //entityTreeNode.EntitySave.UpdateFromBaseType();
            }
        }
Beispiel #3
0
        public static void UpdateAllDerivedElementFromBaseValues(bool regenerateCode)
        {
            if (EditorLogic.CurrentEntitySave != null)
            {
                List <EntitySave> derivedEntities = ObjectFinder.Self.GetAllEntitiesThatInheritFrom(EditorLogic.CurrentEntitySave.Name);

                List <NamedObjectSave> nosList = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(EditorLogic.CurrentEntitySave.Name);

                for (int i = 0; i < derivedEntities.Count; i++)
                {
                    EntitySave entitySave = derivedEntities[i];

                    nosList.AddRange(ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(entitySave.Name));


                    entitySave.UpdateFromBaseType();
                    // Update the tree nodes
                    EntityTreeNode treeNode = GlueState.Self.Find.EntityTreeNode(entitySave);
                    treeNode.UpdateReferencedTreeNodes();

                    if (regenerateCode)
                    {
                        CodeWriter.GenerateCode(entitySave);
                    }
                }

                foreach (NamedObjectSave nos in nosList)
                {
                    nos.UpdateCustomProperties();

                    IElement element = nos.GetContainer();

                    if (element != null)
                    {
                        CodeWriter.GenerateCode(element);
                    }
                }
            }
            else if (EditorLogic.CurrentScreenSave != null)
            {
                List <ScreenSave> derivedScreens = ObjectFinder.Self.GetAllScreensThatInheritFrom(EditorLogic.CurrentScreenSave.Name);

                for (int i = 0; i < derivedScreens.Count; i++)
                {
                    ScreenSave screenSave = derivedScreens[i];
                    screenSave.UpdateFromBaseType();

                    ScreenTreeNode treeNode = GlueState.Self.Find.ScreenTreeNode(screenSave);
                    treeNode.UpdateReferencedTreeNodes();

                    if (regenerateCode)
                    {
                        CodeWriter.GenerateCode(screenSave);
                    }
                }
            }
            else
            {
                if (EditorLogic.CurrentNamedObject == null)
                {
                    // This means the value is being set on the Screen itself
                    throw new NotImplementedException();
                }
            }
        }