Esempio n. 1
0
    void OnGUI()
    {
        GUI.enabled = BrowserUtility.guiEnabled;

        if (!initGUIStyle)
        {
            InitializeStyle();

            LoadSettings();
        }

        scrollPosition1 = GUILayout.BeginScrollView(scrollPosition1, false, false, GUI.skin.horizontalScrollbar, blankScrollbar, GUILayout.Height(110));

        #region Main button row
        GUILayout.BeginHorizontal();

        DisplayButtons();

        GUILayout.EndHorizontal();
        #endregion

        GUILayout.Space(12);
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(3));

        #region Repository location, initialization
        GUILayout.BeginHorizontal();
        if (!string.IsNullOrEmpty(BrowserUtility.repositoryLocation))
        {
            GUILayout.Label(versionControlTypeLogo);

            GUILayout.Space(10);

            GUILayout.Label(BrowserUtility.repositoryShortName);



            GUILayout.FlexibleSpace();

            /* TODO: Put this in the settings window
             *
             * if (viewMode != BrowserViewMode.ArtistMode)
             * {
             *      if (GUILayout.Button("Reinitialize"))
             *              BrowserUtility.OnButton_Init(this);
             * }
             */

            var vm = (BrowserViewMode)EditorGUILayout.EnumPopup(viewMode);

            if (vm != viewMode)
            {
                viewMode = vm;
                EditorPrefs.SetInt("UnityVersionControl.BrowserViewMode", (int)viewMode);
            }
        }
        else
        {
            GUI.color = Color.red;
            GUILayout.Label("No project repository found!");
            GUI.color = Color.white;

            GUILayout.FlexibleSpace();

            // Todo, make initialization UI prettier
            if (GUILayout.Button("Initialize"))
            {
                BrowserUtility.OnButton_Init(this);
            }

            var vm = (BrowserViewMode)EditorGUILayout.EnumPopup(viewMode);

            if (vm != viewMode)
            {
                viewMode = vm;
                EditorPrefs.SetInt("UnityVersionControl.BrowserViewMode", (int)viewMode);
            }
        }

        GUILayout.EndHorizontal();
        #endregion


        GUILayout.EndScrollView();


        mainScrollPosition = GUILayout.BeginScrollView(mainScrollPosition);

        GUILayout.BeginHorizontal();
        if (viewMode != BrowserViewMode.ArtistMode && showDiff)
        {
            GUILayout.BeginVertical(GUILayout.Width(horizontalResizeWidget1 - 3));
        }
        else
        {
            GUILayout.BeginVertical();
        }

        #region First scroll area - Staged files (git)
        if (VersionControl.versionControlType == VersionControlType.Git && viewMode != BrowserViewMode.ArtistMode && showStagedFiles)
        {
            GUILayout.BeginVertical(GUILayout.Height(verticalResizeWidget1 - 3));

            GUILayout.BeginHorizontal();
            GUILayout.Label("Staged files", EditorStyles.toolbarButton);
            stagedFilesFilter = (FileState)EditorGUILayout.EnumMaskField(stagedFilesFilter, EditorStyles.toolbarPopup, GUILayout.Width(100));

            GUILayout.EndHorizontal();

            scrollPosition2 = GUILayout.BeginScrollView(scrollPosition2, false, false);
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUI.backgroundColor *= .5f;
            GUILayout.Label("State", EditorStyles.toolbarButton, GUILayout.Width(80));
            GUILayout.Label("File", EditorStyles.toolbarButton, GUILayout.Width(300));
            GUILayout.Label("Path", EditorStyles.toolbarButton, GUILayout.ExpandWidth(true));
            GUI.backgroundColor = Color.white;
            GUILayout.EndHorizontal();

            filteredStagedFiles.Clear();
            filteredStagedFiles.AddRange(BrowserUtility.stagedFiles.Values);

            FilterFileList(filteredStagedFiles, true);

            for (int i = 0; i < filteredStagedFiles.Count; i++)
            {
                DisplayFile(filteredStagedFiles[i], i, true, filteredStagedFiles);
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.EndVertical();
        }
        #endregion

        #region Resize widget
        if (VersionControl.versionControlType == VersionControlType.Git && viewMode != BrowserViewMode.ArtistMode && showStagedFiles)
        {
            Rect r    = new Rect(position.x, position.y - 220, position.width, position.height);
            bool drag = GUIHelpers.ResizeWidget(drag1, ref verticalResizeWidget1, 60, position.height - 180, 6, true, r, this);

            if (drag != drag1)
            {
                drag1 = drag;
                EditorPrefs.SetFloat("UnityVersionControl.VWidget1", verticalResizeWidget1);
            }
        }
        #endregion

        #region Second scroll area - Working tree
        if (VersionControl.versionControlType == VersionControlType.Git && viewMode != BrowserViewMode.ArtistMode && showStagedFiles)
        {
            GUILayout.BeginVertical(GUILayout.Height(position.height - 126 - verticalResizeWidget1 - 3));
        }

        GUILayout.BeginHorizontal();
        GUILayout.Label("Working tree", EditorStyles.toolbarButton);
        workingTreeFilter = (FileState)EditorGUILayout.EnumMaskField(workingTreeFilter, EditorStyles.toolbarPopup, GUILayout.Width(100));
        GUILayout.EndHorizontal();

        scrollPosition3 = GUILayout.BeginScrollView(scrollPosition3, false, false);
        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        GUI.backgroundColor *= .5f;
        GUILayout.Label("State", EditorStyles.toolbarButton, GUILayout.Width(80));
        if (viewMode != BrowserViewMode.ArtistMode)
        {
            GUILayout.Label("File", EditorStyles.toolbarButton, GUILayout.Width(300));
        }
        GUILayout.Label("Path", EditorStyles.toolbarButton, GUILayout.ExpandWidth(true));
        GUI.backgroundColor = Color.white;
        GUILayout.EndHorizontal();

        filteredWorkingTree.Clear();
        filteredWorkingTree.AddRange(BrowserUtility.workingTree.Values);

        FilterFileList(filteredWorkingTree, false);

        for (int i = 0; i < filteredWorkingTree.Count; i++)
        {
            DisplayFile(filteredWorkingTree[i], i, false, filteredWorkingTree);
        }

        GUILayout.EndVertical();
        GUILayout.EndScrollView();
        if (VersionControl.versionControlType == VersionControlType.Git && viewMode != BrowserViewMode.ArtistMode && showStagedFiles)
        {
            GUILayout.EndVertical();
        }
        #endregion

        GUILayout.EndVertical();

        #region Resize widget
        if (viewMode != BrowserViewMode.ArtistMode && showDiff)
        {
            bool drag = GUIHelpers.ResizeWidget(drag2, ref horizontalResizeWidget1, 80, position.width - 80, 4, false, position, this);

            if (drag != drag2)
            {
                drag2 = drag;
                EditorPrefs.SetFloat("UnityVersionControl.HWidget1", horizontalResizeWidget1);
            }
        }
        #endregion

        #region 3rd scroll area - Diff
        if (viewMode != BrowserViewMode.ArtistMode && showDiff)
        {
            GUILayout.BeginVertical(GUILayout.Width(position.width - horizontalResizeWidget1));

            GUILayout.BeginHorizontal();
            GUILayout.Label("Diff", EditorStyles.toolbarButton, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            scrollPosition4 = GUILayout.BeginScrollView(scrollPosition4, false, false);
            EditorGUILayout.SelectableLabel(BrowserUtility.diffString, GUILayout.ExpandHeight(true));
            GUILayout.EndScrollView();

            GUILayout.EndVertical();
        }
        #endregion

        GUILayout.EndHorizontal();

        GUILayout.EndScrollView();

        #region Status bar
        DisplayStatusBar();
        #endregion

        GUI.enabled = BrowserUtility.guiEnabled;

        if (BrowserUtility.guiEnabled)
        {
            BrowserUtility.ProcessKeyboardEvents(ref lastSelectedIndex, filteredStagedFiles, filteredWorkingTree);
        }
    }