From b24233f699826760bd31050f7ec38e8d77842556 Mon Sep 17 00:00:00 2001 From: molsonkiko <46202915+molsonkiko@users.noreply.github.com> Date: Wed, 26 Apr 2023 08:13:27 -0700 Subject: [PATCH 1/2] change GetFilePath param from int to IntPtr Previously the GetFilePath method of NotepadPPGateway was unusable in 64-bit Notepad++ because it accepted an int parameter, but the buffer id (the IdFrom parameter of the NPPN_FILEBEFORECLOSE notification) could be 64-bit. Also added a new plugin command to Demo.cs illustrating how tracking the NPPN_FILEBEFORECLOSE notification allows the plugin to keep a list of all the filenames that were closed this session. --- Demo Plugin/NppManagedPluginDemo/Demo.cs | 20 +++++++++++++++++++ .../PluginInfrastructure/NotepadPPGateway.cs | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Demo Plugin/NppManagedPluginDemo/Demo.cs b/Demo Plugin/NppManagedPluginDemo/Demo.cs index 96bae70..4cb1860 100644 --- a/Demo Plugin/NppManagedPluginDemo/Demo.cs +++ b/Demo Plugin/NppManagedPluginDemo/Demo.cs @@ -1,5 +1,6 @@ // NPP plugin platform for .Net v0.91.57 by Kasper B. Graversen etc. using System; +using System.Collections.Generic; using System.IO; using System.Text; using System.Drawing; @@ -40,6 +41,10 @@ public static void OnNotification(ScNotification notification) { Kbg.Demo.Namespace.Main.doInsertHtmlCloseTag((char)notification.Character); } + else if (notification.Header.Code == (uint)NppMsg.NPPN_FILEBEFORECLOSE) + { + Kbg.Demo.Namespace.Main.addFileToFilesClosed(notification.Header.IdFrom); + } } internal static string PluginName { get { return Kbg.Demo.Namespace.Main.PluginName; }} @@ -56,6 +61,7 @@ class Main static string sectionName = "Insert Extension"; static string keyName = "doCloseTag"; static bool doCloseTag = false; + static List filesClosedThisSession = new List(); static string sessionFilePath = @"C:\text.session"; static frmGoToLine frmGoToLine = null; static internal int idFrmGotToLine = -1; @@ -136,6 +142,7 @@ static internal void CommandMenuInit() PluginBase.SetCommand(16, "---", null); PluginBase.SetCommand(17, "Print Scroll and Row Information", PrintScrollInformation); + PluginBase.SetCommand(18, "Show files closed this session", filesClosedDemo); } /// @@ -353,6 +360,19 @@ static internal void doInsertHtmlCloseTag(char newChar) } } + static internal void addFileToFilesClosed(IntPtr bufClosedId) + { + var bufClosedName = notepad.GetFilePath(bufClosedId); + filesClosedThisSession.Add(bufClosedName); + } + + static void filesClosedDemo() + { + var filesClosed = string.Join("\r\n", filesClosedThisSession); + MessageBox.Show($"Files closed this session:\r\n{filesClosed}", + "Files closed this session"); + } + static void getFileNamesDemo() { int nbFile = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_GETNBOPENFILES, 0, 0); diff --git a/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs b/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs index ff11162..0d8c93a 100644 --- a/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs +++ b/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs @@ -16,7 +16,7 @@ public interface INotepadPPGateway string GetNppPath(); string GetPluginConfigPath(); string GetCurrentFilePath(); - unsafe string GetFilePath(int bufferId); + unsafe string GetFilePath(IntPtr bufferId); void SetCurrentLanguage(LangType language); bool OpenFile(string path); } @@ -108,7 +108,7 @@ public bool OpenFile(string path) /// /// Gets the path of the current document. /// - public unsafe string GetFilePath(int bufferId) + public unsafe string GetFilePath(IntPtr bufferId) { var path = new StringBuilder(2000); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_GETFULLPATHFROMBUFFERID, bufferId, path); From e512f50dece70d9ff0332293c5278bd40fdbf52d Mon Sep 17 00:00:00 2001 From: molsonkiko <46202915+molsonkiko@users.noreply.github.com> Date: Fri, 19 May 2023 20:44:25 -0700 Subject: [PATCH 2/2] add missing semicolon fix bug introduced in merge --- Demo Plugin/NppManagedPluginDemo/Demo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Demo Plugin/NppManagedPluginDemo/Demo.cs b/Demo Plugin/NppManagedPluginDemo/Demo.cs index a3936f2..fce807f 100644 --- a/Demo Plugin/NppManagedPluginDemo/Demo.cs +++ b/Demo Plugin/NppManagedPluginDemo/Demo.cs @@ -143,7 +143,7 @@ static internal void CommandMenuInit() PluginBase.SetCommand(17, "Print Scroll and Row Information", PrintScrollInformation); PluginBase.SetCommand(18, "Show files closed this session", filesClosedDemo); - PluginBase.SetCommand(19, "Use NanInf class for -inf, inf, nan!!", PrintNanInf) + PluginBase.SetCommand(19, "Use NanInf class for -inf, inf, nan!!", PrintNanInf); } ///