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

Commit

Permalink
Merge pull request #3 from kbilsted/topic/incorporate_ufo_v.0.7
Browse files Browse the repository at this point in the history
Topic/incorporate ufo v.0.7
  • Loading branch information
kbilsted committed Apr 25, 2016
2 parents 5572c2f + 7dc23c2 commit 4c83dc8
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 26 deletions.
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
# NppPlugin .NET package for VS2015
# NppPlugin .NET package for VS2015 and beyond...

## Fork information
This is a fork of UFO's plugin package http://sourceforge.net/projects/sourcecookifier/files/other%20plugins/NppPlugin.NET.v0.5.zip/download which seems abandoned (and only supports up to visual studio 2010).
This is a fork of UFO's plugin package updated for VS2015



## Content information
This package contains two folders:

1) Visual Studio Project Template C#:
A VS template for very fast and even easier building of .NET plugins for Notepad++.
1. Templates:
Simple templates for very fast and even easier building of .NET plugins for Notepad++.
Setting up a plugin for N++ has never ever been as easy as with this package.
Please See its containing text file for further information.
Please see the containing txt files for further installation information.

2) Demo Plugin:

2. Demo:
An example .NET plugin for Notepad++, build upon the template above.
It demonstrates the same functionality as the original demo plugin by Don HO:
http://notepad-plus.sourceforge.net/commun/pluginDemoTemplate/NppPluginTemplate.zip
I don't know if I've added new bugs, but I've corrected some small mistakes which
are in the original demo. I've also added example code for registering icons for
the tab of a dockable dialog and for Notepad++'s tool bar (and how to toggle its
state).
It demonstrates the same functionality as the original demo plugin by Don Ho:
http://download.tuxfamily.org/nppplugins/NppPluginDemo/NppPluginDemo.zip



## Credits
For the main work on the plugin package
* UFO
* v0.5 http://sourceforge.net/projects/sourcecookifier/files/other%20plugins/NppPlugin.NET.v0.5.zip/download
* and v0.7 https://bitbucket.org/uph0/npppluginnet

## Requirements:
All credits for the used DllExport technique to following guys:
* Dark Daskin: http://www.codeproject.com/KB/dotnet/DllExporter.aspx
* Robert Giesecke: http://sites.google.com/site/robertgiesecke/Home/uploads/csharpprojecttemplateforunmanagedexports https://www.nuget.org/packages/UnmanagedExports


## Requirements:
* works with .NET Runtime 2.0 and above
* UNICODE only! ANSI is doable, but not supported so far

please feel free to contribute!
Binary file modified Visual Studio Project Template C#/DllExport/Mono.Cecil.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="NppPlugin.DllExport.MSBuild.DllExportTask"
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<PostBuildEventDependsOn>
$(PostBuildEventDependsOn);
NppPluginDllExport
</PostBuildEventDependsOn>
</PropertyGroup>

<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
NppPluginDllExport
</BuildDependsOn>
</PropertyGroup>

<UsingTask TaskName="NppPlugin.DllExport.MSBuild.DllExportAppDomainIsolatedTask"
AssemblyFile="NppPlugin.DllExport.MSBuild.dll"/>
<Target Name="AfterBuild"
DependsOnTargets="GetFrameworkPaths"
>
<DllExportTask Platform="$(Platform)"

<Target Name="NppPluginDllExport"
DependsOnTargets="GetFrameworkPaths">

<!--
These properties can still be applied to the task, but upon installation of a
new version of the nuget package, the properties
DllExportAttributeAssemblyName and DllExportAttributeAssemblyName will be removed from the project.
So, if you want to provide an alternative attribute name, the you have to name the property in your project file differently.
e.g.:
DllExportAttributeAssemblyName="$(MyDllExportAttributeAssemblyName)"
DllExportAttributeFullName="$(MyDllExportAttributeFullName)"
-->
<PropertyGroup>
<DllExportLeaveIntermediateFiles Condition="'$(DllExportLeaveIntermediateFiles)'==''">
false
</DllExportLeaveIntermediateFiles>


</PropertyGroup>

<DllExportAppDomainIsolatedTask Platform="$(Platform)"
PlatformTarget="$(PlatformTarget)"
CpuType="$(CpuType)"
EmitDebugSymbols="$(DebugSymbols)"
DllExportAttributeAssemblyName="$(DllExportAttributeAssemblyName)"
DllExportAttributeFullName="$(DllExportAttributeFullName)"
LeaveIntermediateFiles="$(DllExportLeaveIntermediateFiles)"
Timeout="$(DllExportTimeout)"
KeyContainer="$(KeyContainerName)$(AssemblyKeyContainerName)"
KeyFile="$(KeyOriginatorFile)"
Expand All @@ -19,6 +52,8 @@
FrameworkPath="$(TargetedFrameworkDir);$(TargetFrameworkDirectory)"
LibToolPath="$(DevEnvDir)\..\..\VC\bin"
LibToolDllPath="$(DevEnvDir)"
SdkPath="$(SDK40ToolsPath)"/>
TargetFrameworkVersion="$(TargetFrameworkVersion)"
SdkPath="$(SDK40ToolsPath)"
SkipOnAnyCpu="$(NoDllExportsForAnyCpu)"/>
</Target>
</Project>
2 changes: 1 addition & 1 deletion Visual Studio Project Template C#/NppPlugin.vstemplate
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<ProjectItem ReplaceParameters="false" TargetFileName="star.png">star.png</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="star_bmp.bmp">star_bmp.bmp</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="true" TargetFileName="Main.cs">Main.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Main.cs" OpenInEditor="true">Main.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="NppPluginNETBase.cs">NppPluginNETBase.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="NppPluginNETHelper.cs">NppPluginNETHelper.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="UnmanagedExports.cs">UnmanagedExports.cs</ProjectItem>
Expand Down
86 changes: 86 additions & 0 deletions Visual Studio Project Template C#/NppPluginNETHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Kbg.NppPluginNET
Expand Down Expand Up @@ -201,10 +202,17 @@ public enum LangType
L_ASM, L_DIFF, L_PROPS, L_PS, L_RUBY, L_SMALLTALK, L_VHDL, L_KIX, L_AU3,
L_CAML, L_ADA, L_VERILOG, L_MATLAB, L_HASKELL, L_INNO, L_SEARCHRESULT,
L_CMAKE, L_YAML, L_COBOL, L_GUI4CLI, L_D, L_POWERSHELL, L_R, L_JSP,
L_COFFEESCRIPT,
// The end of enumated language type, so it should be always at the end
L_EXTERNAL
}

public enum winVer
{
WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K,
WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81
}

[Flags]
public enum NppMsg : uint
{
Expand Down Expand Up @@ -257,6 +265,9 @@ public enum NppMsg : uint

NPPM_GETMENUHANDLE = (NPPMSG + 25),
NPPPLUGINMENU = 0,
NPPMAINMENU = 1,
// INT NPPM_GETMENUHANDLE(INT menuChoice, 0)
// Return: menu handle (HMENU) of choice (plugin menu handle or Notepad++ main menu handle)

NPPM_ENCODESCI = (NPPMSG + 26),
//ascii file to unicode
Expand Down Expand Up @@ -366,6 +377,7 @@ public enum NppMsg : uint
NPPM_GETPOSFROMBUFFERID = (NPPMSG + 57),
// INT NPPM_GETPOSFROMBUFFERID(INT bufferID, 0)
// Return VIEW|INDEX from a buffer ID. -1 if the bufferID non existing
// if priorityView set to SUB_VIEW, then SUB_VIEW will be search firstly
//
// VIEW takes 2 highest bits and INDEX (0 based) takes the rest (30 bits)
// Here's the values for the view :
Expand All @@ -380,49 +392,58 @@ public enum NppMsg : uint
// allocate fullFilePath with the return values + 1, then call it again to get full path file name

NPPM_GETBUFFERIDFROMPOS = (NPPMSG + 59),
// INT NPPM_GETBUFFERIDFROMPOS(INT index, INT iView)
//wParam: Position of document
//lParam: View to use, 0 = Main, 1 = Secondary
//Returns 0 if invalid

NPPM_GETCURRENTBUFFERID = (NPPMSG + 60),
// INT NPPM_GETCURRENTBUFFERID(0, 0)
//Returns active Buffer

NPPM_RELOADBUFFERID = (NPPMSG + 61),
// VOID NPPM_RELOADBUFFERID(0, 0)
//Reloads Buffer
//wParam: Buffer to reload
//lParam: 0 if no alert, else alert


NPPM_GETBUFFERLANGTYPE = (NPPMSG + 64),
// INT NPPM_GETBUFFERLANGTYPE(INT bufferID, 0)
//wParam: BufferID to get LangType from
//lParam: 0
//Returns as int, see LangType. -1 on error

NPPM_SETBUFFERLANGTYPE = (NPPMSG + 65),
// BOOL NPPM_SETBUFFERLANGTYPE(INT bufferID, INT langType)
//wParam: BufferID to set LangType of
//lParam: LangType
//Returns TRUE on success, FALSE otherwise
//use int, see LangType for possible values
//L_USER and L_EXTERNAL are not supported

NPPM_GETBUFFERENCODING = (NPPMSG + 66),
// INT NPPM_GETBUFFERENCODING(INT bufferID, 0)
//wParam: BufferID to get encoding from
//lParam: 0
//returns as int, see UniMode. -1 on error

NPPM_SETBUFFERENCODING = (NPPMSG + 67),
// BOOL NPPM_SETBUFFERENCODING(INT bufferID, INT encoding)
//wParam: BufferID to set encoding of
//lParam: format
//Returns TRUE on success, FALSE otherwise
//use int, see UniMode
//Can only be done on new, unedited files

NPPM_GETBUFFERFORMAT = (NPPMSG + 68),
// INT NPPM_GETBUFFERFORMAT(INT bufferID, 0)
//wParam: BufferID to get format from
//lParam: 0
//returns as int, see formatType. -1 on error

NPPM_SETBUFFERFORMAT = (NPPMSG + 69),
// BOOL NPPM_SETBUFFERFORMAT(INT bufferID, INT format)
//wParam: BufferID to set format of
//lParam: format
//Returns TRUE on success, FALSE otherwise
Expand Down Expand Up @@ -503,6 +524,51 @@ public enum NppMsg : uint
// Allocates a marker number to a plugin
// Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful

NPPM_GETLANGUAGENAME = (NPPMSG + 83),
// INT NPPM_GETLANGUAGENAME(int langType, TCHAR *langName)
// Get programing language name from the given language type (LangType)
// Return value is the number of copied character / number of character to copy (\0 is not included)
// You should call this function 2 times - the first time you pass langName as NULL to get the number of characters to copy.
// You allocate a buffer of the length of (the number of characters + 1) then call NPPM_GETLANGUAGENAME function the 2nd time
// by passing allocated buffer as argument langName

NPPM_GETLANGUAGEDESC = (NPPMSG + 84),
// INT NPPM_GETLANGUAGEDESC(int langType, TCHAR *langDesc)
// Get programing language short description from the given language type (LangType)
// Return value is the number of copied character / number of character to copy (\0 is not included)
// You should call this function 2 times - the first time you pass langDesc as NULL to get the number of characters to copy.
// You allocate a buffer of the length of (the number of characters + 1) then call NPPM_GETLANGUAGEDESC function the 2nd time
// by passing allocated buffer as argument langDesc

NPPM_SHOWDOCSWITCHER = (NPPMSG + 85),
// VOID NPPM_ISDOCSWITCHERSHOWN(0, BOOL toShowOrNot)
// Send this message to show or hide doc switcher.
// if toShowOrNot is TRUE then show doc switcher, otherwise hide it.

NPPM_ISDOCSWITCHERSHOWN = (NPPMSG + 86),
// BOOL NPPM_ISDOCSWITCHERSHOWN(0, 0)
// Check to see if doc switcher is shown.

NPPM_GETAPPDATAPLUGINSALLOWED = (NPPMSG + 87),
// BOOL NPPM_GETAPPDATAPLUGINSALLOWED(0, 0)
// Check to see if loading plugins from "%APPDATA%\Notepad++\plugins" is allowed.

NPPM_GETCURRENTVIEW = (NPPMSG + 88),
// INT NPPM_GETCURRENTVIEW(0, 0)
// Return: current edit view of Notepad++. Only 2 possible values: 0 = Main, 1 = Secondary

NPPM_DOCSWITCHERDISABLECOLUMN = (NPPMSG + 89),
// VOID NPPM_DOCSWITCHERDISABLECOLUMN(0, BOOL disableOrNot)
// Disable or enable extension column of doc switcher

NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR = (NPPMSG + 90),
// INT NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR(0, 0)
// Return: current editor default foreground color. You should convert the returned value in COLORREF

NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR = (NPPMSG + 91),
// INT NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR(0, 0)
// Return: current editor default background color. You should convert the returned value in COLORREF

RUNCOMMAND_USER = (0x400/*WM_USER*/ + 3000),
NPPM_GETFULLCURRENTPATH = (RUNCOMMAND_USER + FULL_CURRENT_PATH),
NPPM_GETCURRENTDIRECTORY = (RUNCOMMAND_USER + CURRENT_DIRECTORY),
Expand Down Expand Up @@ -2082,6 +2148,8 @@ public class Win32
public static extern IntPtr SendMessage(IntPtr hWnd, NppMsg Msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, NppMsg Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, NppMsg Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lParam);

[DllImport("user32")]
public static extern IntPtr SendMessage(IntPtr hWnd, SciMsg Msg, int wParam, IntPtr lParam);
Expand All @@ -2107,6 +2175,12 @@ public class Win32
public static extern int CheckMenuItem(IntPtr hmenu, int uIDCheckItem, int uCheck);

public const int WM_CREATE = 1;

[DllImport("user32")]
public static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint);

[DllImport("kernel32")]
public static extern void OutputDebugString(string lpOutputString);
}

public class ClikeStringArray : IDisposable
Expand All @@ -2127,6 +2201,18 @@ public ClikeStringArray(int num, int stringCapacity)
}
Marshal.WriteIntPtr((IntPtr)((int)_nativeArray + (num * IntPtr.Size)), IntPtr.Zero);
}
public ClikeStringArray(List<string> lstStrings)
{
_nativeArray = Marshal.AllocHGlobal((lstStrings.Count + 1) * IntPtr.Size);
_nativeItems = new List<IntPtr>();
for (int i = 0; i < lstStrings.Count; i++)
{
IntPtr item = Marshal.StringToHGlobalUni(lstStrings[i]);
Marshal.WriteIntPtr((IntPtr)((int)_nativeArray + (i * IntPtr.Size)), item);
_nativeItems.Add(item);
}
Marshal.WriteIntPtr((IntPtr)((int)_nativeArray + (lstStrings.Count * IntPtr.Size)), IntPtr.Zero);
}

public IntPtr NativePointer { get { return _nativeArray; } }
public List<string> ManagedStringsAnsi { get { return _getManagedItems(false); } }
Expand Down

0 comments on commit 4c83dc8

Please sign in to comment.