diff --git a/Demo Plugin/NppManagedPluginDemo/Demo.cs b/Demo Plugin/NppManagedPluginDemo/Demo.cs index 382d0fe..fce807f 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,8 +142,8 @@ static internal void CommandMenuInit() PluginBase.SetCommand(16, "---", null); PluginBase.SetCommand(17, "Print Scroll and Row Information", PrintScrollInformation); - - PluginBase.SetCommand(18, "Use NanInf class for -inf, inf, nan!!", PrintNanInf); + PluginBase.SetCommand(18, "Show files closed this session", filesClosedDemo); + PluginBase.SetCommand(19, "Use NanInf class for -inf, inf, nan!!", PrintNanInf); } /// @@ -355,6 +361,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);