Skip to content

Commit e1e3621

Browse files
authored
Merge pull request bruderstein#84 from ClaudiaFrank/multiple_issues
Multiple issues
2 parents 1402c12 + 3806ff9 commit e1e3621

17 files changed

+1026
-308
lines changed

PythonScript/res/PythonScript.rc

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x1
5757
BEGIN
5858
DEFPUSHBUTTON "OK",IDOK,143,168,50,14
5959
LTEXT "Python Script",IDC_STATIC,146,7,49,8
60-
LTEXT "(C) 2010, 2011, 2014, 2018 Dave Brotherstone",IDC_STATIC,92,30,154,8
61-
CONTROL 118,IDC_STATIC,"Static",SS_BITMAP | SS_REALSIZEIMAGE,118,42,93,34
60+
LTEXT "(C) 2010, 2011, 2014, 2018 Dave Brotherstone",IDC_STATIC,105,30,133,8
61+
CONTROL IDB_PYTHONPOWERED,IDC_STATIC,"Static",SS_BITMAP | SS_REALSIZEIMAGE,118,42,93,34
6262
EDITTEXT IDC_COPYRIGHT,7,84,324,74,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL
6363
CTEXT "1.0",IDC_VERSION,156,19,26,8
6464
END
@@ -73,32 +73,39 @@ BEGIN
7373
LTEXT ">>>",IDC_PROMPT,7,161,17,8
7474
END
7575

76-
IDD_SCRIPTCONFIG DIALOGEX 0, 0, 376, 363
76+
IDD_SCRIPTCONFIG DIALOGEX 0, 0, 377, 404
7777
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
78-
CAPTION "Python Script Shortcut Configuration"
78+
CAPTION "Python Script Configuration"
7979
FONT 8, "MS Shell Dlg", 400, 0, 0x1
8080
BEGIN
81-
DEFPUSHBUTTON "OK",IDOK,265,342,50,14
82-
PUSHBUTTON "Cancel",IDCANCEL,319,342,50,14
81+
DEFPUSHBUTTON "OK",IDOK,265,383,50,14
82+
PUSHBUTTON "Cancel",IDCANCEL,320,382,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
84-
GROUPBOX "Scripts",IDC_STATIC,7,7,362,136
84+
GROUPBOX "Scripts",IDC_STATIC,7,7,363,136
8585
CONTROL "Machine Scripts",IDC_RADMACHINE,"Button",BS_AUTORADIOBUTTON,19,18,65,10
8686
CONTROL "User Scripts",IDC_RADUSER,"Button",BS_AUTORADIOBUTTON,94,18,54,10
8787
PUSHBUTTON "Add",IDC_MENUADD,21,146,50,14
8888
PUSHBUTTON "Remove",IDC_MENUREMOVE,89,146,50,14
89-
PUSHBUTTON "Add",IDC_TOOLBARADD,187,146,50,14
89+
PUSHBUTTON "Add",IDC_TOOLBARADD,187,145,50,14
9090
PUSHBUTTON "Remove",IDC_TOOLBARREMOVE,245,146,50,14
91-
LTEXT "Menu items",IDC_STATIC,10,161,37,8
91+
LTEXT "Menu items",IDC_STATIC,10,162,37,8
9292
LTEXT "Toolbar icons",IDC_STATIC,186,161,43,8
93-
CONTROL "",IDC_TOOLBARITEMLIST2,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,185,172,184,104
94-
PUSHBUTTON "Set Icon",IDC_TOOLBARSETICON,304,146,50,14
95-
CONTROL "",IDC_MENUITEMLIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,7,172,173,104
96-
COMBOBOX IDC_COMBOINITIALISATION,58,285,69,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
93+
CONTROL "",IDC_TOOLBARITEMLIST2,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,186,172,184,104
94+
PUSHBUTTON "Set Icon...",IDC_TOOLBARSETICON,304,146,50,14
95+
CONTROL "",IDC_MENUITEMLIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,7,171,173,106
96+
COMBOBOX IDC_COMBOINITIALISATION,55,285,69,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
9797
LTEXT "Initialisation:",IDC_STATIC,9,287,44,12
9898
LTEXT "Lazy initialisation initialises Python when it is first used. Use ATSTARTUP if you want your startup.py scripts to run as soon as Notepad++ starts.",IDC_STATIC,131,282,232,21
9999
CONTROL "Prefer installed Python libraries - use only if you have Python 2.7 installed, and you have copied the python27.dll from your Windows directory to the Notepad++ directory. ",IDC_CHECKPREFERINSTALLEDPYTHON,
100100
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | WS_TABSTOP,11,303,352,19
101-
LTEXT "This has the effect that the directories under Notepad++ that contain Python libraries are searched AFTER the standard Python directories. If in doubt, leave unchecked.",IDC_STATIC,21,321,348,19
101+
LTEXT "This has the effect that the directories under Notepad++ that contain Python libraries are searched AFTER the standard Python directories. If in doubt, leave unchecked.",IDC_STATIC,22,321,348,19
102+
CONTROL "Add an additional end of line character for run statements and error messages to the console",IDC_CHECKADDEXTRALINETOOUTPUT,
103+
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | WS_TABSTOP,11,356,310,10
104+
CONTROL "Automatically open console on error (no restart required)",IDC_CHECKOPENCONSOLEONERROR,
105+
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | WS_TABSTOP,11,342,197,10
106+
CONTROL "Color output from run statements differently",IDC_CHECKCOLORIZEOUTPUT,
107+
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | BS_NOTIFY | WS_TABSTOP,11,370,157,10
108+
PUSHBUTTON "Chose a color...",IDC_COLORCHOOSER,169,367,62,14
102109
END
103110

104111
IDD_PROMPTDIALOG DIALOGEX 0, 0, 313, 105
@@ -109,7 +116,7 @@ BEGIN
109116
DEFPUSHBUTTON "OK",IDOK,205,84,50,14
110117
PUSHBUTTON "Cancel",IDCANCEL,256,84,50,14
111118
LTEXT "Static",IDC_PROMPT,7,7,299,19
112-
EDITTEXT IDC_USERTEXT,7,29,299,46,ES_MULTILINE | ES_AUTOHSCROLL
119+
EDITTEXT IDC_USERTEXT,7,29,299,46,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL
113120
END
114121

115122

@@ -140,9 +147,9 @@ BEGIN
140147
IDD_SCRIPTCONFIG, DIALOG
141148
BEGIN
142149
LEFTMARGIN, 7
143-
RIGHTMARGIN, 369
150+
RIGHTMARGIN, 370
144151
TOPMARGIN, 7
145-
BOTTOMMARGIN, 356
152+
BOTTOMMARGIN, 397
146153
END
147154

148155
IDD_PROMPTDIALOG, DIALOG
@@ -164,17 +171,39 @@ END
164171
// Icon with lowest ID value placed first to ensure application icon
165172
// remains consistent on all systems.
166173
IDI_FOLDERCLOSED ICON "FolderClosed.ico"
174+
167175
IDI_FOLDEROPEN ICON "FolderOpen.ico"
176+
168177
IDI_PYTHON ICON "python.ico"
178+
169179
IDI_PYTHON8 ICON "python2.ico"
170180

181+
171182
/////////////////////////////////////////////////////////////////////////////
172183
//
173184
// Bitmap
174185
//
175186

176187
IDB_PYTHON BITMAP "python.bmp"
188+
177189
IDB_PYTHONPOWERED BITMAP "python-powered-w-140x56.bmp"
190+
191+
192+
/////////////////////////////////////////////////////////////////////////////
193+
//
194+
// AFX_DIALOG_LAYOUT
195+
//
196+
197+
IDD_SCRIPTCONFIG AFX_DIALOG_LAYOUT
198+
BEGIN
199+
0
200+
END
201+
202+
IDD_PROMPTDIALOG AFX_DIALOG_LAYOUT
203+
BEGIN
204+
0
205+
END
206+
178207
#endif // English (United Kingdom) resources
179208
/////////////////////////////////////////////////////////////////////////////
180209

0 Bytes
Binary file not shown.

PythonScript/res/resource.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@
3838
#define IDC_COPYRIGHT 1018
3939
#define IDC_VERSION 1019
4040
#define IDC_CHECKPREFERINSTALLEDPYTHON 1020
41+
#define IDC_CHECKADDEXTRALINETOOUTPUT 1021
42+
#define IDC_CHECKOPENCONSOLEONERROR 1022
43+
#define IDC_CHECKCOLORIZEOUTPUT 1023
44+
#define IDC_COLORCHOOSER 1024
4145

4246
// Next default values for new objects
4347
//
4448
#ifdef APSTUDIO_INVOKED
4549
#ifndef APSTUDIO_READONLY_SYMBOLS
46-
#define _APS_NEXT_RESOURCE_VALUE 119
50+
#define _APS_NEXT_RESOURCE_VALUE 121
4751
#define _APS_NEXT_COMMAND_VALUE 40001
48-
#define _APS_NEXT_CONTROL_VALUE 1021
52+
#define _APS_NEXT_CONTROL_VALUE 1025
4953
#define _APS_NEXT_SYMED_VALUE 101
5054
#endif
5155
#endif

PythonScript/src/ConfigFile.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ConfigFile::ConfigFile(const TCHAR *configDir, const TCHAR *pluginDir, HINSTANCE
2626
m_machineScriptsDir.append(_T("\\PythonScript\\scripts"));
2727
m_userScriptsDir.append(_T("\\PythonScript\\scripts"));
2828

29+
initSettings();
2930
readConfig();
3031
}
3132

@@ -39,6 +40,14 @@ ConfigFile::~ConfigFile()
3940

4041
}
4142

43+
void ConfigFile::initSettings()
44+
{
45+
setSetting(_T("ADDEXTRALINETOOUTPUT"), _T("0"));
46+
setSetting(_T("COLORIZEOUTPUT"), _T("-1"));
47+
setSetting(_T("OPENCONSOLEONERROR"), _T("0"));
48+
setSetting(_T("PREFERINSTALLEDPYTHON"), _T("0"));
49+
setSetting(_T("STARTUP"), _T("LAZY"));
50+
}
4251

4352
void ConfigFile::readConfig()
4453
{
@@ -89,7 +98,7 @@ void ConfigFile::readConfig()
8998
{
9099
element = strtok_s(NULL, "/", &context);
91100
char *settingValue = strtok_s(NULL, "/", &context);
92-
m_settings.insert(std::pair<tstring, tstring>(tstring(WcharMbcsConverter::char2tchar(element).get()), tstring(WcharMbcsConverter::char2tchar(settingValue).get())));
101+
m_settings.insert_or_assign(tstring(WcharMbcsConverter::char2tchar(element).get()), tstring(WcharMbcsConverter::char2tchar(settingValue).get()));
93102
}
94103
}
95104

PythonScript/src/ConfigFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ConfigFile
3838

3939
protected:
4040
void readConfig();
41+
void initSettings();
4142

4243
private:
4344
ConfigFile(); // default constructor disabled

PythonScript/src/ConsoleDialog.cpp

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "WcharMbcsConverter.h"
1111
#include "MenuManager.h"
1212
#include "PythonScript.h"
13+
#include "ConfigFile.h"
1314

1415

1516
namespace NppPythonScript
@@ -27,7 +28,9 @@ ConsoleDialog::ConsoleDialog() :
2728
m_currentHistory(0),
2829
m_runButtonIsRun(true),
2930
m_hContext(NULL),
30-
m_nppData{0,0,0}
31+
m_nppData{0,0,0},
32+
m_colorOutput(false),
33+
m_user_color(-1)
3134
{
3235
m_historyIter = m_history.end();
3336
}
@@ -72,6 +75,17 @@ void ConsoleDialog::initDialog(HINSTANCE hInst, NppData& nppData, ConsoleInterfa
7275
{
7376
DockingDlgInterface::init(hInst, nppData._nppHandle);
7477

78+
try
79+
{
80+
m_user_color = stoi(ConfigFile::getInstance()->getSetting(_T("COLORIZEOUTPUT")));
81+
m_colorOutput = m_user_color > -1;
82+
}
83+
catch (const std::exception&)
84+
{
85+
m_colorOutput = false;
86+
}
87+
m_prompt = ConfigFile::getInstance()->getSetting(_T("ADDEXTRALINETOOUTPUT")) == _T("1") ? m_prompt.insert(0, "\n") : m_prompt;
88+
7589
//Window::init(hInst, nppData._nppHandle);
7690
createOutputWindow(nppData._nppHandle);
7791

@@ -419,9 +433,9 @@ void ConsoleDialog::runStatement()
419433
std::shared_ptr<char> charBuffer = WcharMbcsConverter::tchar2char(buffer);
420434
delete [] buffer;
421435

422-
writeText(m_prompt.size(), m_prompt.c_str());
423-
writeText(strlen(charBuffer.get()), charBuffer.get());
424-
writeText(1, "\n");
436+
writeCmdText(m_prompt.size(), m_prompt.c_str());
437+
writeCmdText(strlen(charBuffer.get()), charBuffer.get());
438+
writeCmdText(1, "\n");
425439
SetWindowText(hText, _T(""));
426440
m_console->runStatement(charBuffer.get());
427441
}
@@ -441,9 +455,13 @@ void ConsoleDialog::stopStatement()
441455
void ConsoleDialog::setPrompt(const char *prompt)
442456
{
443457
m_prompt = prompt;
444-
::SetWindowTextA(::GetDlgItem(_hSelf, IDC_PROMPT), prompt);
458+
::SetWindowTextA(::GetDlgItem(_hSelf, IDC_PROMPT), (m_prompt.rfind('\n', 0) == 0) ? m_prompt.substr(1, m_prompt.size() - 1).c_str() : m_prompt.c_str());
445459
}
446460

461+
const char * ConsoleDialog::getPrompt()
462+
{
463+
return m_prompt.c_str();
464+
}
447465

448466
void ConsoleDialog::createOutputWindow(HWND hParentWindow)
449467
{
@@ -504,6 +522,10 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
504522
callScintilla(SCI_STYLESETFORE, 7, RGB(255, 128, 64)); // orange
505523
callScintilla(SCI_STYLESETUNDERLINE, 7 /* = style number */, 1 /* = underline */);
506524
callScintilla(SCI_STYLESETHOTSPOT, 7, 1);
525+
526+
// 8 is colored stdout
527+
callScintilla(SCI_STYLESETSIZE, 8 /* = style number */, 8 /* = size in points */);
528+
callScintilla(SCI_STYLESETFORE, 8, m_colorOutput ? m_user_color : 0); // green
507529

508530
callScintilla(SCI_USEPOPUP, 0);
509531
callScintilla(SCI_SETLEXER, SCLEX_CONTAINER);
@@ -529,6 +551,31 @@ LRESULT ConsoleDialog::scintillaWndProc(HWND hWnd, UINT message, WPARAM wParam,
529551
return CallWindowProc(s_originalScintillaWndProc, hWnd, message, wParam, lParam);
530552
}
531553

554+
void ConsoleDialog::writeCmdText(size_t length, const char *text)
555+
{
556+
::SendMessage(m_scintilla, SCI_SETREADONLY, 0, 0);
557+
for (idx_t i = 0; i < length; ++i)
558+
{
559+
if (text[i] == '\r')
560+
{
561+
::SendMessage(m_scintilla, SCI_APPENDTEXT, i, reinterpret_cast<LPARAM>(text));
562+
text += i + 1;
563+
length -= i + 1;
564+
i = 0;
565+
}
566+
}
567+
568+
if (length > 0)
569+
{
570+
::SendMessage(m_scintilla, SCI_APPENDTEXT, length, reinterpret_cast<LPARAM>(text));
571+
}
572+
573+
::SendMessage(m_scintilla, SCI_SETREADONLY, 1, 0);
574+
575+
::SendMessage(m_scintilla, SCI_GOTOPOS, ::SendMessage(m_scintilla, SCI_GETLENGTH, 0, 0), 0);
576+
577+
}
578+
532579
void ConsoleDialog::writeText(size_t length, const char *text)
533580
{
534581
::SendMessage(m_scintilla, SCI_SETREADONLY, 0, 0);
@@ -554,6 +601,39 @@ void ConsoleDialog::writeText(size_t length, const char *text)
554601

555602
}
556603

604+
void ConsoleDialog::writeColoredText(size_t length, const char *text)
605+
{
606+
size_t docLength = (size_t)callScintilla(SCI_GETLENGTH);
607+
size_t realLength = length;
608+
callScintilla(SCI_SETREADONLY, 0);
609+
for (idx_t i = 0; i < length; ++i)
610+
{
611+
if (text[i] == '\r')
612+
{
613+
if (i)
614+
{
615+
callScintilla(SCI_APPENDTEXT, i, reinterpret_cast<LPARAM>(text));
616+
}
617+
text += i + 1;
618+
length -= i + 1;
619+
realLength--;
620+
i = 0;
621+
}
622+
}
623+
624+
if (length > 0)
625+
{
626+
callScintilla(SCI_APPENDTEXT, length, reinterpret_cast<LPARAM>(text));
627+
}
628+
629+
callScintilla(SCI_SETREADONLY, 1);
630+
callScintilla(SCI_STARTSTYLING, docLength, 0x01);
631+
callScintilla(SCI_SETSTYLING, realLength, m_colorOutput ? 8 : 0);
632+
633+
634+
callScintilla(SCI_COLOURISE, docLength, -1);
635+
callScintilla(SCI_GOTOPOS, docLength + realLength);
636+
}
557637

558638
void ConsoleDialog::writeError(size_t length, const char *text)
559639
{

PythonScript/src/ConsoleDialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ class ConsoleDialog : public DockingDlgInterface
2727
void doDialog();
2828
void hide();
2929

30+
void writeCmdText(size_t length, const char *text);
3031
void writeText(size_t length, const char *text);
32+
void writeColoredText(size_t length, const char *text);
3133
void writeError(size_t length, const char *text);
3234
void clearText();
3335
void setPrompt(const char *prompt);
36+
const char * getPrompt();
3437
HWND getScintillaHwnd() { return m_scintilla; }
3538

3639
void giveInputFocus() { SetFocus(m_hInput); }
@@ -91,6 +94,8 @@ class ConsoleDialog : public DockingDlgInterface
9194
bool m_runButtonIsRun;
9295

9396
HMENU m_hContext;
97+
bool m_colorOutput;
98+
int m_user_color;
9499

95100
};
96101

PythonScript/src/NotepadPlusWrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,13 +1085,13 @@ bool NotepadPlusWrapper::isSingleView()
10851085
return !IsWindowVisible(splitter_hwnd);
10861086
}
10871087

1088-
void NotepadPlusWrapper::flashWindow(UINT count, DWORD timeout)
1088+
void NotepadPlusWrapper::flashWindow(UINT count, DWORD milliseconds)
10891089
{
10901090
FLASHWINFO flashinfo;
10911091
flashinfo.cbSize = sizeof(flashinfo);
10921092
flashinfo.hwnd = m_nppHandle;
10931093
flashinfo.dwFlags = FLASHW_ALL;
1094-
flashinfo.dwTimeout = timeout;
1094+
flashinfo.dwTimeout = milliseconds;
10951095
flashinfo.uCount = count;
10961096

10971097
FlashWindowEx(&flashinfo);

PythonScript/src/NotepadPython.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void export_notepad()
121121
.def("triggerTabbarContextMenu", &NotepadPlusWrapper::triggerTabbarContextMenu, boost::python::args("view, index2Activate"), "Activates the context menu for provided view and tab index")
122122
.def("disableAutoUpdate", &NotepadPlusWrapper::disableAutoUpdate, "Disables notepad++ auto update functionality")
123123
.def("isSingleView", &NotepadPlusWrapper::isSingleView, "True if only one view is used, False otherwise")
124-
.def("flashWindow", &NotepadPlusWrapper::flashWindow, boost::python::args("count", "timeout"), "Flashes notepad++ for the given count and timeout");
124+
.def("flashWindow", &NotepadPlusWrapper::flashWindow, boost::python::args("count", "milliseconds"), "Flashes notepad++ for the given count and timeout");
125125
boost::python::enum_<LangType>("LANGTYPE")
126126
.value("TXT", L_TEXT)
127127
.value("PHP", L_PHP)

0 commit comments

Comments
 (0)