Skip to content

Commit

Permalink
GE Debugger: Allow search by state name.
Browse files Browse the repository at this point in the history
Since adding breakpoint as the first column, the default search behavior
stopped working.  This restores it, searching for any matching column.
  • Loading branch information
unknownbrackets committed Sep 18, 2022
1 parent 5b5529b commit a0b44c5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Windows/W32Util/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,49 @@ int GenericListControl::HandleNotify(LPARAM lParam) {
return 0;
}

if (mhdr->code == LVN_INCREMENTALSEARCH) {
NMLVFINDITEM *request = (NMLVFINDITEM *)lParam;
uint32_t supported = LVFI_WRAP | LVFI_STRING | LVFI_PARTIAL | LVFI_SUBSTRING;
if ((request->lvfi.flags & ~supported) == 0 && (request->lvfi.flags & LVFI_STRING) != 0) {
bool wrap = (request->lvfi.flags & LVFI_WRAP) != 0;
bool partial = (request->lvfi.flags & (LVFI_PARTIAL | LVFI_SUBSTRING)) != 0;

// It seems like 0 is always sent for start, let's override.
int startRow = request->iStart;
if (startRow == 0)
startRow = GetSelectedIndex();
int result = OnIncrementalSearch(startRow, request->lvfi.psz, wrap, partial);
if (result != -1) {
request->lvfi.flags = LVFI_PARAM;
request->lvfi.lParam = (LPARAM)result;
}
}
}

return 0;
}

int GenericListControl::OnIncrementalSearch(int startRow, const wchar_t *str, bool wrap, bool partial) {
int size = GetRowCount();
size_t searchlen = wcslen(str);
if (!wrap)
size -= startRow;

// We start with the earliest column, preferring matches on the leftmost columns by default.
for (int c = 0; c < columnCount; ++c) {
for (int i = 0; i < size; ++i) {
int r = (startRow + i) % size;
stringBuffer[0] = 0;
GetColumnText(stringBuffer, r, c);
int difference = partial ? _wcsnicmp(str, stringBuffer, searchlen) : _wcsicmp(str, stringBuffer);
if (difference == 0)
return r;
}
}

return -1;
}

void GenericListControl::Update() {
if (!updateScheduled_) {
SetTimer(handle, IDT_UPDATE, UPDATE_DELAY, nullptr);
Expand Down
2 changes: 2 additions & 0 deletions Windows/W32Util/Misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class GenericListControl
virtual bool OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) { return false; }
virtual bool OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) { return false; }

virtual int OnIncrementalSearch(int startRow, const wchar_t *str, bool wrap, bool partial);

private:
static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void ProcessUpdate();
Expand Down

0 comments on commit a0b44c5

Please sign in to comment.