Skip to content

Commit

Permalink
Feature notepad-plus-plus#685 progress bar in search dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyk24 committed Jun 6, 2017
1 parent 6b0977b commit b43fe2e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
33 changes: 32 additions & 1 deletion PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp
Expand Up @@ -703,6 +703,8 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
_findClosePos.left = p.x;
_findClosePos.top = p.y + 10;

::SendMessage(GetDlgItem(_hSelf, IDC_PROGRESSBAR), PBM_SETPOS, (WPARAM)0, 0);

NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
generic_string tip2show = pNativeSpeaker->getLocalizedStrFromID("shift-change-direction-tip");
if (tip2show.empty())
Expand Down Expand Up @@ -1749,7 +1751,8 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
if (op == ProcessReplaceAll || op == ProcessFindAll)
flags |= SCFIND_REGEXP_EMPTYMATCH_NOTAFTERMATCH;


::SendMessage(GetDlgItem(_hSelf, IDC_PROGRESSBAR), PBM_SETPOS, (WPARAM)0, 0);
const clock_t beginTime = clock();

if (op == ProcessMarkAll && colourStyleID == -1) //if marking, check if purging is needed
{
Expand Down Expand Up @@ -1786,6 +1789,33 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
int foundTextLen = targetEnd - targetStart;
int replaceDelta = 0;

// Update progress information
if (nbProcessed % 1000 == 0)
{
double progress = 100.0*double(targetStart) / double(findReplaceInfo._endRange);
::SendMessage(GetDlgItem(_hSelf, IDC_PROGRESSBAR), PBM_SETPOS, (WPARAM)int(progress), 0);

double elapsedSeconds = double(clock() - beginTime) / CLOCKS_PER_SEC;
if (progress > 1.0)
{
double onePercentElapsedTime = elapsedSeconds / progress;
double remainingSeconds = onePercentElapsedTime* (100.0 - progress);
generic_string result;

TCHAR moreInfo[64];
if (remainingSeconds < 60.0)
wsprintf(moreInfo, TEXT("Remaining time: %d seconds"), int(remainingSeconds));
else
{
int nRemainingMinutes = int(remainingSeconds / 60.0);
int nRemainingSeconds = int(remainingSeconds) % 60;
wsprintf(moreInfo, TEXT("Remaining time: %d minutes %d seconds"), nRemainingMinutes, nRemainingSeconds);
}
result = moreInfo;

setStatusbarMessage(result, FSMessage);
}
}

switch (op)
{
Expand Down Expand Up @@ -1967,6 +1997,7 @@ int FindReplaceDlg::processRange(ProcessOperation op, FindReplaceInfo & findRepl
findReplaceInfo._endRange += replaceDelta; //adjust end of range in case of replace
}

::SendMessage(GetDlgItem(_hSelf, IDC_PROGRESSBAR), PBM_SETPOS, (WPARAM)100, 0);
delete [] pTextFind;
delete [] pTextReplace;

Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScitillaComponent/FindReplaceDlg.h
Expand Up @@ -171,7 +171,7 @@ protected :
};

bool isLineActualSearchResult(const generic_string & s) const;
generic_string & prepareStringForClipboard(generic_string & s) const;
generic_string & prepareStringForClipboard(generic_string & s) const;

static FoundInfo EmptyFoundInfo;
static SearchResultMarking EmptySearchResultMarking;
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc
Expand Up @@ -85,6 +85,8 @@ BEGIN
CONTROL "Always",IDC_TRANSPARENT_ALWAYS_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,268,155,85,10
CONTROL "",IDC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | NOT WS_VISIBLE | WS_TABSTOP,265,166,85,10
CONTROL "&. matches newline",IDREDOTMATCHNL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,93,167,68,9
CONTROL "" , IDC_PROGRESSBAR, "msctls_progress32" , PBS_SMOOTH , 5, 180, 356, 5

END

IDB_INCREMENTAL_BG BITMAP "../icons/incrementalBg.bmp"
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h
Expand Up @@ -134,5 +134,6 @@
#define IDEXTENDED_FIFOLDER 1718
#define IDREGEXP_FIFOLDER 1719
#define IDREDOTMATCHNL_FIFOLDER 1720
#define IDC_PROGRESSBAR 1722

#endif //FINDREPLACE_DLG_H

0 comments on commit b43fe2e

Please sign in to comment.