Skip to content

Commit 9a86e5b

Browse files
committed
notepad.loadSession() and notepad.getSessionFiles()
These notepad object functions had not been exported (or tested!) Many thanks to user kankri, who pointed this out.
1 parent 2619364 commit 9a86e5b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

PythonScript/src/NotepadPlusWrapper.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,13 @@ boost::python::list NotepadPlusWrapper::getFiles()
281281
boost::python::list NotepadPlusWrapper::getSessionFiles(const char *sessionFilename)
282282
{
283283
boost::python::list result;
284-
285-
idx_t count = (idx_t)callNotepad(NPPM_GETNBSESSIONFILES, 0, reinterpret_cast<LPARAM>(sessionFilename));
284+
#ifdef UNICODE
285+
std::shared_ptr<TCHAR> converted = WcharMbcsConverter::char2tchar(sessionFilename);
286+
const TCHAR *convertedSessionFilename = converted.get();
287+
#else
288+
const TCHAR *convertedSessionFilename = sessionFilename;
289+
#endif
290+
idx_t count = (idx_t)callNotepad(NPPM_GETNBSESSIONFILES, 0, reinterpret_cast<LPARAM>(convertedSessionFilename));
286291
if (count > 0)
287292
{
288293
TCHAR **fileNames = (TCHAR **)new TCHAR*[count];
@@ -291,7 +296,7 @@ boost::python::list NotepadPlusWrapper::getSessionFiles(const char *sessionFilen
291296
fileNames[pos] = new TCHAR[MAX_PATH];
292297
}
293298

294-
if (callNotepad(NPPM_GETSESSIONFILES, 0, reinterpret_cast<LPARAM>(fileNames)))
299+
if (callNotepad(NPPM_GETSESSIONFILES, reinterpret_cast<WPARAM>(fileNames), reinterpret_cast<LPARAM>(convertedSessionFilename)))
295300
{
296301

297302
for(idx_t pos = 0; pos < count; pos++)
@@ -334,7 +339,7 @@ void NotepadPlusWrapper::saveSession(const char *sessionFilename, boost::python:
334339

335340
for(idx_t pos = 0; pos < filesCount; pos++)
336341
{
337-
filesList[pos] = WcharMbcsConverter::char2tchar(static_cast<const char*>(boost::python::extract<const char *>(files[0])));
342+
filesList[pos] = WcharMbcsConverter::char2tchar(static_cast<const char*>(boost::python::extract<const char *>(files[pos])));
338343
si.files[pos] = filesList[pos].get();
339344
}
340345

PythonScript/src/NotepadPython.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ void export_notepad()
2828
.def("getCurrentLang", &NotepadPlusWrapper::getCurrentLangType, "Get the current language type (returns the LANGTYPE.xxx constants)")
2929
.def("setCurrentLang", &NotepadPlusWrapper::setCurrentLangType, "Set the current language type (use LANGTYPE.xxx constants)")
3030
.def("getFiles", &NotepadPlusWrapper::getFiles, "Gets a list of the open filenames, as a list of tuples (filename, bufferID, index, view)")
31+
.def("loadSession", &NotepadPlusWrapper::loadSession, "Loads a session from a session file")
3132
.def("saveSession", &NotepadPlusWrapper::saveSession, "Saves a session file with the list of files (sessionFilename, filesList)")
33+
.def("getSessionFiles", &NotepadPlusWrapper::getSessionFiles, "Gets a list of files within a session file")
3234
.def("saveCurrentSession", &NotepadPlusWrapper::saveCurrentSession, "Save the current session (filename)")
3335
.def("createScintilla", &NotepadPlusWrapper::createScintilla, "Create a new Scintilla handle. Returns a Buffer object")
3436
.def("destroyScintilla", &NotepadPlusWrapper::destroyScintilla, "Destroy a Scintilla handle created with createScintilla")
@@ -51,6 +53,8 @@ void export_notepad()
5153
.def("setLangType", &NotepadPlusWrapper::setBufferLangType, "Sets the language type of the current buffer. Pass a buffer ID as the second parameter to set the language for a specific buffer.")
5254
.def("getEncoding", &NotepadPlusWrapper::getEncoding, "Gets the encoding of the current buffer. Pass a buffer ID to get the encoding of a specific buffer.")
5355
.def("getEncoding", &NotepadPlusWrapper::getBufferEncoding, "Gets the encoding of the current buffer. Pass a buffer ID to get the encoding of a specific buffer.")
56+
.def("setEncoding", &NotepadPlusWrapper::setEncoding, "Sets the encoding of the current buffer. Pass a buffer ID to set the encoding of a specific buffer.")
57+
.def("setEncoding", &NotepadPlusWrapper::setBufferEncoding, "Sets the encoding of the current buffer. Pass a buffer ID to set the encoding of a specific buffer.")
5458
.def("getFormatType", &NotepadPlusWrapper::getFormatType, "Gets the format type (i.e. Windows, Unix or Mac) of the current buffer. Pass a buffer ID to get the format type of a specific buffer.")
5559
.def("getFormatType", &NotepadPlusWrapper::getBufferFormatType, "Gets the format type (i.e. Windows, Unix or Mac) of the current buffer. Pass a buffer ID to get the format type of a specific buffer.")
5660
.def("setFormatType", &NotepadPlusWrapper::setFormatType, "Sets the format type (i.e. Windows, Unix or Mac) of the current buffer - use the FORMATTYPE enum. Pass a buffer ID as the second parameter to set the format type of a specific buffer.")

0 commit comments

Comments
 (0)