Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

change GetFilePath param from int to IntPtr #106

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Demo Plugin/NppManagedPluginDemo/Demo.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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; }}
Expand All @@ -56,6 +61,7 @@ class Main
static string sectionName = "Insert Extension";
static string keyName = "doCloseTag";
static bool doCloseTag = false;
static List<string> filesClosedThisSession = new List<string>();
static string sessionFilePath = @"C:\text.session";
static frmGoToLine frmGoToLine = null;
static internal int idFrmGotToLine = -1;
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public bool OpenFile(string path)
/// <summary>
/// Gets the path of the current document.
/// </summary>
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);
Expand Down