Skip to content

Commit

Permalink
Add an config option to chose a different console error color (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekopalypse authored Jan 3, 2025
1 parent d4333fe commit 65b7ed8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 27 deletions.
19 changes: 11 additions & 8 deletions PythonScript/res/PythonScript.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -151,7 +154,7 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 370
TOPMARGIN, 7
BOTTOMMARGIN, 405
BOTTOMMARGIN, 428
END

IDD_PROMPTDIALOG, DIALOG
Expand Down
4 changes: 3 additions & 1 deletion PythonScript/res/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions PythonScript/src/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 15 additions & 10 deletions PythonScript/src/ConsoleDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */);
Expand Down
3 changes: 2 additions & 1 deletion PythonScript/src/ConsoleDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 27 additions & 6 deletions PythonScript/src/ShortcutDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]{};
Expand Down Expand Up @@ -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)
Expand All @@ -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<HWND>(lParam), BM_GETCHECK, 0, 0);
EnableWindow(m_hButtonConsoleErrorColor, (result == BST_CHECKED) ? true : false);
}
break;
}
switch(wParam)
{
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);

}


Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -625,16 +644,18 @@ void ShortcutDlg::toolbarSetIcon()
}
}

void ShortcutDlg::ctrlOnClick() const
void ShortcutDlg::ctrlOnClick(WORD whichColorButton) const
{
CHOOSECOLOR cc;
static COLORREF acrCustClr[16];
for (int i = 0; i < 16; i++)
{
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);
Expand All @@ -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));
}

}
3 changes: 2 additions & 1 deletion PythonScript/src/ShortcutDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit 65b7ed8

Please sign in to comment.