From df5514b632fa8b6bcb52c093007ab770f572bcb0 Mon Sep 17 00:00:00 2001 From: Ekopalypse Date: Thu, 2 Jan 2025 13:23:42 +0100 Subject: [PATCH] Add an config option to chose a different console error color --- PythonScript/res/PythonScript.rc | 19 +++++++++-------- PythonScript/res/resource.h | 4 +++- PythonScript/src/ConfigFile.cpp | 1 + PythonScript/src/ConsoleDialog.cpp | 25 +++++++++++++--------- PythonScript/src/ConsoleDialog.h | 3 ++- PythonScript/src/ShortcutDlg.cpp | 33 ++++++++++++++++++++++++------ PythonScript/src/ShortcutDlg.h | 3 ++- 7 files changed, 61 insertions(+), 27 deletions(-) diff --git a/PythonScript/res/PythonScript.rc b/PythonScript/res/PythonScript.rc index 0e4f9836..d314fbc7 100644 --- a/PythonScript/res/PythonScript.rc +++ b/PythonScript/res/PythonScript.rc @@ -25,18 +25,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK // TEXTINCLUDE // -1 TEXTINCLUDE +1 TEXTINCLUDE BEGIN "resource.h\0" END -2 TEXTINCLUDE +2 TEXTINCLUDE BEGIN "#include ""afxres.h""\r\n" "\0" END -3 TEXTINCLUDE +3 TEXTINCLUDE BEGIN "\r\n" "\0" @@ -73,13 +73,13 @@ BEGIN COMBOBOX IDC_COMBO1,25,156,125,50,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP END -IDD_SCRIPTCONFIG DIALOGEX 0, 0, 377, 412 +IDD_SCRIPTCONFIG DIALOGEX 0, 0, 377, 435 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Python Script Configuration" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - DEFPUSHBUTTON "OK",IDOK,265,391,50,14 - PUSHBUTTON "Cancel",IDCANCEL,320,391,50,14 + DEFPUSHBUTTON "OK",IDOK,265,414,50,14 + PUSHBUTTON "Cancel",IDCANCEL,320,414,50,14 CONTROL "",IDC_FILETREE,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,14,31,343,105 GROUPBOX "Scripts",IDC_STATIC,7,7,363,136 CONTROL "Machine Scripts",IDC_RADMACHINE,"Button",BS_AUTORADIOBUTTON,19,18,65,10 @@ -106,8 +106,11 @@ BEGIN CONTROL "Color output from run statements differently",IDC_CHECKCOLORIZEOUTPUT, "Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,370,157,10 PUSHBUTTON "Choose a color...",IDC_COLORCHOOSER,169,367,65,14 + CONTROL "Color console errors differently",IDC_CONSOLEERRORCOLOR, + "Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,382,117,10 + PUSHBUTTON "Choose a color...",IDC_COLORCHOOSER2,169,379,65,14 CONTROL "DISABLE another script is running popup warning",IDC_DISABLEPOPUPWARNING, - "Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,384,170,10 + "Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,395,170,10 END IDD_PROMPTDIALOG DIALOGEX 0, 0, 313, 105 @@ -151,7 +154,7 @@ BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 370 TOPMARGIN, 7 - BOTTOMMARGIN, 405 + BOTTOMMARGIN, 428 END IDD_PROMPTDIALOG, DIALOG diff --git a/PythonScript/res/resource.h b/PythonScript/res/resource.h index 12cb131e..d75c3399 100644 --- a/PythonScript/res/resource.h +++ b/PythonScript/res/resource.h @@ -43,9 +43,11 @@ #define IDC_CHECKCOLORIZEOUTPUT 1023 #define IDC_COLORCHOOSER 1024 #define IDC_DISABLEPOPUPWARNING 1025 +#define IDC_CONSOLEERRORCOLOR 1026 +#define IDC_COLORCHOOSER2 1027 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 122 diff --git a/PythonScript/src/ConfigFile.cpp b/PythonScript/src/ConfigFile.cpp index d14f8ec0..c2fb1dbf 100644 --- a/PythonScript/src/ConfigFile.cpp +++ b/PythonScript/src/ConfigFile.cpp @@ -49,6 +49,7 @@ void ConfigFile::initSettings() setSetting(_T("DISABLEPOPUPWARNING"), _T("0")); setSetting(_T("PREFERINSTALLEDPYTHON"), _T("0")); setSetting(_T("STARTUP"), _T("LAZY")); + setSetting(_T("CUSTOMCONSOLEERRORCOLOR"), _T("-1")); } void ConfigFile::readConfig() diff --git a/PythonScript/src/ConsoleDialog.cpp b/PythonScript/src/ConsoleDialog.cpp index 6395adc6..e01cba4c 100644 --- a/PythonScript/src/ConsoleDialog.cpp +++ b/PythonScript/src/ConsoleDialog.cpp @@ -76,15 +76,19 @@ void ConsoleDialog::initDialog(HINSTANCE hInst, NppData& nppData, ConsoleInterfa { DockingDlgInterface::init(hInst, nppData._nppHandle); - try - { - m_user_color = stoi(ConfigFile::getInstance()->getSetting(_T("COLORIZEOUTPUT"))); - m_colorOutput = m_user_color > -1; - } - catch (const std::exception&) - { - m_colorOutput = false; - } + auto getColorSetting = [](const TCHAR* settingName, int& output) { + try { + output = stoi(ConfigFile::getInstance()->getSetting(settingName)); + return true; + } + catch (const std::exception&) { + return false; + } + }; + + m_colorOutput = getColorSetting(_T("COLORIZEOUTPUT"), m_user_color) && m_user_color > -1; + m_customizeConsoleErrorColor = getColorSetting(_T("CUSTOMCONSOLEERRORCOLOR"), m_customConsoleErrorColor) && m_customConsoleErrorColor > -1; + m_standardPrompt = ConfigFile::getInstance()->getSetting(_T("ADDEXTRALINETOOUTPUT")) == _T("1") ? m_standardPrompt.insert(0, "\n") : m_standardPrompt; m_currentPrompt = m_standardPrompt; //Window::init(hInst, nppData._nppHandle); @@ -381,7 +385,8 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow) // 1 is stderr, red text callScintilla(SCI_STYLESETSIZE, 1 /* = style number */, 8 /* = size in points */); - callScintilla(SCI_STYLESETFORE, 1, RGB(250, 0, 0)); + COLORREF consoleErrorColor = m_customizeConsoleErrorColor ? m_customConsoleErrorColor : RGB(250, 0, 0); + callScintilla(SCI_STYLESETFORE, 1, consoleErrorColor); // 2 is stdout, black text, underline hotspot callScintilla(SCI_STYLESETSIZE, 2 /* = style number */, 8 /* = size in points */); diff --git a/PythonScript/src/ConsoleDialog.h b/PythonScript/src/ConsoleDialog.h index e9966fd3..95525d04 100644 --- a/PythonScript/src/ConsoleDialog.h +++ b/PythonScript/src/ConsoleDialog.h @@ -97,7 +97,8 @@ class ConsoleDialog : public DockingDlgInterface HMENU m_hContext; bool m_colorOutput; int m_user_color; - + bool m_customizeConsoleErrorColor; + int m_customConsoleErrorColor; }; enum ErrorLevel diff --git a/PythonScript/src/ShortcutDlg.cpp b/PythonScript/src/ShortcutDlg.cpp index 7bc12a38..878b7fc3 100644 --- a/PythonScript/src/ShortcutDlg.cpp +++ b/PythonScript/src/ShortcutDlg.cpp @@ -23,7 +23,8 @@ ShortcutDlg::ShortcutDlg(HINSTANCE hInst, NppData& nppData, const TCHAR *scriptD m_menuItemCount(0), m_toolbarColumnWidth(100), m_menuItemColumnWidth(100), - m_currentScript(NULL) + m_currentScript(NULL), + m_hButtonConsoleErrorColor(NULL) { Window::init(hInst, nppData._nppHandle); TCHAR temp[MAX_PATH]{}; @@ -78,7 +79,10 @@ INT_PTR CALLBACK ShortcutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP switch (LOWORD(wParam)) { case IDC_COLORCHOOSER: - ctrlOnClick(); + ctrlOnClick(IDC_COLORCHOOSER); + break; + case IDC_COLORCHOOSER2: + ctrlOnClick(IDC_COLORCHOOSER2); break; case IDC_CHECKCOLORIZEOUTPUT: if (HIWORD(wParam) == BN_CLICKED) @@ -87,6 +91,13 @@ INT_PTR CALLBACK ShortcutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP EnableWindow(m_hButtonColor, (result == BST_CHECKED) ? true : false); } break; + case IDC_CONSOLEERRORCOLOR: + if (HIWORD(wParam) == BN_CLICKED) + { + size_t result = SendMessage(reinterpret_cast(lParam), BM_GETCHECK, 0, 0); + EnableWindow(m_hButtonConsoleErrorColor, (result == BST_CHECKED) ? true : false); + } + break; } switch(wParam) { @@ -224,6 +235,7 @@ void ShortcutDlg::onInitDialog() m_hListToolbarItems = ::GetDlgItem(_hSelf, IDC_TOOLBARITEMLIST2); m_hComboInitialisation = ::GetDlgItem(_hSelf, IDC_COMBOINITIALISATION); m_hButtonColor = ::GetDlgItem(_hSelf, IDC_COLORCHOOSER); + m_hButtonConsoleErrorColor = ::GetDlgItem(_hSelf, IDC_COLORCHOOSER2); InitCommonControls(); HICON hIcon; // handle to icon @@ -533,6 +545,10 @@ void ShortcutDlg::populateCurrentItems() bool disablePopupWarning = (configFile->getSetting(_T("DISABLEPOPUPWARNING")) == _T("1")); CheckDlgButton(_hSelf, IDC_DISABLEPOPUPWARNING, disablePopupWarning ? BST_CHECKED : BST_UNCHECKED); + bool colorConsoleError = (configFile->getSetting(_T("CUSTOMCONSOLEERRORCOLOR")) >= _T("0")); + CheckDlgButton(_hSelf, IDC_CONSOLEERRORCOLOR, colorConsoleError ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(m_hButtonConsoleErrorColor, colorConsoleError); + } @@ -573,6 +589,9 @@ void ShortcutDlg::saveConfig() bool disablePopupWarning = (BST_CHECKED == IsDlgButtonChecked(_hSelf, IDC_DISABLEPOPUPWARNING)); configFile->setSetting(_T("DISABLEPOPUPWARNING"), disablePopupWarning ? _T("1") : _T("0")); + bool customizeConsoleErrorColor = (BST_CHECKED == IsDlgButtonChecked(_hSelf, IDC_CONSOLEERRORCOLOR)); + configFile->setSetting(_T("CUSTOMCONSOLEERRORCOLOR"), customizeConsoleErrorColor ? ConfigFile::getInstance()->getSetting(_T("CUSTOMCONSOLEERRORCOLOR")) : _T("-1")); + configFile->save(); } @@ -625,7 +644,7 @@ void ShortcutDlg::toolbarSetIcon() } } -void ShortcutDlg::ctrlOnClick() const +void ShortcutDlg::ctrlOnClick(WORD whichColorButton) const { CHOOSECOLOR cc; static COLORREF acrCustClr[16]; @@ -633,8 +652,10 @@ void ShortcutDlg::ctrlOnClick() const { acrCustClr[i] = RGB(255,255,255); } - const tstring strRGBCurrent = ConfigFile::getInstance()->getSetting(_T("COLORIZEOUTPUT")); - static DWORD rgbCurrent = (strRGBCurrent == _T("-1")) ? RGB(135,214,18) : stoi(strRGBCurrent); + const TCHAR *colorSetting = whichColorButton == IDC_COLORCHOOSER ? _T("COLORIZEOUTPUT") : _T("CUSTOMCONSOLEERRORCOLOR"); + COLORREF defaultColor = whichColorButton == IDC_COLORCHOOSER ? RGB(135, 214, 18) : RGB(255, 0, 0); + const tstring strRGBCurrent = ConfigFile::getInstance()->getSetting(colorSetting); + static DWORD rgbCurrent = (strRGBCurrent == _T("-1")) ? defaultColor : stoi(strRGBCurrent); ZeroMemory(&cc, sizeof(cc)); cc.lStructSize = sizeof(cc); @@ -646,7 +667,7 @@ void ShortcutDlg::ctrlOnClick() const if (ChooseColor(&cc) == TRUE) { rgbCurrent = cc.rgbResult; - ConfigFile::getInstance()->setSetting(_T("COLORIZEOUTPUT"), std::to_wstring(rgbCurrent)); + ConfigFile::getInstance()->setSetting(colorSetting, std::to_wstring(rgbCurrent)); } } \ No newline at end of file diff --git a/PythonScript/src/ShortcutDlg.h b/PythonScript/src/ShortcutDlg.h index 6d887a1c..a5fe8702 100644 --- a/PythonScript/src/ShortcutDlg.h +++ b/PythonScript/src/ShortcutDlg.h @@ -45,7 +45,7 @@ class ShortcutDlg : public StaticDialog void saveConfig(); - void ctrlOnClick() const; + void ctrlOnClick(WORD whichColorButton) const; HTREEITEM addTreeItem(HTREEITEM parent, HTREEITEM lastItem, TCHAR *fullPath, TCHAR *text, bool isDirectory); @@ -56,6 +56,7 @@ class ShortcutDlg : public StaticDialog HWND m_hListToolbarItems; HWND m_hComboInitialisation; HWND m_hButtonColor; + HWND m_hButtonConsoleErrorColor; HIMAGELIST m_hImageList; int m_hDefaultImageIndex;