diff --git a/GUI/Controls/ManageMods.cs b/GUI/Controls/ManageMods.cs index efa016c91..9f7d2ae6e 100644 --- a/GUI/Controls/ManageMods.cs +++ b/GUI/Controls/ManageMods.cs @@ -19,7 +19,7 @@ namespace CKAN.GUI #if NET5_0_OR_GREATER [SupportedOSPlatform("windows")] #endif - public partial class ManageMods : UserControl + public partial class ManageMods : UserControl, ISearchableControl { public ManageMods() { @@ -1900,17 +1900,8 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch (keyData) { - case Keys.Control | Keys.F: - ActiveControl = EditModSearches; - return true; - - case Keys.Control | Keys.Shift | Keys.F: - EditModSearches.ExpandCollapse(); - ActiveControl = EditModSearches; - return true; - case Keys.Control | Keys.S: - if (ChangeSet != null && ChangeSet.Any()) + if (ChangeSet != null && ChangeSet.Count != 0) { ApplyToolButton_Click(null, null); } @@ -1921,6 +1912,16 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) return base.ProcessCmdKey(ref msg, keyData); } + public void FocusSearch(bool expandCollapse = false) + { + ActiveControl = EditModSearches; + EditModSearches.Focus(); + if (expandCollapse) + { + EditModSearches.ExpandCollapse(); + } + } + public bool AllowClose() { if (Conflicts != null && Conflicts.Count != 0) diff --git a/GUI/ISearchableControl.cs b/GUI/ISearchableControl.cs new file mode 100644 index 000000000..e22b5178c --- /dev/null +++ b/GUI/ISearchableControl.cs @@ -0,0 +1,7 @@ +namespace CKAN.GUI +{ + public interface ISearchableControl + { + void FocusSearch(bool expandCollapse = false); + } +} diff --git a/GUI/Main/Main.cs b/GUI/Main/Main.cs index 8e3ea4149..978a3ef7b 100644 --- a/GUI/Main/Main.cs +++ b/GUI/Main/Main.cs @@ -611,6 +611,38 @@ protected override void OnMove(EventArgs e) ManageMods?.ParentMoved(); } + private IEnumerable VisibleControls() + => (MainTabControl?.SelectedTab + ?.Controls + .OfType() + ?? Enumerable.Empty()) + .Concat(!splitContainer1.Panel2Collapsed + && ModInfo is T t + ? Enumerable.Repeat(t, 1) + : Enumerable.Empty()); + + protected override void OnKeyDown(KeyEventArgs e) + { + switch (e.KeyData) + { + case Keys.Control | Keys.F: + VisibleControls() + .FirstOrDefault() + ?.FocusSearch(false); + e.Handled = true; + break; + case Keys.Control | Keys.Shift | Keys.F: + VisibleControls() + .FirstOrDefault() + ?.FocusSearch(true); + e.Handled = true; + break; + default: + base.OnKeyDown(e); + break; + } + } + private void SetupDefaultSearch() { if (CurrentInstance != null && configuration != null)