Problems identifying number of open files
-
I’m facing a strange issue when focusing on files in both the main and secondary views, using
NPPM_GETNBOPENFILES
andNPPM_ACTIVATEDOC
.When I use
NPPM_GETNBOPENFILES
to count open files, the results seem wired as there is oly one file open in N++ but it is showing me:- 0 (total number of files): 2 files
- 1 (files opened in the main view): 1 file
- 2 (files opened in the second view): 1 file
When i focus with
NPPM_ACTIVATEDOC
to focus on these files, it always focuses on the same file, irrespective of specifying MAIN_VIEW or SECOND_VIEW. This results in focusing on the same file twice.I tried using the compare plugin to create a secondary window. Although the file count then seems correct, attempting to focus on a file in the secondary window still results in the main window being focused.
::SendMessage(nppData._nppHandle, NPPM_ACTIVATEDOC, SECOND_VIEW, i);
I want to focus all documents, regardless of whether they are in the main or secondary view, without focusing on the same document twice.
-
If only one View is visible, there is (in my experience) still one “open” in the other View (the
new 1
or equivalent dummy document).If you try to
NPPM_ACTIVATEDOC
a document in a View that’s not visible, Notepad++ will ignore the WPARAM and instead try to activate that index from the visible View instead of the View you specified in the WPARAM.I cannot find a NPPM message that tells whether each view is visible. The PythonScript source code defines notepad.isSingleView() and checks whether the “splitterContainer” is visible or not, to determine if two views are open or just one. If “splitterContainer” is not visible, there’s just one View visible, and
NPPM_GETCURRENTSCINTILLA
will tell you which of the Views is actually active (yes, it can be just the secondary View if you happened to close/move all the tabs from the primary View).So you can implement a similar function for checking for 1-vs-2-visible-views, then only iterate through a View if it’s visible. That way, you won’t try to activate a document from the invisible View.
-
@PeterJones said in Problems identifying number of open files:
I cannot find a NPPM message that tells whether each view is visible.
bool visibleMain = IsWindowVisible(nppData._scintillaMainHandle); bool visibleSecond = IsWindowVisible(nppData._scintillaSecondHandle);
-
@Coises ,
… and this is where you can tell I’ve never written a plugin. ;-)
I’m pretty good at the messages themselves, because of my involvement in the User Manual, and from building up a whole Perl library of SendMessage calls to interface with N++ from the outside.
But the inside stuff, including what data structures are available inside a plugin that don’t have a messaging interface, are outside my experience. :-)
So yes, that’s much simpler than looking for the splitterContainer and then doing a message to figure out the active View.
-
The
IsWindowVisible
command significantly helped to narrow down the problem. With this command, I was able to focus only on the actually visible files.However, I’ve encountered another issue that I need to address. Previously, I had only one Scintilla handler set up for the main view only. I now realize that I need to check with
NPPM_GETCURRENTSCINTILLA
which view to use before performing each action.…the fix has been implemented! I’m really pleased that this issue could be resolved so easily!
Thanks -> @Coises , @PeterJones
-
@Thomas-Knoefel said in Problems identifying number of open files:
I now realize that I need to check with NPPM_GETCURRENTSCINTILLA which view to use before performing each action.
Everybody says that, but it’s not quite right! It turns out that you can handle multi-instance mode just fine in the following way:
- Have a globally accessible Scintilla handle that is initialized with
NPPM_GETCURRENTSCINTILLA
when your plugin starts up - whenever the plugin receives an
NPPN_BUFFERACTIVATED
notification, re-initialize your Scintilla handle withNPPM_GETCURRENTSCINTILLA
.
I do this in JsonTools, and it handles multi-instance fine.
Granted, that’s a C# plugin, and your C++ plugin(s) may need to deal with weird pointer issues that I don’t have in my happy little garbage-collected world.
- Have a globally accessible Scintilla handle that is initialized with
-
That’s a good idea. Stuff like this should be better managed in the background. I will have a look to see if it can be handled with a listener.
-
I needed the number of open tabs in NppExec script, and I found this way:
npp_sendmsg NPPM_GETNBOPENFILES 0 0 // = total, may be wrong +1 set local n ~ $(MSG_RESULT) npp_sendmsg NPPM_GETCURRENTDOCINDEX 0 0 // MainView, returns -1 if view is closed set local n ~ $(n) - ($(MSG_RESULT)<0) npp_sendmsg NPPM_GETCURRENTDOCINDEX 0 1 // SubView, returns -1 if view is closed set local n ~ $(n) - ($(MSG_RESULT)<0) echo $(n) // = right number of open tabs
If somebody knows simpler method, it’s very welcome.