public void OnGUI()
        {
            //GUIStyle fileButtonStyle = new GUIStyle();
            //fileButtonStyle.

            // file buttons
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("New file", EditorStyles.miniButtonMid))
            {
                var newTab = new FileTab(this);
                OpenTabs.Add(newTab);
                SelectTab(newTab);
            }
            if (GUILayout.Button("Open", EditorStyles.miniButtonMid))
            {
                OpenFile(EditorUtility.OpenFilePanel("Open text file", "", ""));
            }

            EditorGUI.BeginDisabledGroup(CurrentTab == null);
            if (GUILayout.Button("Save", EditorStyles.miniButtonMid))
            {
                SaveFile(CurrentTab.filePath, CurrentTab.currentTextContent);
            }
            if (GUILayout.Button("Close", EditorStyles.miniButtonMid))
            {
                CloseCurrent();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            // tabs area
            Color originalBackgroundColor = GUI.backgroundColor;

            tabsViewScrollPosition = GUILayout.BeginScrollView(tabsViewScrollPosition, false, false, GUIStyle.none, GUIStyle.none, GUILayout.ExpandHeight(false));
            EditorGUILayout.BeginHorizontal();
            foreach (FileTab fileTab in OpenTabs)
            {
                fileTab.OnGUI(CurrentTab == fileTab);
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.EndScrollView();
            GUI.backgroundColor = originalBackgroundColor;

            // text editing area
            if (CurrentTab != null)
            {
                textViewScrollPosition = GUILayout.BeginScrollView(textViewScrollPosition);
                UpdateTextContent(EditorGUILayout.TextArea(CurrentTab.currentTextContent, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)));
                GUILayout.EndScrollView();
            }
        }
 private void CloseCurrent()
 {
     if (CurrentTab == null)
     {
         return;
     }
     OpenTabs.Remove(CurrentTab);
     if (OpenTabs.Count > 0)
     {
         SelectTab(OpenTabs[0]);
     }
     else
     {
         CurrentTab = null;
     }
 }
        public void OpenFile(string filePath)
        {
            if (filePath == null || filePath.Length == 0)
            {
                return;
            }

            var newTextContent = File.ReadAllText(filePath);
            var newTab         = new FileTab(this);

            newTab.filePath           = filePath;
            newTab.currentTextContent = newTextContent;

            OpenTabs.Add(newTab);
            SelectTab(newTab);
        }
 public void SelectTab(FileTab fileTab)
 {
     CurrentTab = fileTab;
     GUI.FocusControl(null); // remove focus so the textarea updates with the new file content
 }