Skip to content

Commit

Permalink
added Element State handling
Browse files Browse the repository at this point in the history
  • Loading branch information
daddel80 committed Aug 6, 2023
1 parent e6144f7 commit ccba292
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
60 changes: 53 additions & 7 deletions src/MultiReplacePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,21 +1128,27 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
break;

case IDC_ALL_TEXT_RADIO:
{
setElementsState(columnRadioDependentElements, false);
setElementsState(selectionRadioDisabledButtons, true);
handleClearColumnMarks();
handleDelimiterPositions();
}
break;

case IDC_SELECTION_RADIO:
{
EnableWindow(GetDlgItem(_hSelf, IDC_COLUMN_NUM_EDIT), FALSE);
EnableWindow(GetDlgItem(_hSelf, IDC_DELIMITER_EDIT), FALSE);
EnableWindow(GetDlgItem(_hSelf, IDC_COLUMN_HIGHLIGHT_BUTTON), FALSE);
setElementsState(columnRadioDependentElements, false);
setElementsState(selectionRadioDisabledButtons, false);
handleClearColumnMarks();
handleDelimiterPositions();
}
break;

case IDC_COLUMN_MODE_RADIO:
{
EnableWindow(GetDlgItem(_hSelf, IDC_COLUMN_NUM_EDIT), TRUE);
EnableWindow(GetDlgItem(_hSelf, IDC_DELIMITER_EDIT), TRUE);
EnableWindow(GetDlgItem(_hSelf, IDC_COLUMN_HIGHLIGHT_BUTTON), TRUE);
setElementsState(columnRadioDependentElements, true);
setElementsState(selectionRadioDisabledButtons, true);
}
break;

Expand Down Expand Up @@ -3178,7 +3184,7 @@ void MultiReplace::displayProgressInStatus(LRESULT current, LRESULT total, const
static std::wstring lastProgressBarMessage;
static bool showProgressBar = false;

if (current == 2) {
if (current == 0) {
// Reset the progress bar and decision when a new process starts
progressDisplayActive = total >= 100;

Expand All @@ -3193,6 +3199,9 @@ void MultiReplace::displayProgressInStatus(LRESULT current, LRESULT total, const

// Update the action description message
::SetWindowText(GetDlgItem(_hSelf, IDC_ACTION_DESCRIPTION), message.c_str());

// Disable all elements except the Cancel Long Run button
setElementsState(allElementsExceptCancelLongRun, false, true);
}

if (progressDisplayActive) {
Expand Down Expand Up @@ -3224,6 +3233,9 @@ void MultiReplace::resetProgressBar() {

// Show the status message control
ShowWindow(GetDlgItem(_hSelf, IDC_STATUS_MESSAGE), SW_SHOW);

// Enable all elements except the Cancel Long Run button
setElementsState(allElementsExceptCancelLongRun, true, true);
}

LRESULT MultiReplace::updateEOLLength() {
Expand All @@ -3246,6 +3258,40 @@ LRESULT MultiReplace::updateEOLLength() {
return currentEolLength;
}

void MultiReplace::setElementsState(const std::vector<int>& elements, bool enable, bool restoreOriginalState) {
// Store the state and disable the elements if restoreOriginalState is true and enable is false
if (restoreOriginalState && !enable) {
for (int id : elements) {
bool isEnabled = IsWindowEnabled(GetDlgItem(_hSelf, id));
stateSnapshot[id] = isEnabled;
// Disable the current element
EnableWindow(GetDlgItem(_hSelf, id), FALSE);
}
}
// Enable or disable the elements if restoreOriginalState is false
else if (!restoreOriginalState) {
for (int id : elements) {
if (enable) {
// Enable the current element
EnableWindow(GetDlgItem(_hSelf, id), TRUE);
}
else {
// Disable the current element
EnableWindow(GetDlgItem(_hSelf, id), FALSE);
}
}
}

// Restore the state if restoreOriginalState is true and enable is true
if (restoreOriginalState && enable) {
for (const auto& item : stateSnapshot) {
EnableWindow(GetDlgItem(_hSelf, item.first), item.second ? TRUE : FALSE);
}
// Clear the snapshot after restoring it
stateSnapshot.clear();
}
}

#pragma endregion


Expand Down
27 changes: 26 additions & 1 deletion src/MultiReplacePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,32 @@ class MultiReplace : public DockingDlgInterface
bool isColumnHighlighted = false;
int scannedDelimiterBufferID = -1;
std::string messageBoxContent; // just for temporyry debugging usage
bool isLongRunCancelled = false;
std::atomic<bool> isLongRunCancelled = false;
bool progressDisplayActive = false;
std::map<int, bool> stateSnapshot; // map to store the state

const std::vector<int> allElementsExceptCancelLongRun = {
IDC_FIND_EDIT, IDC_REPLACE_EDIT, IDC_SEARCH_MODE_GROUP, IDC_NORMAL_RADIO, IDC_EXTENDED_RADIO,
IDC_REGEX_RADIO, IDC_ALL_TEXT_RADIO, IDC_SELECTION_RADIO, IDC_COLUMN_MODE_RADIO,
IDC_DELIMITER_EDIT, IDC_COLUMN_NUM_EDIT, IDC_DELIMITER_STATIC, IDC_COLUMN_NUM_STATIC,
IDC_SWAP_BUTTON, IDC_REPLACE_LIST, IDC_COPY_TO_LIST_BUTTON,IDC_REPLACE_ALL_SMALL_BUTTON,
IDC_USE_LIST_CHECKBOX,IDC_STATIC_FRAME, IDC_STATIC_FIND, IDC_STATIC_REPLACE, IDC_COLUMN_HIGHLIGHT_BUTTON,
IDC_SCOPE_GROUP, IDC_MATCH_CASE_CHECKBOX, IDC_WHOLE_WORD_CHECKBOX, IDC_WRAP_AROUND_CHECKBOX,
IDC_LOAD_FROM_CSV_BUTTON, IDC_SAVE_TO_CSV_BUTTON,
IDC_CLEAR_MARKS_BUTTON, IDC_UP_BUTTON, IDC_DOWN_BUTTON, IDC_SHIFT_FRAME,
IDC_SHIFT_TEXT, IDC_STATUS_MESSAGE, IDC_EXPORT_BASH_BUTTON,
IDC_2_BUTTONS_MODE, IDC_FIND_BUTTON, IDC_FIND_NEXT_BUTTON, IDC_FIND_PREV_BUTTON,
IDC_REPLACE_BUTTON, IDC_REPLACE_ALL_BUTTON, IDC_MARK_BUTTON, IDC_MARK_MATCHES_BUTTON,
IDC_COPY_MARKED_TEXT_BUTTON
};

const std::vector<int> selectionRadioDisabledButtons = {
IDC_FIND_BUTTON, IDC_FIND_NEXT_BUTTON, IDC_FIND_PREV_BUTTON, IDC_REPLACE_BUTTON
};

const std::vector<int> columnRadioDependentElements = {
IDC_COLUMN_NUM_EDIT, IDC_DELIMITER_EDIT, IDC_COLUMN_HIGHLIGHT_BUTTON
};

//Initialization
void positionAndResizeControls(int windowWidth, int windowHeight);
Expand Down Expand Up @@ -389,6 +413,7 @@ class MultiReplace : public DockingDlgInterface
void displayProgressInStatus(LRESULT current, LRESULT total, const std::wstring& message);
void resetProgressBar();
LRESULT updateEOLLength();
void setElementsState(const std::vector<int>& elements, bool enable, bool restoreOriginalState = false);

//StringHandling
std::wstring stringToWString(const std::string& encodedInput);
Expand Down

0 comments on commit ccba292

Please sign in to comment.