Repeating a character in search will jump to next element starting with this character only at the beginning of the search

Means repeating a character in the middle of a search the character will be appended to the search string instead of jumping to next element (as this would prevent searching for any item which has same characters twice next to each other)

Fixes #30 https://github.com/Hofknecht/SystemTrayMenu/issues/30
This commit is contained in:
Peter Kirmeier 2019-07-19 18:58:16 +02:00
parent 04396f7134
commit 381dc3c8a0

View file

@ -21,8 +21,8 @@ namespace SystemTrayMenu
#endregion
class SystemTrayMenuHandler : IDisposable
{
Logger log = new Logger(nameof(SystemTrayMenuHandler));
Logger log = new Logger(nameof(SystemTrayMenuHandler));
IShellDispatch4 iShellDispatch4 = null;
KeyboardHook hook = new KeyboardHook();
@ -47,9 +47,9 @@ namespace SystemTrayMenu
GetName().Version.ToString() +
$" ScalingFactor={Program.ScalingFactor}");
try
{
iShellDispatch4 = (IShellDispatch4)Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
try
{
iShellDispatch4 = (IShellDispatch4)Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
}
catch (Exception ex)
{
@ -413,16 +413,16 @@ namespace SystemTrayMenu
bool HideHiddenEntries = false;
bool HideSystemEntries = false;
if (null != iShellDispatch4)
{
// Using SHGetSetSettings would be much better in performance but the results are not accurate.
// We have to go for the shell interface in order to receive the correct settings:
// https://docs.microsoft.com/en-us/windows/win32/shell/ishelldispatch4-getsetting
const int SSF_SHOWALLOBJECTS = 0x00000001;
const int SSF_SHOWSUPERHIDDEN = 0x00040000;
HideHiddenEntries = !iShellDispatch4.GetSetting(SSF_SHOWALLOBJECTS);
HideSystemEntries = !iShellDispatch4.GetSetting(SSF_SHOWSUPERHIDDEN);
if (null != iShellDispatch4)
{
// Using SHGetSetSettings would be much better in performance but the results are not accurate.
// We have to go for the shell interface in order to receive the correct settings:
// https://docs.microsoft.com/en-us/windows/win32/shell/ishelldispatch4-getsetting
const int SSF_SHOWALLOBJECTS = 0x00000001;
const int SSF_SHOWSUPERHIDDEN = 0x00040000;
HideHiddenEntries = !iShellDispatch4.GetSetting(SSF_SHOWALLOBJECTS);
HideSystemEntries = !iShellDispatch4.GetSetting(SSF_SHOWSUPERHIDDEN);
}
MenuData menuData = new MenuData();
@ -451,17 +451,17 @@ namespace SystemTrayMenu
break;
}
if (HideHiddenEntries || HideSystemEntries) // filter entries..
{
FileAttributes attributes = File.GetAttributes(directory);
if (HideHiddenEntries) // filter hidden files..
{
if (attributes.HasFlag(FileAttributes.Hidden))
if (HideHiddenEntries || HideSystemEntries) // filter entries..
{
FileAttributes attributes = File.GetAttributes(directory);
if (HideHiddenEntries) // filter hidden files..
{
if (attributes.HasFlag(FileAttributes.Hidden))
continue;
}
if (HideSystemEntries) // filter system files..
{
if (attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) // both must be set to be hidden!
}
if (HideSystemEntries) // filter system files..
{
if (attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) // both must be set to be hidden!
continue;
}
}
@ -502,17 +502,17 @@ namespace SystemTrayMenu
if (worker != null && worker.CancellationPending)
break;
if (HideHiddenEntries || HideSystemEntries) // filter entries..
{
FileAttributes attributes = File.GetAttributes(file);
if (HideHiddenEntries) // filter hidden files..
{
if (attributes.HasFlag(FileAttributes.Hidden))
if (HideHiddenEntries || HideSystemEntries) // filter entries..
{
FileAttributes attributes = File.GetAttributes(file);
if (HideHiddenEntries) // filter hidden files..
{
if (attributes.HasFlag(FileAttributes.Hidden))
continue;
}
if (HideSystemEntries) // filter system files..
{
if (attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) // both must be set to be hidden!
}
if (HideSystemEntries) // filter system files..
{
if (attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)) // both must be set to be hidden!
continue;
}
}
@ -780,14 +780,13 @@ namespace SystemTrayMenu
if (string.IsNullOrEmpty(KeySearchString))
{
// no search string set, start new search
// no search string set, start new search with initial letter
KeySearchString += letter;
SelectByKey(Keys.None, KeySearchString);
}
else if (KeySearchString.LastOrDefault().ToString() == letter)
else if (KeySearchString.Length == 1 && KeySearchString.LastOrDefault().ToString() == letter)
{
// previous letter pressed again, jump to next element
KeySearchString += letter;
// initial letter pressed again, jump to next element
SelectByKey(Keys.None, letter);
}
else