Skip to content

Commit

Permalink
refresh form on unhide, show open files @ 1st load
Browse files Browse the repository at this point in the history
Problems that this commit should solve:
1. Hiding or showing the form changing input focus in an unclear way
    (issue young-developer#53)
2. Nothing showing when the form is first loaded (issue young-developer#36)
3. When the form is reloaded, it showed out-of-date search results
    (e.g., it would show files in the top directory of a file that
    is no longer active)
    There was no associated issue for this, but it bugged me.
  • Loading branch information
molsonkiko committed Jul 14, 2023
1 parent 9293f7b commit 87ea359
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
12 changes: 10 additions & 2 deletions NppNavigateTo/Forms/FrmNavigateTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public FrmNavigateTo(IScintillaGateway editor, INotepadPPGateway notepad)
ReloadFileList();
this.notepad.ReloadMenuItems();
FormStyle.ApplyStyle(this, true, notepad.IsDarkModeEnabled());
FilterDataGrid("");
}

/// <summary>
Expand Down Expand Up @@ -617,11 +618,12 @@ private bool NavigateGridDown(bool isShiftPressed)
private void SearchComboBoxTextChanged(object sender, EventArgs e)
{
int textLength = searchComboBox.Text.Length;
bool emptyText = string.IsNullOrWhiteSpace(searchComboBox.Text);
int minLength = FrmSettings.Settings.GetIntSetting(Settings.minTypeCharLimit);

if (textLength == 0)
if (emptyText)
ReloadFileList();
if (textLength > minLength)
if (textLength > minLength || emptyText)
{
FilterDataGrid(searchComboBox.Text);
}
Expand Down Expand Up @@ -886,6 +888,12 @@ private void FrmNavigateAll_KeyPress(object sender, KeyPressEventArgs e)
}
}

public void GrabFocus()
{
searchComboBox.Select();
FilterDataGrid(searchComboBox.Text);
}

private void dataGridFileList_KeyPress(object sender, KeyPressEventArgs e)
{
searchComboBox.Focus();
Expand Down
2 changes: 1 addition & 1 deletion NppNavigateTo/Glob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public Regex Glob2Regex(string inp)
ii++;
}
endOfLoop:
if (uses_metacharacters) // anything without "*" or "?" or "[]" or
if (uses_metacharacters) // anything without any chars in "*?[]{}" will just be treated as a normal string
sb.Append('$'); // globs are anchored at the end; that is "*foo" does not match "foo/bar.txt" but "*foo.tx?" does
string pat = sb.ToString();
try
Expand Down
2 changes: 2 additions & 0 deletions NppNavigateTo/NppNavigateTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,15 @@ static void NavigateToDlg()
frmNavigateTo.Handle);
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SETMENUITEMCHECK,
PluginBase._funcItems.Items[idFormNavigateAll]._cmdID, 1);
frmNavigateTo.GrabFocus();
}
else
{
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMHIDE, 0,
frmNavigateTo.Handle);
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SETMENUITEMCHECK,
PluginBase._funcItems.Items[idFormNavigateAll]._cmdID, 0);
editor.GrabFocus();
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions NppNavigateTo/Tests/GlobTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ public static void Test()
("foo.jsonl", false),
("c:\\bar.txto", false),
}),
("*.p* !< __ | \\j", new[]
{
("bep.po", true),
("joo.po", true),
("boo\\joo.po", false),
("bbq.go", false),
("__bzz.po", false),
("boo\\j__.po", false),
("boo__\\eorpwn\\reiren.po", false),
("Z:\\jnq\\eorpwn\\reiren.po", false),
}),
};
var glob = new Glob();
foreach ((string query, var examples) in testcases)
Expand Down

0 comments on commit 87ea359

Please sign in to comment.