Browse Source

Refactored, and fixed some refreshing issues

sujith 1 month ago
parent
commit
9ffc662ae2

+ 21 - 37
Assets/Better Git/Arbitrator/Editor/GUI/ArbitratorController.cs

@@ -127,25 +127,6 @@ namespace Terra.Arbitrator.GUI
                 })
                 .Finally(EditorApplication.UnlockReloadAssemblies);
         }
-        
-        public void ResolveConflictsAndPull(List<GitChange> resolutions)
-        {
-            StartOperation("Resolving conflicts and pulling...");
-            EditorApplication.LockReloadAssemblies();
-
-            GitService.PullAndOverwrite(resolutions)
-                .Then(successMessage =>
-                {
-                    InfoMessage = successMessage;
-                })
-                .Catch(HandleOperationError)
-                .Finally(() =>
-                {
-                    EditorApplication.UnlockReloadAssemblies();
-                    AssetDatabase.Refresh();
-                    Refresh();
-                });
-        }
 
         public void CommitAndPush(string commitMessage)
         {   
@@ -318,15 +299,17 @@ namespace Terra.Arbitrator.GUI
                     GitService.CreateOrOverwriteStash(selectedFiles)
                         .Then(successMsg => { InfoMessage = successMsg; })
                         .Catch(HandleOperationError)
-                        .Finally(Refresh);
+                        .Finally(() =>
+                        {
+                            Refresh();
+                            EditorApplication.delayCall += AssetDatabase.Refresh;
+                        });
                 })
                 .Catch(HandleOperationError)
                 .Finally(() =>
                 {
                     FinishOperation();
-                    Refresh();
-                    EditorApplication.UnlockReloadAssemblies();
-                    AssetDatabase.Refresh();
+                    EditorApplication.delayCall += EditorApplication.UnlockReloadAssemblies;
                 });
         }
 
@@ -482,8 +465,11 @@ namespace Terra.Arbitrator.GUI
                 })
                 .Finally(() =>
                 {
-                    EditorApplication.UnlockReloadAssemblies();
-                    AssetDatabase.Refresh();
+                    EditorApplication.delayCall += () =>
+                    {
+                        EditorApplication.UnlockReloadAssemblies();
+                        AssetDatabase.Refresh();
+                    };
                 });
         }
         
@@ -496,27 +482,29 @@ namespace Terra.Arbitrator.GUI
                 .Then(successMessage =>
                 {
                     InfoMessage = successMessage;
+                    Refresh();
                 })
                 .Catch(HandleOperationError)
                 .Finally(() =>
                 {
-                    EditorApplication.UnlockReloadAssemblies();
-                    AssetDatabase.Refresh();
-                    Refresh();
+                    EditorApplication.delayCall += () =>
+                    {
+                        EditorApplication.UnlockReloadAssemblies();
+                        AssetDatabase.Refresh();
+                    };
                 });
         }
         
         public void ShowStashedChangesWindow()
         {
-            var tempChanges = new List<GitChange>();
-            tempChanges.AddRange(_changes);
             StartOperation("Loading stashed files...");
             GitService.GetStashedFiles()
                 .Then(stashedFiles =>
                 {
                     if (stashedFiles.Any())
                     {
-                        StashedChangesWindow.ShowWindow(this, stashedFiles);
+                        InfoMessage = "Fetching files from the stash.";
+                        StashedChangesWindow.ShowWindow(this, stashedFiles, Refresh);
                     }
                     else
                     {
@@ -524,11 +512,7 @@ namespace Terra.Arbitrator.GUI
                     }
                 })
                 .Catch(HandleOperationError)
-                .Finally(() =>
-                {
-                    _changes = tempChanges;
-                    FinishOperation();
-                });
+                .Finally(FinishOperation);
         }
 
         public void DiscardStash()
@@ -590,7 +574,7 @@ namespace Terra.Arbitrator.GUI
                 {
                     FinishOperation();
                     Refresh();
-                    AssetDatabase.Refresh();
+                    EditorApplication.delayCall += AssetDatabase.Refresh;
                 });
         }
         

+ 31 - 32
Assets/Better Git/Arbitrator/Editor/GUI/ArbitratorWindow.cs

@@ -99,21 +99,22 @@ namespace Terra.Arbitrator.GUI
             
             if (!_controller.IsInConflictState)
             {
-                var pullLabel = "Pull";
-                if (_controller.CommitsToPull > 0)
-                {
-                    pullLabel = $"Pull ({_controller.CommitsToPull})";
-                }
+                var commitsToPull = _controller.CommitsToPull;
+                EditorGUI.BeginDisabledGroup(commitsToPull == 0);
+                
+                var pullLabel = $"Pull ({_controller.CommitsToPull})";
                 if (GUILayout.Button(new GUIContent(pullLabel), EditorStyles.toolbarButton, GUILayout.Width(80)))
                 {
                     _controller.Pull();
                 }
+                
+                EditorGUI.EndDisabledGroup();
             }
-            var stashSelections = _controller.Changes?.Count(c => c.IsSelectedForCommit) ?? 0;
-            EditorGUI.BeginDisabledGroup(stashSelections == 0);
-            if (GUILayout.Button(new GUIContent("Stash", EditorGUIUtility.IconContent("d_AlphabeticalSorting").image), EditorStyles.toolbarButton, GUILayout.Width(80)))
+            
+            EditorGUI.BeginDisabledGroup(!_controller.HasStash);
+            if (GUILayout.Button("See Stash Changes", EditorStyles.toolbarButton, GUILayout.Width(130)))
             {
-                _controller.StashSelectedFiles();
+                _controller.ShowStashedChangesWindow();
             }
             EditorGUI.EndDisabledGroup();
             
@@ -129,23 +130,31 @@ namespace Terra.Arbitrator.GUI
                 }
             
                 GUILayout.FlexibleSpace();
-
-                var noChanges = !_controller.Changes.Any();
-                EditorGUI.BeginDisabledGroup(noChanges);
-                
-                var selectedCount = _controller.Changes.Count(c => c.IsSelectedForCommit);
-                EditorGUI.BeginDisabledGroup(selectedCount == 0);
                 
-                var originalColor = UnityEngine.GUI.backgroundColor;
-                UnityEngine.GUI.backgroundColor = new Color(1f, 0.5f, 0.5f, 0.8f);
-                if (GUILayout.Button(new GUIContent($"Reset Selected ({selectedCount})", EditorGUIUtility.IconContent("d_TreeEditor.Trash").image), EditorStyles.toolbarButton, GUILayout.Width(200)))
+                var stashSelections = _controller.Changes?.Count(c => c.IsSelectedForCommit) ?? 0;
+                EditorGUI.BeginDisabledGroup(stashSelections == 0);
+                if (GUILayout.Button(new GUIContent("Stash", EditorGUIUtility.IconContent("d_AlphabeticalSorting").image), EditorStyles.toolbarButton, GUILayout.Width(80)))
                 {
-                    EditorApplication.delayCall += _controller.ResetSelected;
+                    _controller.StashSelectedFiles();
                 }
-                UnityEngine.GUI.backgroundColor = originalColor;
-                
-                EditorGUI.EndDisabledGroup();
                 EditorGUI.EndDisabledGroup();
+                
+                var noChanges = _controller.Changes != null && !_controller.Changes.Any();
+                if (_controller.Changes != null)
+                {
+                    var selectedCount = _controller.Changes.Count(c => c.IsSelectedForCommit);
+                    EditorGUI.BeginDisabledGroup(selectedCount == 0 || noChanges);
+                
+                    var originalColor = UnityEngine.GUI.backgroundColor;
+                    UnityEngine.GUI.backgroundColor = new Color(1f, 0.5f, 0.5f, 0.8f);
+                    if (GUILayout.Button(new GUIContent($"Reset Selected ({selectedCount})", EditorGUIUtility.IconContent("d_TreeEditor.Trash").image), EditorStyles.toolbarButton, GUILayout.Width(200)))
+                    {
+                        EditorApplication.delayCall += _controller.ResetSelected;
+                    }
+                    UnityEngine.GUI.backgroundColor = originalColor;
+
+                    EditorGUI.EndDisabledGroup();
+                }
             }
 
             EditorGUI.EndDisabledGroup();
@@ -183,15 +192,6 @@ namespace Terra.Arbitrator.GUI
                 EditorGUILayout.HelpBox(_controller.InfoMessage, MessageType.Info);
             }
         }
-
-        private void DrawStashSection()
-        {
-            if (!_controller.HasStash) return;
-            if (GUILayout.Button("See Stash Changes", GUILayout.Height(30)))
-            {
-                _controller.ShowStashedChangesWindow();
-            }
-        }
         
         private void DrawMainContent()
         {
@@ -218,7 +218,6 @@ namespace Terra.Arbitrator.GUI
             {
                 DrawChangesList();
                 DrawCommitSection();
-                DrawStashSection();
             }
             else if (_controller.ErrorMessage == null && _controller.InfoMessage == null)
             {

+ 9 - 2
Assets/Better Git/Arbitrator/Editor/GUI/StashedChangesWindow.cs

@@ -3,9 +3,9 @@
 // A new, non-dockable editor window for viewing and managing changes
 // stored in the 'Better Git Stash'.
 
+using System;
 using UnityEditor;
 using UnityEngine;
-using System.IO;
 using UnityEngine.Scripting;
 using Terra.Arbitrator.Services;
 using System.Collections.Generic;
@@ -18,13 +18,15 @@ namespace Terra.Arbitrator.GUI
         private ArbitratorController _controller;
         private List<GitChange> _stashedFiles;
         private Vector2 _scrollPosition;
+        private Action _onClose;
 
-        public static void ShowWindow(ArbitratorController controller, List<GitChange> stashedFiles)
+        public static void ShowWindow(ArbitratorController controller, List<GitChange> stashedFiles, Action onClose = null)
         {
             var window = GetWindow<StashedChangesWindow>(true, "Stashed Changes", true);
             window.minSize = new Vector2(500, 350);
             window._controller = controller;
             window._stashedFiles = stashedFiles;
+            window._onClose = onClose;
             window.ShowUtility();
         }
 
@@ -106,5 +108,10 @@ namespace Terra.Arbitrator.GUI
             EditorGUILayout.EndHorizontal();
             EditorGUILayout.Space();
         }
+        
+        private void OnDestroy()
+        {
+            _onClose?.Invoke();
+        }
     }
 }