Пример #1
0
        private void LoadConfig(string filePath)
        {
            iniConfig      = null;
            configFilePath = null;

            if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
            {
                configFilePath = filePath;
                iniConfig      = IniConfigUtil.ReadConfigFrom(filePath);
            }

            Repaint();
        }
Пример #2
0
        private void DrawToolbar()
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));
            {
                if (EGUILayout.ToolbarButton(Contents.OpenStr))
                {
                    string filePath = EditorUtility.OpenFilePanel(Contents.OpenStr, Application.dataPath, "txt");
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        LoadConfig(filePath);
                    }
                }

                if (EGUILayout.ToolbarButton(Contents.NewStr))
                {
                    configFilePath = null;
                    iniConfig      = new IniConfig();
                }
                if (iniConfig != null)
                {
                    if (EGUILayout.ToolbarButton(Contents.SaveStr))
                    {
                        string filePath = configFilePath;

                        if (string.IsNullOrEmpty(filePath))
                        {
                            filePath = EditorUtility.SaveFilePanel(Contents.SaveStr, Application.dataPath, "ini_config", "txt");
                        }

                        if (!string.IsNullOrEmpty(filePath))
                        {
                            configFilePath = filePath;
                            IniConfigUtil.WriteConfigTo(filePath, iniConfig);
                        }
                    }
                }

                GUILayout.FlexibleSpace();

                if (iniConfig != null)
                {
                    if (EGUILayout.ToolbarButton(Contents.AddGroupContent, 70))
                    {
                        PopupWindow.Show(new Rect(Event.current.mousePosition, Vector2.zero), new CreateIniGroupContent(iniConfig, (groupName) =>
                        {
                            Repaint();
                        }));
                    }
                }

                if (searchField == null)
                {
                    searchField = new ToolbarSearchField((text) =>
                    {
                        searchText = text == null?"":text.ToLower();
                    }, null);
                }
                searchField.OnGUILayout();
            }
            EditorGUILayout.EndHorizontal();
        }