Question

I am writing a Notepad++ plugin, and need to create a new tab, for a new file. I haven't been able to find anything covering this in the documentation.

The closest I have come is:

IntPtr curScintilla = PluginBase.GetCurrentScintilla();
IntPtr documentPtr = Win32.SendMessage(curScintilla, SciMsg.SCI_CREATEDOCUMENT, 1, 1);
Win32.SendMessage(curScintilla, SciMsg.SCI_SETDOCPOINTER, 0, documentPtr);

but this acts in the current tab (I think it's creating a new document and pointing the current tab at that).

I was reading the "Multiple views" section of http://www.scintilla.org/ScintillaDoc.html but am unable to get any further than the above. I don't normally work in C# or even Windows, so I might be missing something obvious. I tried looking at existing plugins for examples but most of them seem to be written in C++, rather than C#.

Any guidance appreciated.

Thanks.

Was it helpful?

Solution

I have not gone through scintilla. But I used simple approach. I used this for creating, you may need to look for more information for sending the message.

Create file if it doesn't exist in the directory before you start. Else it will ask for user confirmation.

Arguments for the process should differ from the first and next tabs:

File.Create(yourNewFile); //or yourNextNewFile in case of second, third, so on..
Process notepadPlus = new Process();

notepadPlus.StartInfo.FileName = "notepad++.exe";

For the first file use as (new instance with new session - without any old tabs):

notepadPlus.StartInfo.Arguments = @"-multiInst -nosession yourNewFile";

For next files use as (only new tabs will be created):

notepadPlus.StartInfo.Arguments = @"yourNextNewFile";

/* Start the process */
notepadPlus.Start();

OTHER TIPS

You have to send a message not to the Scintilla control, but to Notepad itself. Like this:

Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_NEW);

More informations here including the used constants.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top