|
@@ -14,9 +14,10 @@ using System.Linq;
|
|
|
using UnityEngine;
|
|
|
using UnityEditor;
|
|
|
using LibGit2Sharp;
|
|
|
+using Terra.Arbitrator.Services;
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
-namespace Terra.Arbitrator
|
|
|
+namespace Terra.Arbitrator.GUI
|
|
|
{
|
|
|
public class ArbitratorWindow : EditorWindow
|
|
|
{
|
|
@@ -27,6 +28,8 @@ namespace Terra.Arbitrator
|
|
|
private string _errorMessage;
|
|
|
private bool _isLoading;
|
|
|
private string _loadingMessage = "";
|
|
|
+ private GUIStyle _evenRowStyle;
|
|
|
+ private bool _stylesInitialized;
|
|
|
|
|
|
[MenuItem("Terra/Changes")]
|
|
|
public static void ShowWindow()
|
|
@@ -43,9 +46,35 @@ namespace Terra.Arbitrator
|
|
|
{
|
|
|
HandleCompare();
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Initializes custom GUIStyles. We do this here to avoid creating new
|
|
|
+ /// styles and textures on every OnGUI call, which is inefficient.
|
|
|
+ /// </summary>
|
|
|
+ private void InitializeStyles()
|
|
|
+ {
|
|
|
+ if (_stylesInitialized) return;
|
|
|
+
|
|
|
+ _evenRowStyle = new GUIStyle();
|
|
|
+
|
|
|
+ // Create a 1x1 texture with a subtle gray color
|
|
|
+ var texture = new Texture2D(1, 1);
|
|
|
+ // Use a slightly different color depending on the editor skin (light/dark)
|
|
|
+ var color = EditorGUIUtility.isProSkin
|
|
|
+ ? new Color(0.3f, 0.3f, 0.3f, 0.3f)
|
|
|
+ : new Color(0.8f, 0.8f, 0.8f, 0.5f);
|
|
|
+ texture.SetPixel(0, 0, color);
|
|
|
+ texture.Apply();
|
|
|
+
|
|
|
+ _evenRowStyle.normal.background = texture;
|
|
|
+
|
|
|
+ _stylesInitialized = true;
|
|
|
+ }
|
|
|
|
|
|
private void OnGUI()
|
|
|
{
|
|
|
+ InitializeStyles();
|
|
|
+
|
|
|
// --- Top Toolbar ---
|
|
|
DrawToolbar();
|
|
|
|
|
@@ -63,11 +92,7 @@ namespace Terra.Arbitrator
|
|
|
}
|
|
|
|
|
|
// --- Main Content ---
|
|
|
- if (_isLoading)
|
|
|
- {
|
|
|
- // You can add a more prominent loading indicator here if you wish
|
|
|
- }
|
|
|
- else if (_changes is { Count: > 0 })
|
|
|
+ else if (!_isLoading && _changes is { Count: > 0 })
|
|
|
{
|
|
|
DrawChangesList();
|
|
|
DrawCommitSection();
|
|
@@ -86,13 +111,27 @@ namespace Terra.Arbitrator
|
|
|
private void DrawToolbar()
|
|
|
{
|
|
|
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
|
|
|
-
|
|
|
+ EditorGUI.BeginDisabledGroup(_isLoading);
|
|
|
// The refresh button is now on the toolbar
|
|
|
if (GUILayout.Button(new GUIContent("Refresh", EditorGUIUtility.IconContent("Refresh").image, "Fetches the latest status from the remote."), EditorStyles.toolbarButton, GUILayout.Width(80)))
|
|
|
{
|
|
|
HandleCompare();
|
|
|
}
|
|
|
|
|
|
+ if (_changes != null && _changes.Count > 0)
|
|
|
+ {
|
|
|
+ if (GUILayout.Button("Select All", EditorStyles.toolbarButton, GUILayout.Width(80)))
|
|
|
+ {
|
|
|
+ SetAllSelection(true);
|
|
|
+ }
|
|
|
+ if (GUILayout.Button("Deselect All", EditorStyles.toolbarButton, GUILayout.Width(80)))
|
|
|
+ {
|
|
|
+ SetAllSelection(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorGUI.EndDisabledGroup();
|
|
|
+
|
|
|
// This pushes everything that comes after it to the right.
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
@@ -107,6 +146,15 @@ namespace Terra.Arbitrator
|
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
}
|
|
|
+
|
|
|
+ private void SetAllSelection(bool selected)
|
|
|
+ {
|
|
|
+ if (_changes == null) return;
|
|
|
+ foreach (var change in _changes)
|
|
|
+ {
|
|
|
+ change.IsSelectedForCommit = selected;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void HandleCompare()
|
|
|
{
|
|
@@ -222,45 +270,52 @@ namespace Terra.Arbitrator
|
|
|
|
|
|
// --- Draw Scrollable List ---
|
|
|
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, GUILayout.ExpandHeight(true));
|
|
|
- foreach (var change in _changes)
|
|
|
+ for (var i = 0; i < _changes.Count; i++)
|
|
|
{
|
|
|
- EditorGUILayout.BeginHorizontal();
|
|
|
+ var change = _changes[i];
|
|
|
+ // Use the evenRowStyle for every second row (i % 2 == 0), otherwise use no style.
|
|
|
+ var rowStyle = i % 2 == 0 ? _evenRowStyle : GUIStyle.none;
|
|
|
+
|
|
|
+ EditorGUILayout.BeginHorizontal(rowStyle);
|
|
|
|
|
|
- // Column 1: Toggle Box
|
|
|
change.IsSelectedForCommit = EditorGUILayout.Toggle(change.IsSelectedForCommit, GUILayout.Width(45));
|
|
|
-
|
|
|
- // Column 2: Status
|
|
|
+
|
|
|
string status;
|
|
|
Color statusColor;
|
|
|
+ string filePathDisplay;
|
|
|
+
|
|
|
switch (change.Status)
|
|
|
{
|
|
|
- case ChangeKind.Added: status = "[+]"; statusColor = Color.green; break;
|
|
|
- case ChangeKind.Deleted: status = "[-]"; statusColor = Color.red; break;
|
|
|
- case ChangeKind.Modified: status = "[M]"; statusColor = new Color(1.0f, 0.6f, 0.0f); break;
|
|
|
+ case ChangeKind.Added:
|
|
|
+ status = "[+]"; statusColor = Color.green; filePathDisplay = change.FilePath; break;
|
|
|
+ case ChangeKind.Deleted:
|
|
|
+ status = "[-]"; statusColor = Color.red; filePathDisplay = change.FilePath; break;
|
|
|
+ case ChangeKind.Modified:
|
|
|
+ status = "[M]"; statusColor = new Color(1.0f, 0.6f, 0.0f); filePathDisplay = change.FilePath; break;
|
|
|
+ case ChangeKind.Renamed:
|
|
|
+ status = "[R]"; statusColor = new Color(0.6f, 0.6f, 1.0f);
|
|
|
+ filePathDisplay = $"{change.OldFilePath} -> {change.FilePath}"; break;
|
|
|
case ChangeKind.Unmodified:
|
|
|
- case ChangeKind.Renamed:
|
|
|
case ChangeKind.Copied:
|
|
|
case ChangeKind.Ignored:
|
|
|
case ChangeKind.Untracked:
|
|
|
case ChangeKind.TypeChanged:
|
|
|
case ChangeKind.Unreadable:
|
|
|
case ChangeKind.Conflicted:
|
|
|
- status = "[C]"; statusColor = new Color(0.5f, 0.5f, 0.5f, 0.3f); break;
|
|
|
- default: status = "[?]"; statusColor = Color.white; break;
|
|
|
+ default:
|
|
|
+ status = "[?]"; statusColor = Color.white; filePathDisplay = change.FilePath; break;
|
|
|
}
|
|
|
- var originalColor = GUI.color;
|
|
|
- GUI.color = statusColor;
|
|
|
+
|
|
|
+ var originalColor = UnityEngine.GUI.color;
|
|
|
+ UnityEngine.GUI.color = statusColor;
|
|
|
EditorGUILayout.LabelField(new GUIContent(status, change.Status.ToString()), GUILayout.Width(50));
|
|
|
- GUI.color = originalColor;
|
|
|
+ UnityEngine.GUI.color = originalColor;
|
|
|
|
|
|
- // Column 3: File Path
|
|
|
- EditorGUILayout.LabelField(new GUIContent(change.FilePath, change.FilePath));
|
|
|
+ EditorGUILayout.LabelField(new GUIContent(filePathDisplay, filePathDisplay));
|
|
|
|
|
|
- // Column 4: Reset Button
|
|
|
EditorGUI.BeginDisabledGroup(_isLoading);
|
|
|
if (GUILayout.Button(new GUIContent("Reset", "Revert changes for this file"), GUILayout.Width(55)))
|
|
|
{
|
|
|
- // Defers the action to avoid GUI layout errors
|
|
|
EditorApplication.delayCall += () => HandleResetFile(change);
|
|
|
}
|
|
|
EditorGUI.EndDisabledGroup();
|
|
@@ -281,6 +336,7 @@ namespace Terra.Arbitrator
|
|
|
EditorGUI.BeginDisabledGroup(isPushDisabled);
|
|
|
if (GUILayout.Button("Commit & Push Selected Files", GUILayout.Height(40)))
|
|
|
{
|
|
|
+ Debug.Log("Commit & Push Selected Files");
|
|
|
HandleCommitAndPush();
|
|
|
}
|
|
|
EditorGUI.EndDisabledGroup();
|