Skip to content

Commit

Permalink
Set focus better on Ctrl+F
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Oct 11, 2024
1 parent 0809104 commit 72931c1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
23 changes: 12 additions & 11 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions GUI/ISearchableControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CKAN.GUI
{
public interface ISearchableControl
{
void FocusSearch(bool expandCollapse = false);
}
}
32 changes: 32 additions & 0 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,38 @@ protected override void OnMove(EventArgs e)
ManageMods?.ParentMoved();
}

private IEnumerable<T> VisibleControls<T>()
=> (MainTabControl?.SelectedTab
?.Controls
.OfType<T>()
?? Enumerable.Empty<T>())
.Concat(!splitContainer1.Panel2Collapsed
&& ModInfo is T t
? Enumerable.Repeat(t, 1)
: Enumerable.Empty<T>());

protected override void OnKeyDown(KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Control | Keys.F:
VisibleControls<ISearchableControl>()
.FirstOrDefault()
?.FocusSearch(false);
e.Handled = true;
break;
case Keys.Control | Keys.Shift | Keys.F:
VisibleControls<ISearchableControl>()
.FirstOrDefault()
?.FocusSearch(true);
e.Handled = true;
break;
default:
base.OnKeyDown(e);
break;
}
}

private void SetupDefaultSearch()
{
if (CurrentInstance != null && configuration != null)
Expand Down

0 comments on commit 72931c1

Please sign in to comment.