Skip to content

Commit 65b7ed8

Browse files
authored
Add an config option to chose a different console error color (#371)
1 parent d4333fe commit 65b7ed8

File tree

7 files changed

+61
-27
lines changed

7 files changed

+61
-27
lines changed

PythonScript/res/PythonScript.rc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
2525
// TEXTINCLUDE
2626
//
2727

28-
1 TEXTINCLUDE
28+
1 TEXTINCLUDE
2929
BEGIN
3030
"resource.h\0"
3131
END
3232

33-
2 TEXTINCLUDE
33+
2 TEXTINCLUDE
3434
BEGIN
3535
"#include ""afxres.h""\r\n"
3636
"\0"
3737
END
3838

39-
3 TEXTINCLUDE
39+
3 TEXTINCLUDE
4040
BEGIN
4141
"\r\n"
4242
"\0"
@@ -73,13 +73,13 @@ BEGIN
7373
COMBOBOX IDC_COMBO1,25,156,125,50,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP
7474
END
7575

76-
IDD_SCRIPTCONFIG DIALOGEX 0, 0, 377, 412
76+
IDD_SCRIPTCONFIG DIALOGEX 0, 0, 377, 435
7777
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
7878
CAPTION "Python Script Configuration"
7979
FONT 8, "MS Shell Dlg", 400, 0, 0x1
8080
BEGIN
81-
DEFPUSHBUTTON "OK",IDOK,265,391,50,14
82-
PUSHBUTTON "Cancel",IDCANCEL,320,391,50,14
81+
DEFPUSHBUTTON "OK",IDOK,265,414,50,14
82+
PUSHBUTTON "Cancel",IDCANCEL,320,414,50,14
8383
CONTROL "",IDC_FILETREE,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,14,31,343,105
8484
GROUPBOX "Scripts",IDC_STATIC,7,7,363,136
8585
CONTROL "Machine Scripts",IDC_RADMACHINE,"Button",BS_AUTORADIOBUTTON,19,18,65,10
@@ -106,8 +106,11 @@ BEGIN
106106
CONTROL "Color output from run statements differently",IDC_CHECKCOLORIZEOUTPUT,
107107
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,370,157,10
108108
PUSHBUTTON "Choose a color...",IDC_COLORCHOOSER,169,367,65,14
109+
CONTROL "Color console errors differently",IDC_CONSOLEERRORCOLOR,
110+
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,382,117,10
111+
PUSHBUTTON "Choose a color...",IDC_COLORCHOOSER2,169,379,65,14
109112
CONTROL "DISABLE another script is running popup warning",IDC_DISABLEPOPUPWARNING,
110-
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,384,170,10
113+
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,395,170,10
111114
END
112115

113116
IDD_PROMPTDIALOG DIALOGEX 0, 0, 313, 105
@@ -151,7 +154,7 @@ BEGIN
151154
LEFTMARGIN, 7
152155
RIGHTMARGIN, 370
153156
TOPMARGIN, 7
154-
BOTTOMMARGIN, 405
157+
BOTTOMMARGIN, 428
155158
END
156159

157160
IDD_PROMPTDIALOG, DIALOG

PythonScript/res/resource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
#define IDC_CHECKCOLORIZEOUTPUT 1023
4444
#define IDC_COLORCHOOSER 1024
4545
#define IDC_DISABLEPOPUPWARNING 1025
46+
#define IDC_CONSOLEERRORCOLOR 1026
47+
#define IDC_COLORCHOOSER2 1027
4648

4749
// Next default values for new objects
48-
//
50+
//
4951
#ifdef APSTUDIO_INVOKED
5052
#ifndef APSTUDIO_READONLY_SYMBOLS
5153
#define _APS_NEXT_RESOURCE_VALUE 122

PythonScript/src/ConfigFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void ConfigFile::initSettings()
4949
setSetting(_T("DISABLEPOPUPWARNING"), _T("0"));
5050
setSetting(_T("PREFERINSTALLEDPYTHON"), _T("0"));
5151
setSetting(_T("STARTUP"), _T("LAZY"));
52+
setSetting(_T("CUSTOMCONSOLEERRORCOLOR"), _T("-1"));
5253
}
5354

5455
void ConfigFile::readConfig()

PythonScript/src/ConsoleDialog.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,19 @@ void ConsoleDialog::initDialog(HINSTANCE hInst, NppData& nppData, ConsoleInterfa
7676
{
7777
DockingDlgInterface::init(hInst, nppData._nppHandle);
7878

79-
try
80-
{
81-
m_user_color = stoi(ConfigFile::getInstance()->getSetting(_T("COLORIZEOUTPUT")));
82-
m_colorOutput = m_user_color > -1;
83-
}
84-
catch (const std::exception&)
85-
{
86-
m_colorOutput = false;
87-
}
79+
auto getColorSetting = [](const TCHAR* settingName, int& output) {
80+
try {
81+
output = stoi(ConfigFile::getInstance()->getSetting(settingName));
82+
return true;
83+
}
84+
catch (const std::exception&) {
85+
return false;
86+
}
87+
};
88+
89+
m_colorOutput = getColorSetting(_T("COLORIZEOUTPUT"), m_user_color) && m_user_color > -1;
90+
m_customizeConsoleErrorColor = getColorSetting(_T("CUSTOMCONSOLEERRORCOLOR"), m_customConsoleErrorColor) && m_customConsoleErrorColor > -1;
91+
8892
m_standardPrompt = ConfigFile::getInstance()->getSetting(_T("ADDEXTRALINETOOUTPUT")) == _T("1") ? m_standardPrompt.insert(0, "\n") : m_standardPrompt;
8993
m_currentPrompt = m_standardPrompt;
9094
//Window::init(hInst, nppData._nppHandle);
@@ -381,7 +385,8 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
381385

382386
// 1 is stderr, red text
383387
callScintilla(SCI_STYLESETSIZE, 1 /* = style number */, 8 /* = size in points */);
384-
callScintilla(SCI_STYLESETFORE, 1, RGB(250, 0, 0));
388+
COLORREF consoleErrorColor = m_customizeConsoleErrorColor ? m_customConsoleErrorColor : RGB(250, 0, 0);
389+
callScintilla(SCI_STYLESETFORE, 1, consoleErrorColor);
385390

386391
// 2 is stdout, black text, underline hotspot
387392
callScintilla(SCI_STYLESETSIZE, 2 /* = style number */, 8 /* = size in points */);

PythonScript/src/ConsoleDialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class ConsoleDialog : public DockingDlgInterface
9797
HMENU m_hContext;
9898
bool m_colorOutput;
9999
int m_user_color;
100-
100+
bool m_customizeConsoleErrorColor;
101+
int m_customConsoleErrorColor;
101102
};
102103

103104
enum ErrorLevel

PythonScript/src/ShortcutDlg.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ ShortcutDlg::ShortcutDlg(HINSTANCE hInst, NppData& nppData, const TCHAR *scriptD
2323
m_menuItemCount(0),
2424
m_toolbarColumnWidth(100),
2525
m_menuItemColumnWidth(100),
26-
m_currentScript(NULL)
26+
m_currentScript(NULL),
27+
m_hButtonConsoleErrorColor(NULL)
2728
{
2829
Window::init(hInst, nppData._nppHandle);
2930
TCHAR temp[MAX_PATH]{};
@@ -78,7 +79,10 @@ INT_PTR CALLBACK ShortcutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
7879
switch (LOWORD(wParam))
7980
{
8081
case IDC_COLORCHOOSER:
81-
ctrlOnClick();
82+
ctrlOnClick(IDC_COLORCHOOSER);
83+
break;
84+
case IDC_COLORCHOOSER2:
85+
ctrlOnClick(IDC_COLORCHOOSER2);
8286
break;
8387
case IDC_CHECKCOLORIZEOUTPUT:
8488
if (HIWORD(wParam) == BN_CLICKED)
@@ -87,6 +91,13 @@ INT_PTR CALLBACK ShortcutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
8791
EnableWindow(m_hButtonColor, (result == BST_CHECKED) ? true : false);
8892
}
8993
break;
94+
case IDC_CONSOLEERRORCOLOR:
95+
if (HIWORD(wParam) == BN_CLICKED)
96+
{
97+
size_t result = SendMessage(reinterpret_cast<HWND>(lParam), BM_GETCHECK, 0, 0);
98+
EnableWindow(m_hButtonConsoleErrorColor, (result == BST_CHECKED) ? true : false);
99+
}
100+
break;
90101
}
91102
switch(wParam)
92103
{
@@ -224,6 +235,7 @@ void ShortcutDlg::onInitDialog()
224235
m_hListToolbarItems = ::GetDlgItem(_hSelf, IDC_TOOLBARITEMLIST2);
225236
m_hComboInitialisation = ::GetDlgItem(_hSelf, IDC_COMBOINITIALISATION);
226237
m_hButtonColor = ::GetDlgItem(_hSelf, IDC_COLORCHOOSER);
238+
m_hButtonConsoleErrorColor = ::GetDlgItem(_hSelf, IDC_COLORCHOOSER2);
227239
InitCommonControls();
228240
HICON hIcon; // handle to icon
229241

@@ -533,6 +545,10 @@ void ShortcutDlg::populateCurrentItems()
533545
bool disablePopupWarning = (configFile->getSetting(_T("DISABLEPOPUPWARNING")) == _T("1"));
534546
CheckDlgButton(_hSelf, IDC_DISABLEPOPUPWARNING, disablePopupWarning ? BST_CHECKED : BST_UNCHECKED);
535547

548+
bool colorConsoleError = (configFile->getSetting(_T("CUSTOMCONSOLEERRORCOLOR")) >= _T("0"));
549+
CheckDlgButton(_hSelf, IDC_CONSOLEERRORCOLOR, colorConsoleError ? BST_CHECKED : BST_UNCHECKED);
550+
EnableWindow(m_hButtonConsoleErrorColor, colorConsoleError);
551+
536552
}
537553

538554

@@ -573,6 +589,9 @@ void ShortcutDlg::saveConfig()
573589
bool disablePopupWarning = (BST_CHECKED == IsDlgButtonChecked(_hSelf, IDC_DISABLEPOPUPWARNING));
574590
configFile->setSetting(_T("DISABLEPOPUPWARNING"), disablePopupWarning ? _T("1") : _T("0"));
575591

592+
bool customizeConsoleErrorColor = (BST_CHECKED == IsDlgButtonChecked(_hSelf, IDC_CONSOLEERRORCOLOR));
593+
configFile->setSetting(_T("CUSTOMCONSOLEERRORCOLOR"), customizeConsoleErrorColor ? ConfigFile::getInstance()->getSetting(_T("CUSTOMCONSOLEERRORCOLOR")) : _T("-1"));
594+
576595
configFile->save();
577596
}
578597

@@ -625,16 +644,18 @@ void ShortcutDlg::toolbarSetIcon()
625644
}
626645
}
627646

628-
void ShortcutDlg::ctrlOnClick() const
647+
void ShortcutDlg::ctrlOnClick(WORD whichColorButton) const
629648
{
630649
CHOOSECOLOR cc;
631650
static COLORREF acrCustClr[16];
632651
for (int i = 0; i < 16; i++)
633652
{
634653
acrCustClr[i] = RGB(255,255,255);
635654
}
636-
const tstring strRGBCurrent = ConfigFile::getInstance()->getSetting(_T("COLORIZEOUTPUT"));
637-
static DWORD rgbCurrent = (strRGBCurrent == _T("-1")) ? RGB(135,214,18) : stoi(strRGBCurrent);
655+
const TCHAR *colorSetting = whichColorButton == IDC_COLORCHOOSER ? _T("COLORIZEOUTPUT") : _T("CUSTOMCONSOLEERRORCOLOR");
656+
COLORREF defaultColor = whichColorButton == IDC_COLORCHOOSER ? RGB(135, 214, 18) : RGB(255, 0, 0);
657+
const tstring strRGBCurrent = ConfigFile::getInstance()->getSetting(colorSetting);
658+
static DWORD rgbCurrent = (strRGBCurrent == _T("-1")) ? defaultColor : stoi(strRGBCurrent);
638659

639660
ZeroMemory(&cc, sizeof(cc));
640661
cc.lStructSize = sizeof(cc);
@@ -646,7 +667,7 @@ void ShortcutDlg::ctrlOnClick() const
646667
if (ChooseColor(&cc) == TRUE)
647668
{
648669
rgbCurrent = cc.rgbResult;
649-
ConfigFile::getInstance()->setSetting(_T("COLORIZEOUTPUT"), std::to_wstring(rgbCurrent));
670+
ConfigFile::getInstance()->setSetting(colorSetting, std::to_wstring(rgbCurrent));
650671
}
651672

652673
}

PythonScript/src/ShortcutDlg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ShortcutDlg : public StaticDialog
4545

4646
void saveConfig();
4747

48-
void ctrlOnClick() const;
48+
void ctrlOnClick(WORD whichColorButton) const;
4949

5050
HTREEITEM addTreeItem(HTREEITEM parent, HTREEITEM lastItem, TCHAR *fullPath, TCHAR *text, bool isDirectory);
5151

@@ -56,6 +56,7 @@ class ShortcutDlg : public StaticDialog
5656
HWND m_hListToolbarItems;
5757
HWND m_hComboInitialisation;
5858
HWND m_hButtonColor;
59+
HWND m_hButtonConsoleErrorColor;
5960

6061
HIMAGELIST m_hImageList;
6162
int m_hDefaultImageIndex;

0 commit comments

Comments
 (0)