Skip to content

Commit

Permalink
enable or disable IDC_SELECTION_RADIO based on selected text
Browse files Browse the repository at this point in the history
  • Loading branch information
daddel80 committed Jul 21, 2023
1 parent 658b904 commit 485d40a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/MultiReplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include "PluginDefinition.h"
#include "MultiReplacePanel.h"

extern FuncItem funcItem[nbFunc];
extern NppData nppData;
Expand Down Expand Up @@ -75,6 +76,14 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode)
commandMenuCleanUp();
}
break;
case SCN_UPDATEUI:
{
if (MultiReplace::isWindowOpen)
{
MultiReplace::onSelectionChanged();
}
}
break;

default:
return;
Expand Down
13 changes: 12 additions & 1 deletion src/MultiReplacePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#endif

std::map<int, ControlInfo> MultiReplace::ctrlMap;
bool MultiReplace::isWindowOpen = false;
HWND MultiReplace::s_hScintilla = nullptr;
HWND MultiReplace::s_hDlg = nullptr;


#pragma region Initialization
Expand Down Expand Up @@ -113,6 +116,7 @@ void MultiReplace::positionAndResizeControls(int windowWidth, int windowHeight)
void MultiReplace::initializeCtrlMap()
{
hInstance = (HINSTANCE)GetWindowLongPtr(_hSelf, GWLP_HINSTANCE);
s_hDlg = _hSelf;

// Get the client rectangle
RECT rcClient;
Expand All @@ -129,7 +133,6 @@ void MultiReplace::initializeCtrlMap()
return;
}


// Create the font
hFont = CreateFont(FONT_SIZE, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, 0, 0, FONT_NAME);

Expand All @@ -152,13 +155,20 @@ void MultiReplace::initializeCtrlMap()

// CheckBox to All Text
CheckRadioButton(_hSelf, IDC_ALL_TEXT_RADIO, IDC_COLUMN_MODE_RADIO, IDC_ALL_TEXT_RADIO);

// Enable IDC_SELECTION_RADIO based on text selection
Sci_Position start = ::SendMessage(MultiReplace::getScintillaHandle(), SCI_GETSELECTIONSTART, 0, 0);
Sci_Position end = ::SendMessage(MultiReplace::getScintillaHandle(), SCI_GETSELECTIONEND, 0, 0);
bool isTextSelected = (start != end);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SELECTION_RADIO), isTextSelected);

// Hide Hint Text
ShowWindow(GetDlgItem(_hSelf, IDC_STATIC_HINT), SW_HIDE);

// Enable the checkbox ID IDC_USE_LIST_CHECKBOX
SendMessage(GetDlgItem(_hSelf, IDC_USE_LIST_CHECKBOX), BM_SETCHECK, BST_CHECKED, 0);

isWindowOpen = true;
}

bool MultiReplace::createAndShowWindows() {
Expand Down Expand Up @@ -229,6 +239,7 @@ void MultiReplace::initializeScintilla() {
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
if (which != -1) {
_hScintilla = (which == 0) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
s_hScintilla = _hScintilla;
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/MultiReplacePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,40 @@ class MultiReplace : public DockingDlgInterface
return _isFloating;
};

static HWND getScintillaHandle() {
return s_hScintilla;
}

static HWND getDialogHandle() {
return s_hDlg;
}

static bool isWindowOpen;
static void onSelectionChanged() {

// Get the start and end of the selection
Sci_Position start = ::SendMessage(MultiReplace::getScintillaHandle(), SCI_GETSELECTIONSTART, 0, 0);
Sci_Position end = ::SendMessage(MultiReplace::getScintillaHandle(), SCI_GETSELECTIONEND, 0, 0);

// Enable or disable IDC_SELECTION_RADIO depending on whether text is selected
bool isTextSelected = (start != end);
::EnableWindow(::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO), isTextSelected);

// If no text is selected and IDC_SELECTION_RADIO is checked, check IDC_ALL_TEXT_RADIO instead
if (!isTextSelected && (::SendMessage(::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO), BM_GETCHECK, 0, 0) == BST_CHECKED)) {
::SendMessage(::GetDlgItem(getDialogHandle(), IDC_ALL_TEXT_RADIO), BM_SETCHECK, BST_CHECKED, 0);
::SendMessage(::GetDlgItem(getDialogHandle(), IDC_SELECTION_RADIO), BM_SETCHECK, BST_UNCHECKED, 0);
}
}


protected:
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

private:
static const int RESIZE_TIMER_ID = 1;
static HWND s_hScintilla;
static HWND s_hDlg;
HINSTANCE hInstance;
HWND _hScintilla;
HWND _replaceListView;
Expand Down

0 comments on commit 485d40a

Please sign in to comment.