Skip to content

Commit b9bde2d

Browse files
authored
Addresses issue bruderstein#105 to ensure file activation works reliably, even when the long path handling fails. (bruderstein#362)
1 parent 469672d commit b9bde2d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

PythonScript/python_tests/tests/test_NotepadWrapperTestCase.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,28 @@ def test_isAutoIndention(self):
16281628
''' '''
16291629
self.__test_invalid_parameter_passed(notepad.isAutoIndention)
16301630

1631+
def test_activateFile(self):
1632+
# Create and open two files
1633+
file1 = self.get_temp_filename()
1634+
file2 = self.get_temp_filename()
1635+
self.assertTrue(notepad.open(file1))
1636+
self.assertTrue(notepad.open(file2))
1637+
1638+
# open two temp files
1639+
notepad.new()
1640+
temp_1 = notepad.getCurrentFilename()
1641+
notepad.new()
1642+
temp_2 = notepad.getCurrentFilename()
1643+
1644+
self.assertTrue(notepad.activateFile(file1))
1645+
notepad.close()
1646+
self.assertTrue(notepad.activateFile(temp_1))
1647+
notepad.close()
1648+
self.assertTrue(notepad.activateFile(file2))
1649+
notepad.close()
1650+
self.assertTrue(notepad.activateFile(temp_2))
1651+
notepad.close()
1652+
16311653

16321654
suite = unittest.TestLoader().loadTestsFromTestCase(NotepadTestCase)
16331655

PythonScript/src/NotepadPlusWrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,14 @@ bool NotepadPlusWrapper::activateFileString(boost::python::str filename)
441441
{
442442
notAllowedInScintillaCallback("activateFile() cannot be called in a synchronous editor callback. "
443443
"Use an asynchronous callback, or avoid using activateFile() in the callback handler");
444-
return handleFileNameToLongPath(NPPM_SWITCHTOFILE, filename);
444+
bool res = handleFileNameToLongPath(NPPM_SWITCHTOFILE, filename);
445+
446+
if (!res) {
447+
// issue 105
448+
std::shared_ptr<TCHAR> tfileName = WcharMbcsConverter::char2tchar(boost::python::extract<const char*>(filename));
449+
return static_cast<bool>(callNotepad(NPPM_SWITCHTOFILE, 0, reinterpret_cast<LPARAM>(tfileName.get())));
450+
}
451+
return res;
445452
}
446453

447454
bool NotepadPlusWrapper::reloadFile(boost::python::str filename, bool alert)

0 commit comments

Comments
 (0)