33
44#include " Python.h"
55
6+ #include " ScintillaWrapper.h"
7+ #include " ScintillaPython.h"
8+
69using namespace std ;
710
8- PythonHandler::PythonHandler (char *pluginsDir, char *configDir)
11+ PythonHandler::PythonHandler (char *pluginsDir, char *configDir, HWND nppHandle, HWND scintilla1Handle, HWND scintilla2Handle )
912 : m_machineBaseDir(pluginsDir),
10- m_userBaseDir(configDir)
13+ m_userBaseDir(configDir),
14+ m_nppHandle(nppHandle),
15+ m_scintilla1Handle(scintilla1Handle),
16+ m_scintilla2Handle(scintilla2Handle)
1117{
1218 m_machineBaseDir.append (" \\ PythonScript\\ " );
1319 m_userBaseDir.append (" \\ PythonScript\\ " );
20+
21+ mp_scintilla = createScintillaWrapper ();
1422}
1523
1624
@@ -23,14 +31,23 @@ PythonHandler::~PythonHandler(void)
2331 }
2432}
2533
34+ ScintillaWrapper* PythonHandler::createScintillaWrapper ()
35+ {
36+ // Default to 1st scintilla handle initially
37+ return new ScintillaWrapper (m_scintilla1Handle);
38+ }
39+
2640
2741void PythonHandler::initPython ()
2842{
2943 if (Py_IsInitialized ())
3044 return ;
3145
46+
47+ preinitScintillaModule ();
48+
3249 Py_Initialize ();
33-
50+
3451
3552 // Init paths
3653 char initBuffer[1024 ];
@@ -55,12 +72,7 @@ void PythonHandler::initPython()
5572
5673void PythonHandler::initModules ()
5774{
58- // Py_InitModule("notepad", notepadMethods);
59- // Py_InitModule("buffer", bufferMethods);
60-
61- // PyRun_SimpleString("import notepad\n"
62- // "import buffer\n");
63-
75+ importScintilla (mp_scintilla);
6476}
6577
6678
@@ -69,7 +81,7 @@ void PythonHandler::runStartupScripts()
6981 // Machine scripts (N++\Plugins\PythonScript\scripts dir)
7082 string startupPath (m_machineBaseDir);
7183 startupPath.append (" scripts\\ startup.py" );
72- if (fileExists (startupPath.c_str ()))
84+ if (:: PathFileExistsA (startupPath.c_str ()))
7385 {
7486
7587 runScript (startupPath);
@@ -78,32 +90,14 @@ void PythonHandler::runStartupScripts()
7890 // User scripts ($CONFIGDIR$\PythonScript\scripts dir)
7991 startupPath = m_userBaseDir;
8092 startupPath.append (" scripts\\ startup.py" );
81- if (fileExists (startupPath.c_str ()))
93+ if (:: PathFileExistsA (startupPath.c_str ()))
8294 {
8395 runScript (startupPath);
8496 }
8597
8698}
8799
88100
89- bool PythonHandler::fileExists (const char *fileName)
90- {
91- DWORD fileAttr;
92-
93- fileAttr = GetFileAttributesA (fileName);
94- if (0xFFFFFFFF == fileAttr)
95- return false ;
96- return true ;
97- }
98-
99- void PythonHandler::reinitPython ()
100- {
101- if (Py_IsInitialized ())
102- Py_Finalize ();
103-
104- initPython ();
105- }
106-
107101
108102bool PythonHandler::runScript (const string& scriptFile)
109103{
@@ -113,12 +107,10 @@ bool PythonHandler::runScript(const string& scriptFile)
113107bool PythonHandler::runScript (const char *filename)
114108{
115109 bool retVal = false ;
116- int filenameLength = strlen (filename) + 1 ;
117- char *copyFilename = (char *) malloc (filenameLength);
118- strcpy_s (copyFilename, filenameLength, filename);
119110
120111 // Why doesn't PyFile_FromString take a const?
121- PyObject* pyFile = PyFile_FromString (copyFilename, " r" );
112+ // It doesn't modify the string, so const_cast is safe
113+ PyObject* pyFile = PyFile_FromString (const_cast <char *>(filename), " r" );
122114 if (pyFile)
123115 {
124116 PyRun_SimpleFile (PyFile_AsFile (pyFile), filename);
0 commit comments