how to call the API to rename a new tab?
-
As the title suggests, how to call the API to rename a new tab?
-
I presume you mean you have a
new 4
tab, for example, and you want to rename it but still not save it into the file system, i.e., you want to keep it “soft named”.I asked for this, HERE, and it was rejected by the Notepad++ author with this reasoning:
“I don’t add the features which are requested by (very) few users, and the features in question needs a lot of coding effort.” (SOURCE).See also HERE for a plugin request that would need this N++ support to be fulfilled.
-
@Alan-Kilborn said in how to call the API to rename a new tab?:
it was rejected by the Notepad++ author
Apparently author has reconsidered, see HERE; the issue in question has been reopened.
-
@Alan-Kilborn :: SendMessage (nppData. nppHandle, NPPM-MENUCOMMAND, 0, IDM-FILE-RENAME); Can a naming dialog box be displayed? How can I use the program to operate this pop-up dialog box?
-
This can already be done using
SendMessage(NPPM_INTERNAL_SETFILENAME, intptr_t bufferId, const char * newName);
However, because you are directly calling an internal API and circumventing the normal machinery of Notepad++, callingNPPM_INTERNAL_SETFILENAME
does not automatically trigger theNPPN_FILEBEFFORERENAME
andNPPN_FILERENAMED
notifications, which may cause strange behavior in plugins that respond to those notifications, and is therefore perhaps not a great idea. That said, I do this myself in the JsonTools plugin and it seems to work fine. -
@Mark-Olson said in how to call the API to rename a new tab?:
This can already be done using…
Ah. I was not aware of this.
In the N++ source code near the
NPPM_INTERNAL_SETFILENAME
definition is a comment “Used by netnote plugin”.Plugins Admin shows a
NppNetNote
plugin and a link to its site: https://sourceforge.net/projects/npp-plugins/files/NppDocShare/ although that’s a bit confusing because it is called “share” instead of “note”.Anyway that plugin has a date of 2008 on it, so it is really old and apparently hasn’t been modified since then.
It’s curious why, if a plugin was going to use it, why it wasn’t made into a full-fledged plugin message rather than an “internal” message.
Also interesting is that it provided a means to rename a soft-named tab (e.g.
new 5
) to something less generic, many years before a Notepad++ release allowed such tabs to be renamed. -
@Zhixun-Qu said in how to call the API to rename a new tab?:
SendMessage (nppData. nppHandle, NPPM-MENUCOMMAND, 0, IDM-FILE-RENAME);
I’d think something like that would get you the Rename Current Tab dialog displayed if executed when a soft-named tab is active.
Can a naming dialog box be displayed?
Yes (see above / below).
How can I use the program to operate this pop-up dialog box?
I wouldn’t do this if I were doing it. I’d create my own renaming interface in whatever language I’m writing the plugin in. It gives you more direct control over what’s going on.
For my purposes (and I do have some), I just want to (have a script) rename the softnamed tab with a single (script) command…no popup prompt from N++ wanted (I already know the name I want to give the tab). Thanks to Mark’s posting, I can now achieve this with a little bit of SendMessage code.
-
@Mark-Olson said in how to call the API to rename a new tab?:
calling NPPM_INTERNAL_SETFILENAME does not automatically trigger the NPPN_FILEBEFFORERENAME and NPPN_FILERENAMED notifications,
I can’t think of any circumstance where I’d care about this. But, I suppose it could be important to others…