void Save()
        {
            if (!m_Dirty)
            {
                return;
            }
            m_Dirty = false;

            var folder = Path.GetDirectoryName(m_CurrentPath);

            Assert.IsNotNull(folder);
            var newName = CurrentStruct.ProxyName() + ".cs";
            var newPath = Path.Combine(folder, newName);

            if (newPath != m_CurrentPath)
            {
                if (File.Exists(m_CurrentPath))
                {
                    AssetDatabase.RenameAsset(m_CurrentPath, newName);
                    File.Delete(m_CurrentPath);
                }

                m_CurrentPath = newPath;
            }

            File.WriteAllText(m_CurrentPath, m_CurrentModel.Generate());
            AssetDatabase.Refresh();
        }
        public void EmitDefinition(Syntax.TypeDefinitionSyntax pNode)
        {
            //Get field types
            var name   = CurrentStruct.GetFullName();
            var fields = CurrentStruct.GetFields();

            LLVMTypeRef[] types = new LLVMTypeRef[fields.Length];
            for (int i = 0; i < types.Length; i++)
            {
                types[i] = SmallTypeCache.GetLLVMType(fields[i].Type, this);
            }

            //Emit struct
            var t = LLVM.StructCreateNamed(_context, name);

            t.StructSetBody(types, false);
            Cache.SetLLVMType(name, t);
        }
        void OnEnable()
        {
            rootVisualElement.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "ComponentEditor.uss"));

            rootVisualElement.AddToClassList("root");
            var root = rootVisualElement;

            m_GhostGraphView = new GhostGraphView(this);

            m_Blackboard = new Blackboard(m_GhostGraphView)
            {
                windowed = true
            };
            m_BlackboardContentContainer = m_Blackboard.Q("unity-content-container");

            // need wait for layout to avoid default 200px width value
            root.RegisterCallback <GeometryChangedEvent>(e =>
            {
                if (!m_Blackboard.scrollable)
                {
                    m_Blackboard.scrollable = true;
                    var sv = m_Blackboard.Q <ScrollView>();
                    sv.RemoveFromClassList(ScrollView.horizontalVariantUssClassName);
                    sv.RemoveFromClassList(ScrollView.scrollVariantUssClassName);
                }

                if (m_BlackboardContentContainer != null)
                {
                    m_BlackboardContentContainer.style.width = e.newRect.width;
                }
            });

            m_Blackboard.editTextRequested = EditTextRequested;
            m_Blackboard.addItemRequested  = AddItemRequested;
            root.Add(m_Blackboard);

            m_Blackboard.Add(m_InfoSection = new BlackboardSection()
            {
                name = "infoSection", title = "No component selected"
            });
            m_InfoSection.Add(new Label("Open an existing component or create a new one.")
            {
                name = "noSelectionLabel"
            });
            m_Blackboard.Add(m_StructSection = new BlackboardSection()
            {
                name = "structSection", title = "Struct"
            });
            m_Blackboard.Add(m_FieldsSection = new BlackboardSection()
            {
                name = "fieldsSection", title = "Fields"
            });

            m_StructNameField = new TextField("Name");
            m_StructNameField.RegisterValueChangedCallback(e =>
            {
                if (CurrentStruct.Name != e.newValue)
                {
                    CurrentStruct.Name = e.newValue;
                    SetModelDirty();
                }
            });

            m_StructSection.Add(m_StructNameField);

            m_PickStructTypeButton = new Button(() => PickStructType(CurrentStruct, SetStructType));
            var structTypeRow = new VisualElement {
                name = "structTypeRow"
            };

            structTypeRow.Add(new Label("Type"));
            structTypeRow.Add(m_PickStructTypeButton);
            m_StructSection.Add(structTypeRow);
            m_StructSection.Add(m_StructTypeLabel = new Label {
                name = "structTypeLabel"
            });

            m_FieldsSection.Q("sectionHeader").Add(new Button(() =>
            {
                FieldModel newField = CurrentStruct.Add(typeof(int), MakeUniqueFieldName("newField"));
                m_FieldsSection.Add(MakeFieldRow(newField));
                SetModelDirty();
            })
            {
                text = "+"
            });

            var bottomToolbar = new VisualElement {
                name = "bottomToolbar"
            };

            bottomToolbar.Add(m_SaveButton = new Button(Save)
            {
                text = "Save"
            });
            root.Add(bottomToolbar);

            // resume after domain reload
            if (!string.IsNullOrEmpty(m_CurrentPath) && File.Exists(m_CurrentPath))
            {
                LoadFromPath(m_CurrentPath);
            }
            else
            {
                Unload();
            }
        }