Skip to content

Commit

Permalink
ToolStatus searchbox tab unfocus
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Mar 31, 2024
1 parent 62c6cfd commit 7ccb384
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 54 deletions.
7 changes: 4 additions & 3 deletions plugins/ToolStatus/ToolStatus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
// TEXTINCLUDE
//

1 TEXTINCLUDE
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\0"
END

3 TEXTINCLUDE
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
Expand Down Expand Up @@ -156,6 +156,7 @@ END
IDR_MAINWND_ACCEL ACCELERATORS
BEGIN
"K", ID_SEARCH, VIRTKEY, CONTROL, NOINVERT
VK_TAB, ID_SEARCH_TAB, VIRTKEY, NOINVERT
END


Expand Down
118 changes: 68 additions & 50 deletions plugins/ToolStatus/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,67 @@ VOID NTAPI SearchControlCallback(
PhInvokeCallback(&SearchChangedEvent, (PVOID)SearchMatchHandle);
}

VOID SetSearchFocus(
_In_ HWND hWnd,
_In_ BOOLEAN Focus
)
{
if (SearchboxHandle && ToolStatusConfig.SearchBoxEnabled)
{
if (Focus)
{
if (SearchBoxDisplayMode == SEARCHBOX_DISPLAY_MODE_HIDEINACTIVE)
{
LONG dpiValue;

dpiValue = PhGetWindowDpi(hWnd);

if (!RebarBandExists(REBAR_BAND_ID_SEARCHBOX))
RebarBandInsert(REBAR_BAND_ID_SEARCHBOX, SearchboxHandle, PhGetDpi(180, dpiValue), 22);

if (!IsWindowVisible(SearchboxHandle))
ShowWindow(SearchboxHandle, SW_SHOW);
}

SetFocus(SearchboxHandle);
Edit_SetSel(SearchboxHandle, 0, -1);
}
else
{
HWND tnHandle;

// Return focus to the treelist.
if (tnHandle = GetCurrentTreeNewHandle())
{
ULONG tnCount = TreeNew_GetFlatNodeCount(tnHandle);

for (ULONG i = 0; i < tnCount; i++)
{
PPH_TREENEW_NODE node = TreeNew_GetFlatNode(tnHandle, i);

// Select the first visible node.
if (node->Visible)
{
SetFocus(tnHandle);
TreeNew_SetFocusNode(tnHandle, node);
TreeNew_SetMarkNode(tnHandle, node);
TreeNew_SelectRange(tnHandle, i, i);
break;
}
}
}
}
}
}

VOID ToggleSearchFocus(
_In_ HWND hWnd
)
{
// Check if the searchbox is already focused.
SetSearchFocus(hWnd, GetFocus() != SearchboxHandle);
}

LRESULT CALLBACK MainWndSubclassProc(
_In_ HWND hWnd,
_In_ UINT uMsg,
Expand Down Expand Up @@ -815,56 +876,13 @@ LRESULT CALLBACK MainWndSubclassProc(
}
break;
case ID_SEARCH:
{
// handle keybind Ctrl + K
if (SearchboxHandle && ToolStatusConfig.SearchBoxEnabled)
{
// Check if the searchbox is already focused.
if (GetFocus() == SearchboxHandle)
{
HWND tnHandle;

// Return focus to the treelist.
if (tnHandle = GetCurrentTreeNewHandle())
{
ULONG tnCount = TreeNew_GetFlatNodeCount(tnHandle);

for (ULONG i = 0; i < tnCount; i++)
{
PPH_TREENEW_NODE node = TreeNew_GetFlatNode(tnHandle, i);

// Select the first visible node.
if (node->Visible)
{
SetFocus(tnHandle);
TreeNew_SetFocusNode(tnHandle, node);
TreeNew_SetMarkNode(tnHandle, node);
TreeNew_SelectRange(tnHandle, i, i);
break;
}
}
}
}
else
{
if (SearchBoxDisplayMode == SEARCHBOX_DISPLAY_MODE_HIDEINACTIVE)
{
LONG dpiValue;

dpiValue = PhGetWindowDpi(hWnd);

if (!RebarBandExists(REBAR_BAND_ID_SEARCHBOX))
RebarBandInsert(REBAR_BAND_ID_SEARCHBOX, SearchboxHandle, PhGetDpi(180, dpiValue), 22);

if (!IsWindowVisible(SearchboxHandle))
ShowWindow(SearchboxHandle, SW_SHOW);
}

SetFocus(SearchboxHandle);
Edit_SetSel(SearchboxHandle, 0, -1);
}
}
}
// handle keybind Ctrl + K
ToggleSearchFocus(hWnd);
goto DefaultWndProc;
case ID_SEARCH_TAB:
// handle tab when the searchbox is focused
if (GetFocus() == SearchboxHandle)
SetSearchFocus(hWnd, FALSE);
goto DefaultWndProc;
case PHAPP_ID_VIEW_ALWAYSONTOP:
{
Expand Down
3 changes: 2 additions & 1 deletion plugins/ToolStatus/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@
#define IDC_ENABLE_AUTOCOMPLETE 1016
#define IDC_ENABLE_AUTOFOCUS_SEARCH 1017
#define ID_SEARCH 40011
#define ID_SEARCH_TAB 40012

// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 147
Expand Down

0 comments on commit 7ccb384

Please sign in to comment.