NPP C# plugin - How to get the list of Notepad++'s open files.
-
“This ANSI plugin is not compatible with your Unicode Notepad++” What am I doing wrong? Am I using the wrong C# plugin templete?
You also asked this SAME question in this OTHER thread:
https://notepad-plus-plus.org/community/topic/14495/npp-c-plugin-template-for-unicodeWas @dail 's answer in that other thread not correct or insufficient?
-
I made a lot of confusion, so sorry.
You didn’t suggest to download the C# template from file-upload.net.
Reading your kind post I thought it was right place from which download it. I was evidently wrong also because that template doesn’t work ( “This ANSI plugin is not compatible with your Unicode Notepad++” issue).Let’s start from the beginning.
Can you suggest where to get the demo C# template you talked about and where you get the SendMessage example?
Regards
Alessandro -
the plugin template is from kblisted as stated in your other post, to be exact it is from
https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net
If you downloaded from this site you should have a Demo Plugin folder which contains the
demo.cs file which itself has several SendMessage examples.The error about unicode and ansi version is coming from notepadd++.
What it does is, simple explanation, notepad++ loads your plugin dll and is calling
a dll function called isUnicode(). If this function returns true then npp assumes it is
a valid unicode plugin. If this function cannot be called, because you didn’t implement it or it returns false, then it throws this error.
The plugin template has this function already defined within UnmanagedExports.cs.Makes this sense to you?
Cheers
Claudia -
Dear Claudia,
I want to thank you so much for the precious help you gave me.
Everything is clear now. Right C# template, right demo project, exactly what I was looking for. The reason of the NPP’s incompatible dll message when NPP stars is now clear.
I greatly appreciated your patience and the clarity of your explanation thanks to which I fully understood.
Cheers
Alessandro -
-
Can you explain me why the method saveCurrentSessionDemo present in the Demo NPP C# plugin, even if the Win32.SendMessage return the full path of the file to be saved (i.e. C:\text.txt) the file text.txt is not created. It happens only if the static string sessionFilePath = @“C:\text.txt”" and it doesn’t if *static string sessionFilePath = @“C:\Users\USR1\Desktop\text.txt”.
Here is the source code of the saveCurrentSessionDemo
static void saveCurrentSessionDemo()
{
string sessionPath = Marshal.PtrToStringUni(Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_SAVECURRENTSESSION, 0, sessionFilePath));
if (!string.IsNullOrEmpty(sessionPath))
MessageBox.Show(sessionPath, “Saved Session File :”, MessageBoxButtons.OK);
}Regards and thanks in advance
Alessandro -
I’m a little bit confused about what is working and what doesn’t.
Are you saying if you specify sessionFilePath = “C:\text.txt” it is working
but if you specify sessionFilePath = “C:\Users\USR1\Desktop\text.txt"
it does not work?Or is it vice versa?
As I’m not a csharp developer I tried this with python and both ways work for me
so I have to assume that the path C:\Users\USR1\Desktop does not exist or permissions
problems happen.Cheers
Claudia -
You confusion comes from the fact I’m not a native english, sorry.
But yes in my case sessionFilePath = “C:\text.txt” doesn’t work. It also for me a matter of permissions. Then the question is Win32.SendMessage doesn’t return a path null or empty as the file ins’t created.Thank you so much.
Alessandro -
I tried this with python and it is behaving the same. I don’t get an info that the call failed.
I did a quick look to the npp source code and it looks like we should get the infocase NPPM_SAVECURRENTSESSION: { return (LRESULT)fileSaveSession(0, NULL, reinterpret_cast<const TCHAR *>(lParam)); }
and
const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save) { if (sessionFile2save) { Session currentSession; if ((nbFile) && (fileNames)) { for (size_t i = 0 ; i < nbFile ; ++i) { if (PathFileExists(fileNames[i])) currentSession._mainViewFiles.push_back(generic_string(fileNames[i])); } } else getCurrentOpenedFiles(currentSession); (NppParameters::getInstance())->writeSession(currentSession, sessionFile2save); return sessionFile2save; } return NULL; }
In case of success it should return the full path, in case of error NULL.
So I assume, this isn’t correctly implemented, either in python and c# plugin pack
or npp. Hmm, as I do not have a windows operating system anymore I can hardly test it. Sorry.Cheers
Claudia -
@Alessandro
BGuenthner has good answer here for get all open files and current open files include new tab
https://sourceforge.net/p/notepad-plus/discussion/482781/thread/90ae2b1a/