From 9510e893756385633f7a5a28a7ce84dfaa6f3a87 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 27 Oct 2017 11:35:53 -0400 Subject: [PATCH 1/3] Refactoring Window.MaybeUpdateData --- .../Assets/Editor/GitHub.Unity/UI/Window.cs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs index f9a32fa25..7c9070d90 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs @@ -109,19 +109,7 @@ public override void OnDataUpdate() { base.OnDataUpdate(); - string repoRemote = null; - if (MaybeUpdateData(out repoRemote)) - { - repoBranchContent = new GUIContent(repoBranch, Window_RepoBranchTooltip); - if (repoUrl != null) - { - repoUrlContent = new GUIContent(repoUrl, string.Format(Window_RepoUrlTooltip, repoRemote)); - } - else - { - repoUrlContent = new GUIContent(repoUrl, Window_RepoNoUrlTooltip); - } - } + MaybeUpdateData(); if (ActiveView != null) ActiveView.OnDataUpdate(); @@ -198,10 +186,10 @@ private void RefreshOnMainThread() new ActionTask(TaskManager.Token, Refresh) { Affinity = TaskAffinity.UI }.Start(); } - private bool MaybeUpdateData(out string repoRemote) + private void MaybeUpdateData() { - repoRemote = null; - bool repoDataChanged = false; + string repoRemote = null; + var repoDataChanged = false; if (Repository != null) { var currentBranchString = (Repository.CurrentBranch.HasValue ? Repository.CurrentBranch.Value.Name : null); @@ -236,7 +224,18 @@ private bool MaybeUpdateData(out string repoRemote) } } - return repoDataChanged; + if (repoDataChanged) + { + repoBranchContent = new GUIContent(repoBranch, Window_RepoBranchTooltip); + if (repoUrl != null) + { + repoUrlContent = new GUIContent(repoUrl, string.Format(Window_RepoUrlTooltip, repoRemote)); + } + else + { + repoUrlContent = new GUIContent(repoUrl, Window_RepoNoUrlTooltip); + } + } } private void AttachHandlers(IRepository repository) From aa92bf0022e51cde680b54fa2b2da8134da1dc47 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 27 Oct 2017 11:59:30 -0400 Subject: [PATCH 2/3] Cleaning up this logic --- .../Assets/Editor/GitHub.Unity/UI/Window.cs | 49 +++++++------------ 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs index 7c9070d90..6664577cd 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs @@ -188,48 +188,35 @@ private void RefreshOnMainThread() private void MaybeUpdateData() { - string repoRemote = null; - var repoDataChanged = false; + string updatedRepoBranch = null; + string updatedRepoRemote = null; + string updatedRepoUrl = DefaultRepoUrl; + if (Repository != null) { - var currentBranchString = (Repository.CurrentBranch.HasValue ? Repository.CurrentBranch.Value.Name : null); - if (repoBranch != currentBranchString) - { - repoBranch = currentBranchString; - repoDataChanged = true; - } + var repositoryCurrentBranch = Repository.CurrentBranch; + updatedRepoBranch = repositoryCurrentBranch.HasValue ? repositoryCurrentBranch.Value.Name : null; - var url = Repository.CloneUrl != null ? Repository.CloneUrl.ToString() : DefaultRepoUrl; - if (repoUrl != url) - { - repoUrl = url; - repoDataChanged = true; - } + var repositoryCloneUrl = Repository.CloneUrl; + updatedRepoUrl = repositoryCloneUrl != null ? repositoryCloneUrl.ToString() : DefaultRepoUrl; - if (Repository.CurrentRemote.HasValue) - repoRemote = Repository.CurrentRemote.Value.Name; + var repositoryCurrentRemote = Repository.CurrentRemote; + if (repositoryCurrentRemote.HasValue) + updatedRepoRemote = repositoryCurrentRemote.Value.Name; } - else - { - if (repoBranch != null) - { - repoBranch = null; - repoDataChanged = true; - } - if (repoUrl != DefaultRepoUrl) - { - repoUrl = DefaultRepoUrl; - repoDataChanged = true; - } + if (repoBranch != updatedRepoBranch) + { + repoBranch = updatedRepoBranch; + repoBranchContent = new GUIContent(repoBranch, Window_RepoBranchTooltip); } - if (repoDataChanged) + if (repoUrl != updatedRepoUrl) { - repoBranchContent = new GUIContent(repoBranch, Window_RepoBranchTooltip); + repoUrl = updatedRepoUrl; if (repoUrl != null) { - repoUrlContent = new GUIContent(repoUrl, string.Format(Window_RepoUrlTooltip, repoRemote)); + repoUrlContent = new GUIContent(repoUrl, string.Format(Window_RepoUrlTooltip, updatedRepoRemote)); } else { From a97787088cb5062b60c533e47b18d29d05d289ad Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 27 Oct 2017 12:06:59 -0400 Subject: [PATCH 3/3] Logic error --- src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs index 6664577cd..82ece2823 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs @@ -214,7 +214,7 @@ private void MaybeUpdateData() if (repoUrl != updatedRepoUrl) { repoUrl = updatedRepoUrl; - if (repoUrl != null) + if (updatedRepoRemote != null) { repoUrlContent = new GUIContent(repoUrl, string.Format(Window_RepoUrlTooltip, updatedRepoRemote)); }