Example #1
0
    void DrawToolBar()
    {
        GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); //2A+

        GUILayout.BeginHorizontal(GUILayout.Width(mLeftBarWidth - 6));                //2B+
        GUI.SetNextControlName("ForFouce");

        _mAsset         = mSelectionAsset;
        mSelectionAsset = (TextAsset)EditorGUILayout.ObjectField(mSelectionAsset, typeof(TextAsset), false);
        if (_mAsset != mSelectionAsset)
        {
            ReadFromTextAsset();
        }

        GUILayout.EndHorizontal();                              //2B-

        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); //2C+

        if (mSelectionAsset != null)
        {
            if (GUILayout.Button("Import", EditorStyles.toolbarDropDown, GUILayout.Width(65)))
            {
                GUIContent[] menuItems = new GUIContent[] {
                    new GUIContent("from OOForm table..."),
                    new GUIContent("from Json..."),
                    new GUIContent("from XML..."),
                    new GUIContent("from CSV...")
                };

                EditorUtility.DisplayCustomMenu(new Rect(mLeftBarWidth, 16, 0, 0), menuItems, -1,
                                                delegate(object userData, string[] options, int selected)
                {
                    switch (selected)
                    {
                    case 0:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "txt");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFromFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;

                    case 1:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "txt");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFromJsonFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;

                    case 2:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "xml");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFromXMLFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;

                    case 3:
                        {
                            string path = EditorUtility.OpenFilePanel("Select file to import!", "", "csv");
                            if (path != "")
                            {
                                mSelectionTable = OOFormArray.ReadFormCSVFile(path);
                                mIsModify       = true;
                            }
                        }
                        break;
                    }
                }
                                                , null);
            }
            if (GUILayout.Button("Export", EditorStyles.toolbarDropDown, GUILayout.Width(65)))
            {
                GUIContent[] menuItems = new GUIContent[] {
                    new GUIContent("to OOForm table..."),
                    new GUIContent("to Json..."),
                    new GUIContent("to XML..."),
                    new GUIContent("to CSV...")
                };

                EditorUtility.DisplayCustomMenu(new Rect(mLeftBarWidth + 65, 16, 0, 0), menuItems, -1,
                                                delegate(object userData, string[] options, int selected)
                {
                    switch (selected)
                    {
                    case 0:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "txt");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToString());
                            }
                        }
                        break;

                    case 1:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "txt");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToJsonString());
                            }
                        }
                        break;

                    case 2:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "xml");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToXMLString(), System.Text.Encoding.UTF8);
                            }
                        }
                        break;

                    case 3:
                        {
                            string path = EditorUtility.SaveFilePanel("Select file to save!", "", "", "csv");
                            if (path != "")
                            {
                                OOFormTools.WriteFileText(path, mSelectionTable.ToCSVString(), System.Text.Encoding.UTF8);
                            }
                        }
                        break;
                    }
                }
                                                , null);
            }

            GUILayout.Label("");

            GUILayout.Label("Search:", GUILayout.Width(50));
            mSearchString = GUILayout.TextField(mSearchString, OOFormSkin.OStyle_ToolbarSearch, GUILayout.Width(120));
            GUILayout.Label("", OOFormSkin.OStyle_ToolbarSearchRightCap);

            GUILayout.Label("    Column Page:", GUILayout.ExpandWidth(false));
            if (GUILayout.Button("<", EditorStyles.toolbarButton, GUILayout.Width(40)))
            {
                mCurrentColumnPage--;
                mCurrentColumnPage = Mathf.Max(mCurrentColumnPage, 1);
                GUI.FocusControl("ForFouce");
            }
            int max_column_page = mSelectionTable.mColumnCount / mPageColumnCount + 1;
            GUILayout.Label(mCurrentColumnPage.ToString() + "/" + max_column_page.ToString(), EditorStyles.textField, GUILayout.Width(50));

            if (GUILayout.Button(">", EditorStyles.toolbarButton, GUILayout.Width(40)))
            {
                mCurrentColumnPage++;
                mCurrentColumnPage = Mathf.Min(mCurrentColumnPage, max_column_page);
                GUI.FocusControl("ForFouce");
            }
        }
        GUILayout.EndHorizontal();  //2C-

        GUILayout.EndHorizontal();  //2A-
    }