Skip to content

Commit 27c40a6

Browse files
committed
0.6.2.1 - Release
- Fix bug with console.show() - Regenerate for Scintilla 2.12 (as per N++ 5.7) - Add editor1 and editor2 objects - Fix bug with pymlreplace - Temporary download locations - scripts dir added (Samples and standard startup.py)
1 parent 242b8d5 commit 27c40a6

36 files changed

Lines changed: 526 additions & 57 deletions

PythonScript/include/PythonScript/NppPythonScript.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
*/
2424
#define PYSCR_EXECSTATEMENT (PYSCR_START+1)
2525

26+
/** Show/Create the console window
27+
* No arguments
28+
*/
29+
#define PYSCR_SHOWCONSOLE (PYSCR_START+2)
2630

2731
/** Use PYSCRF_SYNC in the flags member to run the script or statement
2832
* synchronously (i.e. within the same thread). The SendMessage() call

PythonScript/src/ConsoleDialog.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
278278
::SendMessage(m_scintilla, SCI_SETREADONLY, 1, 0);
279279
::SendMessage(m_scintilla, SCI_STYLESETSIZE, 0 /* = style number */, 8 /* = size in points */);
280280
::SendMessage(m_scintilla, SCI_STYLESETSIZE, 1 /* = style number */, 8 /* = size in points */);
281+
::SendMessage(m_scintilla, SCI_STYLESETFORE, 1, RGB(250, 0, 0));
282+
281283
}
282284

283285
void ConsoleDialog::writeText(int length, const char *text)
@@ -292,6 +294,24 @@ void ConsoleDialog::writeText(int length, const char *text)
292294
}
293295

294296

297+
void ConsoleDialog::writeError(int length, const char *text)
298+
{
299+
300+
301+
302+
::SendMessage(m_scintilla, SCI_SETREADONLY, 0, 0);
303+
304+
::SendMessage(m_scintilla, SCI_APPENDTEXT, length, reinterpret_cast<LPARAM>(text));
305+
::SendMessage(m_scintilla, SCI_SETREADONLY, 1, 0);
306+
307+
int docLength = ::SendMessage(m_scintilla, SCI_GETLENGTH, 0, 0);
308+
::SendMessage(m_scintilla, SCI_STARTSTYLING, docLength - length, 255);
309+
::SendMessage(m_scintilla, SCI_SETSTYLING, length, 1);
310+
::SendMessage(m_scintilla, SCI_GOTOPOS, docLength, 0);
311+
312+
}
313+
314+
295315
void ConsoleDialog::doDialog()
296316
{
297317
if (!isCreated())
@@ -324,6 +344,11 @@ void ConsoleDialog::doDialog()
324344
display(true);
325345
}
326346

347+
void ConsoleDialog::hide()
348+
{
349+
display(false);
350+
}
351+
327352
void ConsoleDialog::runEnabled(bool enabled)
328353
{
329354
//EnableWindow(GetDlgItem(_hSelf, IDC_RUN), enabled);

PythonScript/src/ConsoleDialog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void export_console();
99

1010
class ConsoleInterface;
1111

12-
class ConsoleDialog : DockingDlgInterface
12+
class ConsoleDialog : public DockingDlgInterface
1313
{
1414
public:
1515
ConsoleDialog();
@@ -18,9 +18,12 @@ class ConsoleDialog : DockingDlgInterface
1818
void init(HINSTANCE hInst, NppData nppData, ConsoleInterface *console);
1919

2020
void doDialog();
21+
void hide();
22+
2123
BOOL CALLBACK run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
2224

2325
void writeText(int length, const char *text);
26+
void writeError(int length, const char *text);
2427
void clearText();
2528
void setPrompt(const char *prompt);
2629
HWND getScintillaHwnd() { return m_scintilla; };

PythonScript/src/HelpController.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ string HelpController::getTopicUrl()
125125
url.append(buffer + dotPosition + 1);
126126
}
127127

128-
if (dotPosition - startPosition == 6 && 0 == _strnicmp((buffer + startPosition), "editor", dotPosition - startPosition))
128+
if ((dotPosition - startPosition == 6 && 0 == _strnicmp((buffer + startPosition), "editor", dotPosition - startPosition))
129+
|| (dotPosition - startPosition == 7 && 0 == _strnicmp((buffer + startPosition), "editor1", dotPosition - startPosition))
130+
|| (dotPosition - startPosition == 7 && 0 == _strnicmp((buffer + startPosition), "editor2", dotPosition - startPosition)))
129131
{
130132
url = "scintilla.html#Editor.";
131133
url.append(buffer + dotPosition + 1);

PythonScript/src/NotepadPlusWrapper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,13 @@ void NotepadPlusWrapper::activateBufferID(int bufferID)
733733
callNotepad(NPPM_ACTIVATEDOC, view, index);
734734
Py_END_ALLOW_THREADS
735735
}
736-
736+
boost::python::str NotepadPlusWrapper::getBufferFilename(int bufferID)
737+
{
738+
TCHAR buffer[MAX_PATH];
739+
callNotepad(NPPM_GETFULLPATHFROMBUFFERID, bufferID, reinterpret_cast<LPARAM>(buffer));
740+
shared_ptr<char> filename = WcharMbcsConverter::tchar2char(buffer);
741+
return str(const_cast<const char *>(filename.get()));
742+
}
737743

738744
boost::python::str NotepadPlusWrapper::getCurrentFilename()
739745
{

PythonScript/src/NotepadPlusWrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ class NotepadPlusWrapper
517517
boost::python::object promptDefault(boost::python::object promptObj, boost::python::object title)
518518
{ return prompt(promptObj, title, object()); };
519519

520-
boost::python::str NotepadPlusWrapper::getCurrentFilename();
520+
boost::python::str getBufferFilename(int bufferID);
521+
boost::python::str getCurrentFilename();
521522

522523
bool runPluginCommand(boost::python::str pluginName, boost::python::str menuOption);
523524
bool runMenuCommand(boost::python::str menuName, boost::python::str menuOption);

PythonScript/src/NotepadPython.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void export_notepad()
5252
.def("closeAllButCurrent", &NotepadPlusWrapper::closeAllButCurrentDocument, "Closes all but the currently active document")
5353
.def("reloadCurrentDocument", &NotepadPlusWrapper::reloadCurrentDocument, "Reloads the current document")
5454
.def("getCurrentFilename", &NotepadPlusWrapper::getCurrentFilename, "Gets the filename of the active document")
55+
.def("getBufferFilename", &NotepadPlusWrapper::getBufferFilename, "Gets the filename of the given buffer ID")
5556
.def("activateBufferID", &NotepadPlusWrapper::activateBufferID, "Activates the given bufferID")
5657
.def("messageBox", &NotepadPlusWrapper::messageBox, "Displays a message box. messageBox(message, title, flags).\nFlags can be 0 for a standard 'OK' message box, or a combination of MessageBoxFlags")
5758
.def("prompt", &NotepadPlusWrapper::promptDefault, "Prompts the user for some text. enteredText = prompt(prompt, title[, defaultText])")

PythonScript/src/PythonConsole.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
#include "ConsoleDialog.h"
66
#include "PythonHandler.h"
77
#include "ProcessExecute.h"
8+
#include "PluginInterface.h"
9+
#include "Notepad_plus_msgs.h"
10+
#include "PythonScript/NppPythonScript.h"
811

912
using namespace std;
1013
using namespace boost::python;
1114
using namespace NppPythonScript;
1215

13-
PythonConsole::PythonConsole() :
16+
PythonConsole::PythonConsole(HWND hNotepad) :
1417
PyProducerConsumer<const char *>(),
15-
m_consumerStarted(false)
18+
m_consumerStarted(false),
19+
m_hNotepad(hNotepad)
1620
{
1721
mp_consoleDlg = new ConsoleDialog();
1822
m_statementRunning = CreateEvent(NULL, FALSE, TRUE, NULL);
@@ -67,11 +71,32 @@ void PythonConsole::initPython(PythonHandler *pythonHandler)
6771

6872
}
6973

74+
void PythonConsole::pythonShowDialog()
75+
{
76+
// Post the message to ourselves (on the right thread) to create the window
77+
if (!mp_consoleDlg->isCreated())
78+
{
79+
CommunicationInfo commInfo;
80+
commInfo.internalMsg = PYSCR_SHOWCONSOLE;
81+
commInfo.srcModuleName = _T("PythonScript.dll");
82+
TCHAR pluginName[] = _T("PythonScript.dll");
83+
::SendMessage(m_hNotepad, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM>(pluginName), reinterpret_cast<LPARAM>(&commInfo));
84+
}
85+
else
86+
{
87+
mp_consoleDlg->doDialog();
88+
}
89+
}
90+
7091
void PythonConsole::showDialog()
7192
{
7293
mp_consoleDlg->doDialog();
7394
}
7495

96+
void PythonConsole::hideDialog()
97+
{
98+
mp_consoleDlg->hide();
99+
}
75100

76101
void PythonConsole::message(const char *msg)
77102
{
@@ -93,6 +118,11 @@ void PythonConsole::writeText(object text)
93118
mp_consoleDlg->writeText(len(text), (const char *)extract<const char *>(text.attr("__str__")()));
94119
}
95120

121+
void PythonConsole::writeError(object text)
122+
{
123+
mp_consoleDlg->writeError(len(text), (const char *)extract<const char *>(text.attr("__str__")()));
124+
}
125+
96126
void PythonConsole::stopStatement()
97127
{
98128
DWORD threadID;
@@ -185,6 +215,10 @@ void export_console()
185215
{
186216
class_<PythonConsole>("Console", no_init)
187217
.def("write", &PythonConsole::writeText, "Writes text to the console. Uses the __str__ function of the object passed.")
218+
.def("clear", &PythonConsole::clear, "Clears the console window")
219+
.def("writeError", &PythonConsole::writeError, "Writes text in the console in a red colour")
220+
.def("show", &PythonConsole::pythonShowDialog, "Shows the console")
221+
.def("hide", &PythonConsole::hideDialog, "Hides the console")
188222
.def("run", &PythonConsole::runCommand, "Runs a command on the console")
189223
.def("run", &PythonConsole::runCommandNoStderr, "Runs a command on the console")
190224
.def("run", &PythonConsole::runCommandNoStdout, "Runs a command on the console");

PythonScript/src/PythonConsole.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ struct RunStatementArgs;
1313
class PythonConsole : public NppPythonScript::PyProducerConsumer<const char *>, ConsoleInterface
1414
{
1515
public:
16-
PythonConsole();
16+
PythonConsole(HWND hNotepad);
1717
~PythonConsole();
1818

1919
void init(HINSTANCE hInst, NppData nppData);
2020
void initPython(PythonHandler *pythonHandler);
21+
2122
void showDialog();
23+
// Show console but fire a message to get it created on the right thread.
24+
void pythonShowDialog();
25+
void hideDialog();
2226

2327
void message(const char *msg);
2428
void writeText(boost::python::object text);
29+
void writeError(boost::python::object text);
2530
void clear();
2631
void stopScript();
2732

@@ -57,6 +62,7 @@ class PythonConsole : public NppPythonScript::PyProducerConsumer<const char *>,
5762
PyThreadState* mp_mainThreadState;
5863
HANDLE m_statementRunning;
5964
HANDLE m_hThread;
65+
HWND m_hNotepad;
6066
bool m_consumerStarted;
6167
};
6268

PythonScript/src/PythonHandler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ PythonHandler::PythonHandler(char *pluginsDir, char *configDir, HINSTANCE hInst,
3333

3434
mp_notepad = createNotepadPlusWrapper();
3535
mp_scintilla = createScintillaWrapper();
36+
mp_scintilla1 = new ScintillaWrapper(scintilla1Handle);
37+
mp_scintilla2 = new ScintillaWrapper(scintilla2Handle);
3638

3739
}
3840

@@ -110,7 +112,7 @@ void PythonHandler::initPython()
110112

111113
void PythonHandler::initModules()
112114
{
113-
importScintilla(mp_scintilla);
115+
importScintilla(mp_scintilla, mp_scintilla1, mp_scintilla2);
114116
importNotepad(mp_notepad);
115117
importConsole(mp_console);
116118
}
@@ -146,7 +148,7 @@ bool PythonHandler::runScript(const string& scriptFile,
146148
HANDLE completedEvent /* = NULL */,
147149
bool isStatement /* = false */)
148150
{
149-
return runScript(scriptFile.c_str(), synchronous, allowQueuing, completedEvent);
151+
return runScript(scriptFile.c_str(), synchronous, allowQueuing, completedEvent, isStatement);
150152
}
151153

152154

0 commit comments

Comments
 (0)