|
@@ -3,9 +3,12 @@
|
|
|
// A modal editor window that displays pull conflicts and allows the user
|
|
|
// to select files to reset before proceeding.
|
|
|
|
|
|
+using System.IO;
|
|
|
using UnityEditor;
|
|
|
using UnityEngine;
|
|
|
+using System.Linq;
|
|
|
using UnityEngine.Scripting;
|
|
|
+using Terra.Arbitrator.Services;
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace Terra.Arbitrator.GUI
|
|
@@ -13,34 +16,46 @@ namespace Terra.Arbitrator.GUI
|
|
|
[Preserve]
|
|
|
public class ConflictResolutionWindow : EditorWindow
|
|
|
{
|
|
|
- private List<string> _conflictingFiles;
|
|
|
- private string _fileBeingReset;
|
|
|
+ private List<GitChange> _conflictingFiles;
|
|
|
private Vector2 _scrollPosition;
|
|
|
private ArbitratorController _controller;
|
|
|
+ private GUIStyle _wordWrapStyle;
|
|
|
|
|
|
/// <summary>
|
|
|
/// Shows a modal window to display pull conflicts and get user action.
|
|
|
/// </summary>
|
|
|
/// <param name="controller">Reference to the arbitrator controller</param>
|
|
|
/// <param name="conflictingFiles">The list of files that have conflicts.</param>
|
|
|
- public static void ShowWindow(ArbitratorController controller, List<string> conflictingFiles)
|
|
|
+ public static void ShowWindow(ArbitratorController controller, IReadOnlyList<GitChange> conflictingFiles)
|
|
|
{
|
|
|
var window = GetWindow<ConflictResolutionWindow>(true, "Pull Conflicts Detected", true);
|
|
|
window.minSize = new Vector2(600, 400);
|
|
|
window._controller = controller;
|
|
|
- window._conflictingFiles = new List<string>(conflictingFiles);
|
|
|
+ window._conflictingFiles = new List<GitChange>(conflictingFiles);
|
|
|
window.ShowModalUtility();
|
|
|
}
|
|
|
|
|
|
private void OnGUI()
|
|
|
{
|
|
|
- EditorGUILayout.HelpBox("A pull would result in conflicts with your local changes. To proceed with a clean pull, you must reset your local changes for the conflicting files listed below.", MessageType.Warning);
|
|
|
- EditorGUILayout.LabelField("Conflicting Files:", EditorStyles.boldLabel);
|
|
|
+ _wordWrapStyle ??= new GUIStyle(EditorStyles.label) { wordWrap = true };
|
|
|
+
|
|
|
+ EditorGUILayout.HelpBox("A pull would result in conflicts with your local changes. To proceed with a clean pull, you must choose a resolution for the conflicting files listed below.", MessageType.Warning);
|
|
|
+
|
|
|
+ EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
|
|
|
+ GUILayout.Label("Filename");
|
|
|
+ GUILayout.FlexibleSpace();
|
|
|
+ GUILayout.Label(""); //Spacer
|
|
|
+ GUILayout.FlexibleSpace();
|
|
|
+ GUILayout.Label("Choice", GUILayout.Width(70));
|
|
|
+ EditorGUILayout.EndHorizontal();
|
|
|
|
|
|
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, EditorStyles.helpBox);
|
|
|
- foreach (var file in new List<string>(_conflictingFiles))
|
|
|
+ if (_conflictingFiles != null)
|
|
|
{
|
|
|
- DrawFileRow(file);
|
|
|
+ foreach (var change in _conflictingFiles)
|
|
|
+ {
|
|
|
+ DrawFileRow(change);
|
|
|
+ }
|
|
|
}
|
|
|
EditorGUILayout.EndScrollView();
|
|
|
|
|
@@ -48,44 +63,27 @@ namespace Terra.Arbitrator.GUI
|
|
|
DrawActionButtons();
|
|
|
}
|
|
|
|
|
|
- private void DrawFileRow(string filePath)
|
|
|
+ private void DrawFileRow(GitChange change)
|
|
|
{
|
|
|
- EditorGUILayout.BeginHorizontal();
|
|
|
- EditorGUILayout.LabelField(new GUIContent(filePath, filePath));
|
|
|
+ EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
|
|
|
|
|
|
- var isThisFileLoading = _fileBeingReset == filePath;
|
|
|
-
|
|
|
- EditorGUI.BeginDisabledGroup(isThisFileLoading || !string.IsNullOrEmpty(_fileBeingReset));
|
|
|
- if (GUILayout.Button(isThisFileLoading ? "Resetting..." : "Reset", GUILayout.Width(100)))
|
|
|
- {
|
|
|
- HandleResetFile(filePath);
|
|
|
- }
|
|
|
- EditorGUI.EndDisabledGroup();
|
|
|
+ EditorGUILayout.LabelField(new GUIContent(change.FilePath, change.FilePath), _wordWrapStyle, GUILayout.ExpandWidth(true));
|
|
|
+ change.Resolution = (GitChange.ConflictResolution)EditorGUILayout.EnumPopup(change.Resolution, GUILayout.Width(70));
|
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
}
|
|
|
-
|
|
|
- private void HandleResetFile(string filePath)
|
|
|
- {
|
|
|
- _fileBeingReset = filePath;
|
|
|
- Repaint();
|
|
|
-
|
|
|
- _controller.ResetSingleConflictingFile(filePath, () =>
|
|
|
- {
|
|
|
- _conflictingFiles.Remove(filePath);
|
|
|
- _fileBeingReset = null;
|
|
|
- Repaint();
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
private void DrawActionButtons()
|
|
|
{
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
|
- if (GUILayout.Button("Proceed with Pull (Risky)", GUILayout.Height(30), GUILayout.Width(180)))
|
|
|
+ var allResolved = _conflictingFiles != null && _conflictingFiles.All(c => c.Resolution != GitChange.ConflictResolution.None);
|
|
|
+ var pullButtonText = allResolved ? "Pull Safely" : "Pull Anyways (Risky)";
|
|
|
+
|
|
|
+ if (GUILayout.Button(pullButtonText, GUILayout.Height(30), GUILayout.Width(180)))
|
|
|
{
|
|
|
- _controller.ForcePull();
|
|
|
+ _controller?.ResolveConflictsAndPull(_conflictingFiles);
|
|
|
Close();
|
|
|
}
|
|
|
if (GUILayout.Button("Cancel", GUILayout.Height(30)))
|