From c0bdcb8bad588725482abb326327037e02201ee4 Mon Sep 17 00:00:00 2001 From: ThomasAunvik Date: Sat, 19 May 2018 20:58:05 +0200 Subject: [PATCH 1/3] Fixes NullReferenceException on gitLocks --- .../Assets/Editor/GitHub.Unity/UI/ChangesView.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs index 021e8eb2f..978151882 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs @@ -292,6 +292,11 @@ private void MaybeUpdateData() gitLocks = new HashSet(Repository.CurrentLocks.Select(gitLock => gitLock.Path)); } + if (gitLocks == null) + { + gitLocks = new HashSet(); + } + if (currentStatusEntriesHasUpdate) { gitStatusEntries = Repository.CurrentChanges.Where(x => x.Status != GitFileStatus.Ignored).ToList(); From be3e2cd2330c0d7beb21faa7466aa84ac5b3cba0 Mon Sep 17 00:00:00 2001 From: ThomasAunvik Date: Sun, 20 May 2018 05:22:30 +0200 Subject: [PATCH 2/3] Adds Discard Button --- .../Editor/GitHub.Unity/UI/ChangesView.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs index 978151882..6827a6df3 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; + [SerializeField] private bool shouldOpenDiscardConfirmDialog; [SerializeField] private string commitBody = ""; [SerializeField] private string commitMessage = ""; @@ -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(); @@ -412,6 +439,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; } From 3264516e9aeb8741a783b48ea16ee694d93cc566 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Wed, 23 May 2018 20:19:58 +0200 Subject: [PATCH 3/3] Set a bool to non-serialized. --- src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs index a1c651110..f463fe8a5 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs @@ -27,7 +27,7 @@ class ChangesView : Subview [SerializeField] private bool currentLocksHasUpdate; [NonSerialized] private GUIContent discardGuiContent; - [SerializeField] private bool shouldOpenDiscardConfirmDialog; + [NonSerialized] private bool shouldOpenDiscardConfirmDialog; [NonSerialized] private bool isBusy; [SerializeField] private string commitBody = "";