Skip to content

Commit 0795eb0

Browse files
committed
Add textbox for filtering the list of snippets
1 parent cffe7c7 commit 0795eb0

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

DlgConsole.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@
5050

5151
static HWND s_hDlg = NULL; // The HWND to the dialog
5252
static HWND s_hList = NULL; // The HWND to the listbox
53+
static HWND s_hFilter = NULL; // The HWND to the filter editbox
5354
static HWND s_hCombo = NULL; // The HWND to the combo
5455
static WNDPROC s_hListboxProcOld = NULL; // The HWND to the original procedure of the listbox
5556
static HICON s_hTabIcon = NULL; // The icon on the docking tab
5657
static HBRUSH s_hbrBkgnd = NULL; // The brush to paint the theme on the background of the listbox
5758
static int s_iHeightCombo = 20; // This info should come from Windows
59+
static int s_iHeightFilter = 20; // This info should come from Windows
5860
static bool s_bConsoleInitialized = false; // Is the console initialized?
5961
static bool s_bConsoleVisible = false; // Is the console visible?
6062
static Library* s_curLibrary = NULL; // The currently selected lib
@@ -462,8 +464,17 @@ static void IndentSnippet(int firstLine, int lastLine)
462464
static void OnSize(HWND hWnd, int iWidth, int iHeight)
463465
{
464466
UNREFERENCED_PARAMETER(hWnd);
465-
SetWindowPos(s_hList, 0, 0, s_iHeightCombo + SPACER, iWidth, iHeight - s_iHeightCombo - SPACER, SWP_NOACTIVATE | SWP_NOZORDER);
467+
468+
// Position the languages combobox
466469
SetWindowPos(s_hCombo, 0, 0, 0, iWidth, s_iHeightCombo, SWP_NOACTIVATE | SWP_NOZORDER);
470+
471+
// Position the filter editbox
472+
const int iFilterX = s_iHeightCombo + SPACER;
473+
SetWindowPos(s_hFilter, 0, 0, iFilterX, iWidth, s_iHeightFilter, SWP_NOACTIVATE | SWP_NOZORDER);
474+
475+
// Position the list of snippets
476+
const int iListX = iFilterX + s_iHeightFilter + SPACER;
477+
SetWindowPos(s_hList, 0, 0, iListX, iWidth, iHeight - iListX, SWP_NOACTIVATE | SWP_NOZORDER);
467478
}
468479

469480
/////////////////////////////////////////////////////////////////////////////
@@ -1160,12 +1171,17 @@ static BOOL OnInitDialog(HWND hWnd)
11601171
// Store the DlgItems
11611172
s_hList = GetDlgItem(hWnd, IDC_LIST);
11621173
s_hCombo = GetDlgItem(hWnd, IDC_NAME);
1174+
s_hFilter = GetDlgItem(hWnd, IDC_FILTER);
11631175

1164-
// Get the height of the combobox
1176+
// Get the height of the languages combobox
11651177
RECT rc;
11661178
GetWindowRect(s_hCombo, &rc);
11671179
s_iHeightCombo = rc.bottom - rc.top;
11681180

1181+
// Get the height of the filter editbox
1182+
GetWindowRect(s_hFilter, &rc);
1183+
s_iHeightFilter = rc.bottom - rc.top;
1184+
11691185
// Use our own ListboxProc to intercept the ENTER-key
11701186
s_hListboxProcOld = (WNDPROC)SetWindowLongPtr(s_hList, GWLP_WNDPROC, (LONG_PTR)ListboxProc);
11711187

NppSnippets_res.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ CAPTION "Snippets"
8484
FONT 8, "MS Shell Dlg", 400, 0, 0x1
8585
BEGIN
8686
COMBOBOX IDC_NAME, 0, 0, 77, 30, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
87+
EDITTEXT IDC_FILTER, 0, 7, 77, 14, ES_AUTOVSCROLL | ES_AUTOHSCROLL
8788
LISTBOX IDC_LIST, 0, 7, 186, 90, LBS_NOTIFY | WS_VSCROLL | WS_BORDER
8889
END
8990

Resource.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef RESOURCE_H
22
#define RESOURCE_H
33

4-
#ifndef IDC_STATIC
4+
#ifndef IDC_STATIC
55
#define IDC_STATIC -1
66
#endif
77

@@ -16,7 +16,8 @@
1616
// Snippets Console/Main dialog
1717
#define IDD_SNIPPETS 3000
1818
#define IDC_LIST 3001
19-
#define IDC_NAME 3002
19+
#define IDC_FILTER 3002
20+
#define IDC_NAME 3003
2021

2122
// Edit Snippet dialog
2223
#define IDD_EDIT_SNIPPET 3100

0 commit comments

Comments
 (0)