Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class ChangesView : Subview
private const string CommitButton = "Commit to <b>{0}</b>";
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";
Expand All @@ -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 = "";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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; }
Expand Down