From e073715c0d56352b6e4bb34e0b30b0a443e6537f Mon Sep 17 00:00:00 2001 From: Logan Higinbotham Date: Sat, 10 Oct 2020 15:09:22 -0400 Subject: [PATCH] Fixes #8146 "Keyboard navigation : Enter Key should open a recent repository" --- .../DashboardControl/UserRepositoriesList.cs | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs index ee1f8426638..6e865e0be39 100644 --- a/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs +++ b/GitUI/CommandsDialogs/BrowseDialog/DashboardControl/UserRepositoriesList.cs @@ -330,6 +330,20 @@ protected virtual void OnModuleChanged(GitModuleEventArgs args) handler?.Invoke(this, args); } + protected override bool ProcessDialogKey(Keys keyData) + { + if (keyData == Keys.Enter) + { + // .NET 5.0 introduced collapsible `ListViewGoup`s, which we do not yet have API access to but still get rendered in the UI. + // Whenever the list of repos is collapsed but we still have a repo selected (and hidden), if we hit enter, the selected repo will + // be opened. This should be a no-op instead, however, since we cannot visually tell what repo is selected. When we upgrade + // to .NET 5.0, we can check ListViewGroup.CollapsedState to fix this issue. + return TryOpenSelectedRepository(); + } + + return base.ProcessDialogKey(keyData); + } + private List GetCategories() { return GetRepositories() @@ -587,23 +601,7 @@ private void listView1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { - var selected = GetSelectedRepository(); - if (selected == null) - { - return; - } - - if (_controller.IsValidGitWorkingDir(selected.Path)) - { - OnModuleChanged(new GitModuleEventArgs(new GitModule(selected.Path))); - return; - } - - if (_controller.RemoveInvalidRepository(selected.Path)) - { - ShowRecentRepositories(); - return; - } + TryOpenSelectedRepository(); } else if (e.Button == MouseButtons.Right) { @@ -862,5 +860,29 @@ private void OnDragEnter(object sender, DragEventArgs e) } } } + + // returns false only if no repository is selected + private bool TryOpenSelectedRepository() + { + var selected = GetSelectedRepository(); + if (selected == null) + { + return false; + } + + if (_controller.IsValidGitWorkingDir(selected.Path)) + { + OnModuleChanged(new GitModuleEventArgs(new GitModule(selected.Path))); + return true; + } + + if (_controller.RemoveInvalidRepository(selected.Path)) + { + ShowRecentRepositories(); + return true; + } + + return true; + } } }