diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs index ec0de8717..5d45d3102 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs @@ -14,6 +14,10 @@ class ChangesView : Subview private const string CommitButton = "Commit to {0}"; private const string SelectAllButton = "All"; private const string SelectNoneButton = "None"; + private const string DiscardAllSelected = "Discard"; + private const string WantToDiscardMessage = "Are you sure you want to discard the selected files?"; + private const string DiscardOK = "Yes"; + private const string DiscardCancel = "No"; private const string ChangedFilesLabel = "{0} changed files"; private const string OneChangedFileLabel = "1 changed file"; private const string NoChangedFilesLabel = "No changed files"; @@ -23,6 +27,7 @@ class ChangesView : Subview [SerializeField] private bool currentLocksHasUpdate; [NonSerialized] private GUIContent discardGuiContent; + [NonSerialized] private bool shouldOpenDiscardConfirmDialog; [NonSerialized] private bool isBusy; [SerializeField] private string commitBody = ""; @@ -155,6 +160,28 @@ private void DoButtonBarGUI() GUILayout.FlexibleSpace(); + EditorGUI.BeginDisabledGroup(gitStatusEntries == null || gitStatusEntries.Count == 0 || !treeChanges.GetCheckedFiles().Any() || IsBusy || shouldOpenDiscardConfirmDialog); + { + if (GUILayout.Button(DiscardAllSelected, EditorStyles.miniButton)) + { + shouldOpenDiscardConfirmDialog = true; + } + } + EditorGUI.EndDisabledGroup(); + + if (shouldOpenDiscardConfirmDialog) + { + if(EditorUtility.DisplayDialog(DiscardAllSelected, WantToDiscardMessage, DiscardOK, DiscardCancel)) + { + DiscardSelectedFiles(); + shouldOpenDiscardConfirmDialog = false; + } + else + { + shouldOpenDiscardConfirmDialog = false; + } + } + GUILayout.Label(changedFilesText, EditorStyles.miniLabel); } GUILayout.EndHorizontal(); @@ -502,6 +529,11 @@ private void Commit() }).Start(); } + private void DiscardSelectedFiles() + { + Repository.DiscardChanges(treeChanges.checkedFileNodes.Select(entry => entry.Value.GitStatusEntry).ToArray()).Start(); + } + public override bool IsBusy { get { return isBusy || base.IsBusy; }