Hi, I am very new to npppythonscript, but have been a happy user of NP++ and python developer for quite some time.
I am currently trying to get all open filenames in NP++, by using notepad.getFiles() …but that only gives me two entries, even though I have one file open in the left view and five open in the right view.
Playing around with re-arranging the views and order, the notepad.getFiles() output changes - sometimes, even files are listed which are non-existent (such as "New 3", which I had created and closed without saving earlier).
Am I using the wrong function or is this a bug?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm noticing the following behavior with NPP 6.8.3 and PS 1.08:
given NL = number of file tabs in the left (main) view
and NR = number of file tabs in the right (secondary view)
notepad.getFiles() returns correct data when NR <= NL
notepad.getFiles() returns incorrect data when NR > NL. In this case, it appears to internally cap NR at NL.
To say this in a non-nerdy way, if you have more file tabs in the secondary view than the primary view, it doesn't return all of the files in the secondary view.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are pretty much in the right place (the right site) for reporting it. I don't know how committed the author (Dave Brotherstone) is to the Pythonscript plug-in these days. I hope the answer is "very" but I don't see a lot of activity by him here anymore. I think without Pythonscript I would not use NPP, so it is obviously pretty important to me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
you can see that it loops over each view (0 and 1), but then it uses the view int as-is in the call to NPP's NPPM_GETNBOPENFILES message. But according to the documentation ( http://docs.notepad-plus-plus.org/index.php/Messages_And_Notifications ), that message requires the constants PRIMARY_VIEW or SECOND_VIEW, which I don't think are 0 and 1. I think the fix would be to change the line that reads:
I don't have an environment in which I can build PythonScript myself, but if someone wants to try the above fix, I'd be interested to hear how it went...
Last edit: W P Blatchley 2015-10-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think you are likely correct. A search of the NPP source code yields that
ALL_OPEN_FILES is 0
PRIMARY_VIEW is 1
SECOND_VIEW is 2
Somewhat interestingly, another call to callNotepad() a bit further down on line 261:
bufferID = callNotepad(NPPM_GETBUFFERIDFROMPOS, pos, view);
is supposed to use another set of defined values for "view":
"view should be MAIN_VIEW or SUB_VIEW"
In this case, however, MAIN_VIEW is 0 and SUB_VIEW is 1, so it works because the view variable aligns with that.
Whomever introduced PRIMARY_VIEW and SECOND_VIEW really muddied the waters here, in my opinion.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Whomever introduced PRIMARY_VIEW and SECOND_VIEW really muddied the waters here, in my opinion.
Yes, I agree with that. Though I can see why you might want to disassociate your constants from the actual numbers used (to avoid "magic" numbers), in this case I think it would have been wise to keep them in step. ALL_OPEN_FILES could happily have been 2 or something totally different like -1 (if signed is okay).
Anyway, like I said, if anyone can try patching the source with the above potential fix, I would be very grateful. This bug is actually causing me headaches now!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for tracking this down - if that's right, that should be pretty easy to fix. I'll have a crack at it over the next few days (prob won't be the weekend, sorry!)
Hi, I am very new to npppythonscript, but have been a happy user of NP++ and python developer for quite some time.
I am currently trying to get all open filenames in NP++, by using notepad.getFiles() …but that only gives me two entries, even though I have one file open in the left view and five open in the right view.
Playing around with re-arranging the views and order, the notepad.getFiles() output changes - sometimes, even files are listed which are non-existent (such as "New 3", which I had created and closed without saving earlier).
Am I using the wrong function or is this a bug?
I get exactly the same symptoms here. Has anyone else seen this? Is there a known problem?
I'm noticing the following behavior with NPP 6.8.3 and PS 1.08:
given NL = number of file tabs in the left (main) view
and NR = number of file tabs in the right (secondary view)
notepad.getFiles() returns correct data when NR <= NL
notepad.getFiles() returns incorrect data when NR > NL. In this case, it appears to internally cap NR at NL.
To say this in a non-nerdy way, if you have more file tabs in the secondary view than the primary view, it doesn't return all of the files in the secondary view.
Yes, this appears to be a bug. Is there a formal way to report it?
You are pretty much in the right place (the right site) for reporting it. I don't know how committed the author (Dave Brotherstone) is to the Pythonscript plug-in these days. I hope the answer is "very" but I don't see a lot of activity by him here anymore. I think without Pythonscript I would not use NPP, so it is obviously pretty important to me.
I can to NPP before I ever found out about Pythonscript, but now that I know about it, I'm just coming up with more and more uses for it.
Not sure, but I think I may have found the bug. If you look at the getFiles() implementation here:
https://sourceforge.net/p/npppythonscript/code/ci/master/tree/PythonScript/src/NotepadPlusWrapper.cpp#l239
you can see that it loops over each view (0 and 1), but then it uses the view int as-is in the call to NPP's NPPM_GETNBOPENFILES message. But according to the documentation ( http://docs.notepad-plus-plus.org/index.php/Messages_And_Notifications ), that message requires the constants PRIMARY_VIEW or SECOND_VIEW, which I don't think are 0 and 1. I think the fix would be to change the line that reads:
count = (idx_t)callNotepad(NPPM_GETNBOPENFILES, 0, view);
to read:
count = (idx_t)callNotepad(NPPM_GETNBOPENFILES, 0, view ? SECOND_VIEW : PRIMARY_VIEW);
I don't have an environment in which I can build PythonScript myself, but if someone wants to try the above fix, I'd be interested to hear how it went...
Last edit: W P Blatchley 2015-10-16
I think you are likely correct. A search of the NPP source code yields that
ALL_OPEN_FILES is 0
PRIMARY_VIEW is 1
SECOND_VIEW is 2
Somewhat interestingly, another call to callNotepad() a bit further down on line 261:
bufferID = callNotepad(NPPM_GETBUFFERIDFROMPOS, pos, view);
is supposed to use another set of defined values for "view":
"view should be MAIN_VIEW or SUB_VIEW"
In this case, however, MAIN_VIEW is 0 and SUB_VIEW is 1, so it works because the view variable aligns with that.
Whomever introduced PRIMARY_VIEW and SECOND_VIEW really muddied the waters here, in my opinion.
Yes, I agree with that. Though I can see why you might want to disassociate your constants from the actual numbers used (to avoid "magic" numbers), in this case I think it would have been wise to keep them in step. ALL_OPEN_FILES could happily have been 2 or something totally different like -1 (if signed is okay).
Anyway, like I said, if anyone can try patching the source with the above potential fix, I would be very grateful. This bug is actually causing me headaches now!
Thanks for tracking this down - if that's right, that should be pretty easy to fix. I'll have a crack at it over the next few days (prob won't be the weekend, sorry!)
If you could raise an issue https://github.com/bruderstein/PythonScript/issues that'd help.
Thanks
Dave
Brilliant, thanks! Issue raised. See here: https://github.com/bruderstein/PythonScript/issues/22