Skip to content

Commit d9fea6e

Browse files
committed
improve result tip to show match texts left aligned
* `%30s` adds space prefix if the length < 30, remove width specification * show the match with a prefix context, in case of at a long line end, even offset > 259 * in content mode, show content starting from the line pointed to * increase the max picked length to 50
1 parent e779261 commit d9fea6e

25 files changed

+85
-71
lines changed

src/Resources/grepWin.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ BEGIN
396396
IDS_COPYRESULT "Copy text result to clipboard"
397397
IDS_COPYRESULTS "Copy text results to clipboard"
398398
IDS_XMOREMATCHES "%ld more matches"
399-
IDS_CONTEXTLINE "Line %5ld : %30s\n"
399+
IDS_CONTEXTLINE "Line %5ld : %s\n"
400400
IDS_INFOLABELFILE "scanning file '%s'"
401401
IDS_ERR_RELATIVEPATH "Relative paths are not allowed. Please enter an absolute path!"
402402
IDS_ERR_INVALID_PATH "Invalid path!"

src/SearchDlg.cpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,37 +2695,51 @@ void CSearchDlg::DoListNotify(LPNMITEMACTIVATE lpNMItemActivate)
26952695
}
26962696
else if (lpNMItemActivate->hdr.code == LVN_GETINFOTIP)
26972697
{
2698-
NMLVGETINFOTIP* pInfoTip = reinterpret_cast<NMLVGETINFOTIP*>(lpNMItemActivate);
2698+
NMLVGETINFOTIP* pInfoTip = reinterpret_cast<NMLVGETINFOTIP*>(lpNMItemActivate);
26992699

2700-
// Which item number?
2701-
size_t itemId = pInfoTip->iItem;
2702-
int iItem = GetSelectedListIndex(static_cast<int>(itemId));
2703-
pInfoTip->pszText[0] = 0;
2704-
if (static_cast<int>(m_items.size()) > iItem)
2700+
size_t listIndex = pInfoTip->iItem;
2701+
auto tup = m_listItems[listIndex];
2702+
int iItem = std::get<0>(tup);
2703+
CSearchInfo& inf = m_items[iItem];
2704+
int subIndex = 0;
2705+
2706+
bool fileList = (IsDlgButtonChecked(*this, IDC_RESULTFILES) == BST_CHECKED);
2707+
2708+
if (!fileList)
27052709
{
2706-
CSearchInfo& inf = m_items[iItem];
2710+
subIndex = std::get<1>(tup);
2711+
}
27072712

2708-
std::wstring matchString = inf.filePath + L"\n";
2709-
if (!inf.exception.empty())
2710-
{
2711-
matchString += inf.exception;
2712-
matchString += L"\n";
2713-
}
2714-
std::wstring sFormat = TranslatedString(hResource, IDS_CONTEXTLINE);
2715-
for (size_t i = 0; i < min(inf.matchLines.size(), 5); ++i)
2716-
{
2717-
std::wstring matchText = inf.matchLines[i];
2718-
CStringUtils::trim(matchText);
2719-
matchString += CStringUtils::Format(sFormat.c_str(), inf.matchLinesNumbers[i], matchText.c_str());
2720-
}
2721-
if (inf.matchLines.size() > 5)
2713+
std::wstring matchString = inf.filePath + L"\n";
2714+
if (!inf.exception.empty())
2715+
{
2716+
matchString += inf.exception;
2717+
matchString += L"\n";
2718+
}
2719+
2720+
std::wstring sFormat = TranslatedString(hResource, IDS_CONTEXTLINE);
2721+
int leftMax = static_cast<int>(inf.matchLines.size());
2722+
int showMax = min(leftMax, subIndex + 5);
2723+
for (; subIndex < showMax; ++subIndex)
2724+
{
2725+
std::wstring matchText = inf.matchLines[subIndex];
2726+
CStringUtils::rtrim(matchText);
2727+
DWORD iShow = 0;
2728+
if (inf.matchMovesNumbers[subIndex] > 8)
27222729
{
2723-
std::wstring sx = TranslatedString(hResource, IDS_XMOREMATCHES);
2724-
std::wstring ssx = CStringUtils::Format(sx.c_str(), static_cast<int>(inf.matchLines.size() - 5));
2725-
matchString += ssx;
2730+
// 6 + 1 prefix chars would give a context
2731+
iShow = inf.matchMovesNumbers[subIndex] - 8;
27262732
}
2727-
wcsncpy_s(pInfoTip->pszText, pInfoTip->cchTextMax, matchString.c_str(), pInfoTip->cchTextMax - 1LL);
2733+
matchString += CStringUtils::Format(sFormat.c_str(), inf.matchLinesNumbers[subIndex], matchText.substr(iShow, 50).c_str());
2734+
}
2735+
leftMax -= subIndex;
2736+
if (leftMax > 0)
2737+
{
2738+
std::wstring sx = TranslatedString(hResource, IDS_XMOREMATCHES);
2739+
std::wstring ssx = CStringUtils::Format(sx.c_str(), leftMax);
2740+
matchString += ssx;
27282741
}
2742+
wcsncpy_s(pInfoTip->pszText, pInfoTip->cchTextMax, matchString.c_str(), pInfoTip->cchTextMax - 1LL);
27292743
}
27302744
else if (lpNMItemActivate->hdr.code == LVN_GETDISPINFO)
27312745
{

translations/Afrikaans.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ msgstr "Lyn"
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
315-
msgstr "Lyn %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315+
msgstr "Lyn %5ld : %s\n"
316316

317317
#. Resource IDs: (135)
318318
msgid "Matches"

translations/Belarusian.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ msgstr "Радок"
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
315-
msgstr "Радок %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315+
msgstr "Радок %5ld : %s\n"
316316

317317
#. Resource IDs: (135)
318318
msgid "Matches"

translations/Chinese Simplified.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ msgstr "行号"
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
315-
msgstr "行 %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315+
msgstr "行 %5ld : %s\n"
316316

317317
#. Resource IDs: (135)
318318
msgid "Matches"

translations/Chinese Traditional.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ msgstr "行號"
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
315-
msgstr "行 %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315+
msgstr "行 %5ld : %s\n"
316316

317317
#. Resource IDs: (135)
318318
msgid "Matches"

translations/Dutch.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ msgstr "Regel"
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
315-
msgstr "Regel %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315+
msgstr "Regel %5ld : %s\n"
316316

317317
#. Resource IDs: (135)
318318
msgid "Matches"

translations/English.lang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ msgstr ""
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315315
msgstr ""
316316

317317
#. Resource IDs: (135)

translations/French.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ msgstr "Ligne"
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
315-
msgstr "Ligne %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315+
msgstr "Ligne %5ld : %s\n"
316316

317317
#. Resource IDs: (135)
318318
msgid "Matches"

translations/German.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ msgstr "Zeile"
311311

312312
#. Resource IDs: (150)
313313
#, c-format
314-
msgid "Line %5ld : %30s\n"
315-
msgstr "Zeile %5ld : %30s\n"
314+
msgid "Line %5ld : %s\n"
315+
msgstr "Zeile %5ld : %s\n"
316316

317317
#. Resource IDs: (135)
318318
msgid "Matches"

0 commit comments

Comments
 (0)