Skip to content

Commit

Permalink
added Delimiter Update into beNotified
Browse files Browse the repository at this point in the history
  • Loading branch information
daddel80 committed Aug 7, 2023
1 parent 9ec0431 commit 7e242b4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/MultiReplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification * notifyCode)
{
MultiReplace::onTextChanged();
MultiReplace::processTextChange(notifyCode);
MultiReplace::processLog();
}
}
break;
Expand Down
59 changes: 35 additions & 24 deletions src/MultiReplacePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bool MultiReplace::textModified = true;
HWND MultiReplace::s_hScintilla = nullptr;
HWND MultiReplace::s_hDlg = nullptr;
std::vector<MultiReplace::LogEntry> MultiReplace::logChanges;
MultiReplace* MultiReplace::instance = nullptr;


#pragma region Initialization
Expand Down Expand Up @@ -83,7 +84,7 @@ void MultiReplace::positionAndResizeControls(int windowWidth, int windowHeight)

ctrlMap[IDC_SCOPE_GROUP] = { 400, 105, 230, 100, WC_BUTTON, L"Scope", BS_GROUPBOX, NULL };
ctrlMap[IDC_ALL_TEXT_RADIO] = { 410, 125, 100, 20, WC_BUTTON, L"All Text", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, NULL };
ctrlMap[IDC_SELECTION_RADIO] = { 410, 150, 100, 20, WC_BUTTON, L"Selection", BS_AUTORADIOBUTTON | WS_TABSTOP, L"Selection works with 'Replace All' and 'Mark Matches'" };
ctrlMap[IDC_SELECTION_RADIO] = { 410, 150, 100, 20, WC_BUTTON, L"Selection", BS_AUTORADIOBUTTON | WS_TABSTOP, NULL };
ctrlMap[IDC_COLUMN_MODE_RADIO] = { 410, 175, 20, 20, WC_BUTTON, L"", BS_AUTORADIOBUTTON | WS_TABSTOP, NULL };
ctrlMap[IDC_COLUMN_NUM_STATIC] = { 426, 175, 30, 20, WC_STATIC, L"Col.:", SS_RIGHT, NULL };
ctrlMap[IDC_COLUMN_NUM_EDIT] = { 456, 175, 40, 20, WC_EDIT, NULL, ES_LEFT | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL , L"Columns: '1,3,5-12' (individuals, ranges)" };
Expand Down Expand Up @@ -1068,6 +1069,8 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
}
else {
isLongRunCancelled = true;
handleClearTextMarksButton();
handleClearDelimiterState();
}
}
break;
Expand Down Expand Up @@ -1130,17 +1133,15 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
{
setElementsState(columnRadioDependentElements, false);
setElementsState(selectionRadioDisabledButtons, true);
handleClearColumnMarks();
handleDelimiterPositions();
handleClearDelimiterState();
}
break;

case IDC_SELECTION_RADIO:
{
setElementsState(columnRadioDependentElements, false);
setElementsState(selectionRadioDisabledButtons, false);
handleClearColumnMarks();
handleDelimiterPositions();
handleClearDelimiterState();
}
break;

Expand All @@ -1154,7 +1155,7 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
case IDC_COLUMN_HIGHLIGHT_BUTTON:
{
if (!isColumnHighlighted) {
handleDelimiterPositions();
handleDelimiterPositions(DelimiterOperation::LoadAll);
if (!columnDelimiterData.columns.empty() && !columnDelimiterData.extendedDelimiter.empty()) {
handleHighlightColumnsInDocument();
LRESULT startPosition = ::SendMessage(_hScintilla, SCI_GETCURRENTPOS, 0, 0);
Expand Down Expand Up @@ -1198,14 +1199,14 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
case IDC_FIND_BUTTON:
case IDC_FIND_NEXT_BUTTON:
{
handleDelimiterPositions();
handleDelimiterPositions(DelimiterOperation::LoadAll);
handleFindNextButton();
}
break;

case IDC_FIND_PREV_BUTTON:
{
handleDelimiterPositions();
handleDelimiterPositions(DelimiterOperation::LoadAll);
handleFindPrevButton();
}
break;
Expand All @@ -1219,15 +1220,15 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
case IDC_REPLACE_ALL_SMALL_BUTTON:
case IDC_REPLACE_ALL_BUTTON:
{
handleDelimiterPositions();
handleDelimiterPositions(DelimiterOperation::LoadAll);
handleReplaceAllButton();
}
break;

case IDC_MARK_MATCHES_BUTTON:
case IDC_MARK_BUTTON:
{
handleDelimiterPositions();
handleDelimiterPositions(DelimiterOperation::LoadAll);
handleClearTextMarksButton();
handleMarkMatchesButton();
}
Expand Down Expand Up @@ -1502,7 +1503,7 @@ int MultiReplace::replaceString(const std::wstring& findText, const std::wstring
replaceCount++;

// Update Delimiter and Marking if enabled
handleDelimiterPositions();
// handleDelimiterPositions();

searchResult = performSearchForward(findTextUtf8, searchFlags, false, newPos);
}
Expand Down Expand Up @@ -2363,6 +2364,12 @@ bool MultiReplace::parseColumnAndDelimiterData() {
columnDelimiterData.columns = columns;
columnDelimiterData.extendedDelimiter = convertAndExtend(delimiterData, true);
columnDelimiterData.delimiterLength = columnDelimiterData.extendedDelimiter.length();

// Check delimiter data
if (columnDelimiterData.extendedDelimiter.empty()) {
showStatusMessage(L"Extended delimiter is empty", RGB(255, 0, 0));
return false;
}
return true;
}

Expand Down Expand Up @@ -2778,14 +2785,7 @@ void MultiReplace::updateDelimitersInDocument(SIZE_T lineNumber, ChangeType chan
}
}

void MultiReplace::handleDelimiterPositions() {
if (IsDlgButtonChecked(_hSelf, IDC_COLUMN_MODE_RADIO) != BST_CHECKED) {
lineDelimiterPositions.clear();
isLoggingEnabled = false;
textModified = false;
logChanges.clear(); // not really necessary
return;
}
void MultiReplace::handleDelimiterPositions(DelimiterOperation operation) {

int currentBufferID = (int)::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);

Expand All @@ -2804,16 +2804,27 @@ void MultiReplace::handleDelimiterPositions() {

if (eolLengthChanged) eolLength = updatedEolLength;

if (eolLengthChanged || currentBufferID != scannedDelimiterBufferID || lineDelimiterPositions.empty() || columnDelimiterData.delimiterChanged) {
isLoggingEnabled = true; // Enable detailed logging
findAllDelimitersInDocument();
scannedDelimiterBufferID = currentBufferID;
} else {
if (operation == DelimiterOperation::LoadAll) {
if (eolLengthChanged || currentBufferID != scannedDelimiterBufferID || lineDelimiterPositions.empty() || columnDelimiterData.delimiterChanged) {
isLoggingEnabled = true; // Enable detailed logging
findAllDelimitersInDocument();
scannedDelimiterBufferID = currentBufferID;
}
}
else if (operation == DelimiterOperation::Update) {
processLogForDelimiters();
textModified = false; // Reset the textModified flag after processing changes
}
}

void MultiReplace::handleClearDelimiterState() {
lineDelimiterPositions.clear();
isLoggingEnabled = false;
textModified = false;
logChanges.clear();
handleClearColumnMarks();
}

void MultiReplace::displayLogChangesInMessageBox() {

// Create a helper function to convert list to string
Expand Down
25 changes: 23 additions & 2 deletions src/MultiReplacePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ struct StartColumnInfo {
SIZE_T startColumnIndex;
};

enum class DelimiterOperation { LoadAll, Update };

enum class Direction { Up, Down };

typedef std::basic_string<TCHAR> generic_string;
Expand Down Expand Up @@ -137,7 +139,15 @@ class MultiReplace : public DockingDlgInterface
hFont(nullptr),
_hStatusMessage(nullptr),
_statusMessageColor(RGB(0, 0, 0))
{};
{
setInstance(this);
};

static MultiReplace* instance; // Static instance of the class

static void setInstance(MultiReplace* inst) {
instance = inst;
}

virtual void display(bool toShow = true) const {
DockingDlgInterface::display(toShow);
Expand Down Expand Up @@ -186,6 +196,16 @@ class MultiReplace : public DockingDlgInterface
textModified = true;
}

static void processLog() {
if (!isWindowOpen) {
return;
}

if (instance != nullptr) {
instance->handleDelimiterPositions(DelimiterOperation::Update);
}
}

enum class ChangeType { Insert, Delete, Modify };
struct LogEntry {
ChangeType changeType;
Expand Down Expand Up @@ -395,7 +415,8 @@ class MultiReplace : public DockingDlgInterface
void optimizeLogChanges();
void updateDelimitersInDocument(SIZE_T lineNumber, ChangeType changeType);
void processLogForDelimiters();
void handleDelimiterPositions();
void handleDelimiterPositions(DelimiterOperation operation);
void handleClearDelimiterState();
void displayLogChangesInMessageBox();


Expand Down

0 comments on commit 7e242b4

Please sign in to comment.