12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- // Copyright (c) 2025 TerraByte Inc.
- //
- // A modal editor window that displays pull conflicts and allows the user
- // to select files to reset before proceeding.
- using UnityEditor;
- using UnityEngine;
- using System.Collections.Generic;
- namespace Terra.Arbitrator.GUI
- {
- public class ConflictResolutionWindow : EditorWindow
- {
- private List<string> _conflictingFiles;
- private string _fileBeingReset;
- private Vector2 _scrollPosition;
- private ArbitratorController _controller;
- /// <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)
- {
- 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.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);
- _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, EditorStyles.helpBox);
- foreach (var file in new List<string>(_conflictingFiles))
- {
- DrawFileRow(file);
- }
- EditorGUILayout.EndScrollView();
- EditorGUILayout.Space();
- DrawActionButtons();
- }
-
- private void DrawFileRow(string filePath)
- {
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.LabelField(new GUIContent(filePath, filePath));
- var isThisFileLoading = _fileBeingReset == filePath;
- EditorGUI.BeginDisabledGroup(isThisFileLoading || !string.IsNullOrEmpty(_fileBeingReset));
- if (GUILayout.Button(isThisFileLoading ? "Resetting..." : "Reset", GUILayout.Width(100)))
- {
- HandleResetFile(filePath);
- }
- EditorGUI.EndDisabledGroup();
-
- 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)))
- {
- _controller.PerformSafePullWithLock();
- Close();
- }
- if (GUILayout.Button("Cancel", GUILayout.Height(30)))
- {
- Close();
- }
-
- EditorGUILayout.EndHorizontal();
- }
- }
- }
|