77using System . Drawing . Imaging ;
88using System . Runtime . InteropServices ;
99using System . Text . RegularExpressions ;
10+ using Kbg . NppPluginNET ;
1011
1112namespace Kbg . NppPluginNET
1213{
@@ -37,7 +38,7 @@ static internal void SetToolBarIcon()
3738
3839namespace Kbg . Demo . Namespace
3940{
40- partial class PluginBase
41+ class Main
4142 {
4243 #region " Fields "
4344 internal const string PluginName = "NppManagedPluginDemo" ;
@@ -59,26 +60,26 @@ static internal void CommandMenuInit()
5960 // Initialization of your plugin commands
6061 // You should fill your plugins commands here
6162
62- //
63- // Firstly we get the parameters from your plugin config file (if any)
64- //
63+ //
64+ // Firstly we get the parameters from your plugin config file (if any)
65+ //
6566
66- // get path of plugin configuration
67+ // get path of plugin configuration
6768 StringBuilder sbIniFilePath = new StringBuilder ( Win32 . MAX_PATH ) ;
68- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_GETPLUGINSCONFIGDIR , Win32 . MAX_PATH , sbIniFilePath ) ;
69+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_GETPLUGINSCONFIGDIR , Win32 . MAX_PATH , sbIniFilePath ) ;
6970 iniFilePath = sbIniFilePath . ToString ( ) ;
7071
71- // if config path doesn't exist, we create it
72+ // if config path doesn't exist, we create it
7273 if ( ! Directory . Exists ( iniFilePath ) )
73- {
74+ {
7475 Directory . CreateDirectory ( iniFilePath ) ;
75- }
76+ }
7677
77- // make your plugin config file full file path name
78+ // make your plugin config file full file path name
7879 iniFilePath = Path . Combine ( iniFilePath , PluginName + ".ini" ) ;
7980
80- // get the parameter value from plugin config
81- doCloseTag = ( Win32 . GetPrivateProfileInt ( sectionName , keyName , 0 , iniFilePath ) != 0 ) ;
81+ // get the parameter value from plugin config
82+ doCloseTag = ( Win32 . GetPrivateProfileInt ( sectionName , keyName , 0 , iniFilePath ) != 0 ) ;
8283
8384 // with function :
8485 // SetCommand(int index, // zero based number to indicate the order of command
@@ -87,32 +88,32 @@ static internal void CommandMenuInit()
8788 // ShortcutKey *shortcut, // optional. Define a shortcut to trigger this command
8889 // bool check0nInit // optional. Make this menu item be checked visually
8990 // );
90- SetCommand ( 0 , "Hello Notepad++" , hello ) ;
91- SetCommand ( 1 , "Hello (with FX)" , helloFX ) ;
92- SetCommand ( 2 , "What is Notepad++?" , WhatIsNpp ) ;
91+ PluginBase . SetCommand ( 0 , "Hello Notepad++" , hello ) ;
92+ PluginBase . SetCommand ( 1 , "Hello (with FX)" , helloFX ) ;
93+ PluginBase . SetCommand ( 2 , "What is Notepad++?" , WhatIsNpp ) ;
9394
9495 // Here you insert a separator
95- SetCommand ( 3 , "---" , null ) ;
96+ PluginBase . SetCommand ( 3 , "---" , null ) ;
9697
9798 // Shortcut :
9899 // Following makes the command bind to the shortcut Alt-F
99- SetCommand ( 4 , "Current Full Path" , insertCurrentFullPath , new ShortcutKey ( false , true , false , Keys . F ) ) ;
100- SetCommand ( 5 , "Current File Name" , insertCurrentFileName ) ;
101- SetCommand ( 6 , "Current Directory" , insertCurrentDirectory ) ;
102- SetCommand ( 7 , "Date && Time - short format" , insertShortDateTime ) ;
103- SetCommand ( 8 , "Date && Time - long format" , insertLongDateTime ) ;
100+ PluginBase . SetCommand ( 4 , "Current Full Path" , insertCurrentFullPath , new ShortcutKey ( false , true , false , Keys . F ) ) ;
101+ PluginBase . SetCommand ( 5 , "Current File Name" , insertCurrentFileName ) ;
102+ PluginBase . SetCommand ( 6 , "Current Directory" , insertCurrentDirectory ) ;
103+ PluginBase . SetCommand ( 7 , "Date && Time - short format" , insertShortDateTime ) ;
104+ PluginBase . SetCommand ( 8 , "Date && Time - long format" , insertLongDateTime ) ;
104105
105- SetCommand ( 9 , "Close HTML/XML tag automatically" , checkInsertHtmlCloseTag , new ShortcutKey ( false , true , false , Keys . Q ) , doCloseTag ) ;
106+ PluginBase . SetCommand ( 9 , "Close HTML/XML tag automatically" , checkInsertHtmlCloseTag , new ShortcutKey ( false , true , false , Keys . Q ) , doCloseTag ) ;
106107
107- SetCommand ( 10 , "---" , null ) ;
108+ PluginBase . SetCommand ( 10 , "---" , null ) ;
108109
109- SetCommand ( 11 , "Get File Names Demo" , getFileNamesDemo ) ;
110- SetCommand ( 12 , "Get Session File Names Demo" , getSessionFileNamesDemo ) ;
111- SetCommand ( 13 , "Save Current Session Demo" , saveCurrentSessionDemo ) ;
110+ PluginBase . SetCommand ( 11 , "Get File Names Demo" , getFileNamesDemo ) ;
111+ PluginBase . SetCommand ( 12 , "Get Session File Names Demo" , getSessionFileNamesDemo ) ;
112+ PluginBase . SetCommand ( 13 , "Save Current Session Demo" , saveCurrentSessionDemo ) ;
112113
113- SetCommand ( 14 , "---" , null ) ;
114+ PluginBase . SetCommand ( 14 , "---" , null ) ;
114115
115- SetCommand ( 15 , "Dockable Dialog Demo" , DockableDlgDemo ) ; idFrmGotToLine = 15 ;
116+ PluginBase . SetCommand ( 15 , "Dockable Dialog Demo" , DockableDlgDemo ) ; idFrmGotToLine = 15 ;
116117 }
117118
118119 static internal void SetToolBarIcon ( )
@@ -121,24 +122,24 @@ static internal void SetToolBarIcon()
121122 tbIcons . hToolbarBmp = tbBmp . GetHbitmap ( ) ;
122123 IntPtr pTbIcons = Marshal . AllocHGlobal ( Marshal . SizeOf ( tbIcons ) ) ;
123124 Marshal . StructureToPtr ( tbIcons , pTbIcons , false ) ;
124- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_ADDTOOLBARICON , _funcItems . Items [ idFrmGotToLine ] . _cmdID , pTbIcons ) ;
125+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_ADDTOOLBARICON , PluginBase . _funcItems . Items [ idFrmGotToLine ] . _cmdID , pTbIcons ) ;
125126 Marshal . FreeHGlobal ( pTbIcons ) ;
126127 }
127128
128129 static internal void PluginCleanUp ( )
129130 {
130- Win32 . WritePrivateProfileString ( sectionName , keyName , doCloseTag ? "1" : "0" , iniFilePath ) ;
131+ Win32 . WritePrivateProfileString ( sectionName , keyName , doCloseTag ? "1" : "0" , iniFilePath ) ;
131132 }
132133 #endregion
133134
134135 #region " Menu functions "
135136 static void hello ( )
136137 {
137138 // Open a new document
138- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_MENUCOMMAND , 0 , NppMenuCmd . IDM_FILE_NEW ) ;
139+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_MENUCOMMAND , 0 , NppMenuCmd . IDM_FILE_NEW ) ;
139140 // Say hello now :
140141 // Scintilla control has no Unicode mode, so we use ANSI here (marshalled as ANSI by default)
141- Win32 . SendMessage ( GetCurrentScintilla ( ) , SciMsg . SCI_SETTEXT , 0 , "Hello, Notepad++... from .NET!" ) ;
142+ Win32 . SendMessage ( PluginBase . GetCurrentScintilla ( ) , SciMsg . SCI_SETTEXT , 0 , "Hello, Notepad++... from .NET!" ) ;
142143 }
143144 static void helloFX ( )
144145 {
@@ -147,22 +148,22 @@ static void helloFX()
147148 }
148149 static void callbackHelloFX ( )
149150 {
150- IntPtr curScintilla = GetCurrentScintilla ( ) ;
151+ IntPtr curScintilla = PluginBase . GetCurrentScintilla ( ) ;
151152 int currentZoomLevel = ( int ) Win32 . SendMessage ( curScintilla , SciMsg . SCI_GETZOOM , 0 , 0 ) ;
152153 int i = currentZoomLevel ;
153154 for ( int j = 0 ; j < 4 ; j ++ )
154- {
155- for ( ; i >= - 10 ; i -- )
156- {
157- Win32 . SendMessage ( curScintilla , SciMsg . SCI_SETZOOM , i , 0 ) ;
155+ {
156+ for ( ; i >= - 10 ; i -- )
157+ {
158+ Win32 . SendMessage ( curScintilla , SciMsg . SCI_SETZOOM , i , 0 ) ;
158159 Thread . Sleep ( 30 ) ;
159- }
160+ }
160161 Thread . Sleep ( 100 ) ;
161- for ( ; i <= 20 ; i ++ )
162- {
163- Thread . Sleep ( 30 ) ;
164- Win32 . SendMessage ( curScintilla , SciMsg . SCI_SETZOOM , i , 0 ) ;
165- }
162+ for ( ; i <= 20 ; i ++ )
163+ {
164+ Thread . Sleep ( 30 ) ;
165+ Win32 . SendMessage ( curScintilla , SciMsg . SCI_SETZOOM , i , 0 ) ;
166+ }
166167 Thread . Sleep ( 100 ) ;
167168 }
168169 for ( ; i >= currentZoomLevel ; i -- )
@@ -175,7 +176,7 @@ static void WhatIsNpp()
175176 {
176177 string text2display = "Notepad++ is a free (as in \" free speech\" and also as in \" free beer\" ) " +
177178 "source code editor and Notepad replacement that supports several languages.\n " +
178- "Running in the MS Windows environment, its use is governed by GPL License.\n \n " +
179+ "Running in the MS Windows environment, its use is governed by GPL License.\n \n " +
179180 "Based on a powerful editing component Scintilla, Notepad++ is written in C++ and " +
180181 "uses pure Win32 API and STL which ensures a higher execution speed and smaller program size.\n " +
181182 "By optimizing as many routines as possible without losing user friendliness, Notepad++ is trying " +
@@ -187,10 +188,10 @@ static void callbackWhatIsNpp(object data)
187188 {
188189 string text2display = ( string ) data ;
189190 // Open a new document
190- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_MENUCOMMAND , 0 , NppMenuCmd . IDM_FILE_NEW ) ;
191+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_MENUCOMMAND , 0 , NppMenuCmd . IDM_FILE_NEW ) ;
191192
192193 // Get the current scintilla
193- IntPtr curScintilla = GetCurrentScintilla ( ) ;
194+ IntPtr curScintilla = PluginBase . GetCurrentScintilla ( ) ;
194195
195196 Random srand = new Random ( DateTime . Now . Millisecond ) ;
196197 int rangeMin = 0 ;
@@ -221,16 +222,16 @@ static void insertCurrentDirectory()
221222 }
222223 static void insertCurrentPath ( NppMsg which )
223224 {
224- NppMsg msg = NppMsg . NPPM_GETFULLCURRENTPATH ;
225- if ( which == NppMsg . FILE_NAME )
226- msg = NppMsg . NPPM_GETFILENAME ;
227- else if ( which == NppMsg . CURRENT_DIRECTORY )
225+ NppMsg msg = NppMsg . NPPM_GETFULLCURRENTPATH ;
226+ if ( which == NppMsg . FILE_NAME )
227+ msg = NppMsg . NPPM_GETFILENAME ;
228+ else if ( which == NppMsg . CURRENT_DIRECTORY )
228229 msg = NppMsg . NPPM_GETCURRENTDIRECTORY ;
229230
230- StringBuilder path = new StringBuilder ( Win32 . MAX_PATH ) ;
231- Win32 . SendMessage ( nppData . _nppHandle , msg , 0 , path ) ;
231+ StringBuilder path = new StringBuilder ( Win32 . MAX_PATH ) ;
232+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , msg , 0 , path ) ;
232233
233- Win32 . SendMessage ( GetCurrentScintilla ( ) , SciMsg . SCI_REPLACESEL , 0 , path ) ;
234+ Win32 . SendMessage ( PluginBase . GetCurrentScintilla ( ) , SciMsg . SCI_REPLACESEL , 0 , path ) ;
234235 }
235236
236237 static void insertShortDateTime ( )
@@ -246,27 +247,27 @@ static void insertDateTime(bool longFormat)
246247 string dateTime = string . Format ( "{0} {1}" ,
247248 DateTime . Now . ToShortTimeString ( ) ,
248249 longFormat ? DateTime . Now . ToLongDateString ( ) : DateTime . Now . ToShortDateString ( ) ) ;
249- Win32 . SendMessage ( GetCurrentScintilla ( ) , SciMsg . SCI_REPLACESEL , 0 , dateTime ) ;
250+ Win32 . SendMessage ( PluginBase . GetCurrentScintilla ( ) , SciMsg . SCI_REPLACESEL , 0 , dateTime ) ;
250251 }
251252
252253 static void checkInsertHtmlCloseTag ( )
253254 {
254255 doCloseTag = ! doCloseTag ;
255256
256- int i = Win32 . CheckMenuItem ( Win32 . GetMenu ( nppData . _nppHandle ) , _funcItems . Items [ 9 ] . _cmdID ,
257+ int i = Win32 . CheckMenuItem ( Win32 . GetMenu ( PluginBase . nppData . _nppHandle ) , PluginBase . _funcItems . Items [ 9 ] . _cmdID ,
257258 Win32 . MF_BYCOMMAND | ( doCloseTag ? Win32 . MF_CHECKED : Win32 . MF_UNCHECKED ) ) ;
258259 }
259260 static internal void doInsertHtmlCloseTag ( char newChar )
260261 {
261262 LangType docType = LangType . L_TEXT ;
262- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_GETCURRENTLANGTYPE , 0 , ref docType ) ;
263+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_GETCURRENTLANGTYPE , 0 , ref docType ) ;
263264 bool isDocTypeHTML = ( docType == LangType . L_HTML || docType == LangType . L_XML || docType == LangType . L_PHP ) ;
264265 if ( doCloseTag && isDocTypeHTML )
265266 {
266267 if ( newChar == '>' )
267268 {
268269 int bufCapacity = 512 ;
269- IntPtr hCurrentEditView = GetCurrentScintilla ( ) ;
270+ IntPtr hCurrentEditView = PluginBase . GetCurrentScintilla ( ) ;
270271 int currentPos = ( int ) Win32 . SendMessage ( hCurrentEditView , SciMsg . SCI_GETCURRENTPOS , 0 , 0 ) ;
271272 int beginPos = currentPos - ( bufCapacity - 1 ) ;
272273 int startPos = ( beginPos > 0 ) ? beginPos : 0 ;
@@ -316,37 +317,37 @@ static internal void doInsertHtmlCloseTag(char newChar)
316317
317318 static void getFileNamesDemo ( )
318319 {
319- int nbFile = ( int ) Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_GETNBOPENFILES , 0 , 0 ) ;
320+ int nbFile = ( int ) Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_GETNBOPENFILES , 0 , 0 ) ;
320321 MessageBox . Show ( nbFile . ToString ( ) , "Number of opened files:" ) ;
321322
322323 using ( ClikeStringArray cStrArray = new ClikeStringArray ( nbFile , Win32 . MAX_PATH ) )
323324 {
324- if ( Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_GETOPENFILENAMES , cStrArray . NativePointer , nbFile ) != IntPtr . Zero )
325+ if ( Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_GETOPENFILENAMES , cStrArray . NativePointer , nbFile ) != IntPtr . Zero )
325326 foreach ( string file in cStrArray . ManagedStringsUnicode ) MessageBox . Show ( file ) ;
326327 }
327328 }
328329 static void getSessionFileNamesDemo ( )
329330 {
330- int nbFile = ( int ) Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_GETNBSESSIONFILES , 0 , sessionFilePath ) ;
331+ int nbFile = ( int ) Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_GETNBSESSIONFILES , 0 , sessionFilePath ) ;
331332
332- if ( nbFile < 1 )
333- {
334- MessageBox . Show ( "Please modify \" sessionFilePath\" in \" Demo.cs\" in order to point to a valid session file" , "Error" ) ;
335- return ;
336- }
333+ if ( nbFile < 1 )
334+ {
335+ MessageBox . Show ( "Please modify \" sessionFilePath\" in \" Demo.cs\" in order to point to a valid session file" , "Error" ) ;
336+ return ;
337+ }
337338 MessageBox . Show ( nbFile . ToString ( ) , "Number of session files:" ) ;
338339
339340 using ( ClikeStringArray cStrArray = new ClikeStringArray ( nbFile , Win32 . MAX_PATH ) )
340341 {
341- if ( Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_GETSESSIONFILES , cStrArray . NativePointer , sessionFilePath ) != IntPtr . Zero )
342+ if ( Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_GETSESSIONFILES , cStrArray . NativePointer , sessionFilePath ) != IntPtr . Zero )
342343 foreach ( string file in cStrArray . ManagedStringsUnicode ) MessageBox . Show ( file ) ;
343344 }
344345 }
345346 static void saveCurrentSessionDemo ( )
346347 {
347- string sessionPath = Marshal . PtrToStringUni ( Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_SAVECURRENTSESSION , 0 , sessionFilePath ) ) ;
348- if ( ! string . IsNullOrEmpty ( sessionPath ) )
349- MessageBox . Show ( sessionPath , "Saved Session File :" , MessageBoxButtons . OK ) ;
348+ string sessionPath = Marshal . PtrToStringUni ( Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_SAVECURRENTSESSION , 0 , sessionFilePath ) ) ;
349+ if ( ! string . IsNullOrEmpty ( sessionPath ) )
350+ MessageBox . Show ( sessionPath , "Saved Session File :" , MessageBoxButtons . OK ) ;
350351 }
351352
352353 static void DockableDlgDemo ( )
@@ -361,15 +362,15 @@ static void DockableDlgDemo()
361362
362363 using ( Bitmap newBmp = new Bitmap ( 16 , 16 ) )
363364 {
364- Graphics g = Graphics . FromImage ( newBmp ) ;
365- ColorMap [ ] colorMap = new ColorMap [ 1 ] ;
366- colorMap [ 0 ] = new ColorMap ( ) ;
367- colorMap [ 0 ] . OldColor = Color . Fuchsia ;
368- colorMap [ 0 ] . NewColor = Color . FromKnownColor ( KnownColor . ButtonFace ) ;
369- ImageAttributes attr = new ImageAttributes ( ) ;
370- attr . SetRemapTable ( colorMap ) ;
371- g . DrawImage ( tbBmp_tbTab , new Rectangle ( 0 , 0 , 16 , 16 ) , 0 , 0 , 16 , 16 , GraphicsUnit . Pixel , attr ) ;
372- tbIcon = Icon . FromHandle ( newBmp . GetHicon ( ) ) ;
365+ Graphics g = Graphics . FromImage ( newBmp ) ;
366+ ColorMap [ ] colorMap = new ColorMap [ 1 ] ;
367+ colorMap [ 0 ] = new ColorMap ( ) ;
368+ colorMap [ 0 ] . OldColor = Color . Fuchsia ;
369+ colorMap [ 0 ] . NewColor = Color . FromKnownColor ( KnownColor . ButtonFace ) ;
370+ ImageAttributes attr = new ImageAttributes ( ) ;
371+ attr . SetRemapTable ( colorMap ) ;
372+ g . DrawImage ( tbBmp_tbTab , new Rectangle ( 0 , 0 , 16 , 16 ) , 0 , 0 , 16 , 16 , GraphicsUnit . Pixel , attr ) ;
373+ tbIcon = Icon . FromHandle ( newBmp . GetHicon ( ) ) ;
373374 }
374375
375376 NppTbData _nppTbData = new NppTbData ( ) ;
@@ -385,22 +386,22 @@ static void DockableDlgDemo()
385386 IntPtr _ptrNppTbData = Marshal . AllocHGlobal ( Marshal . SizeOf ( _nppTbData ) ) ;
386387 Marshal . StructureToPtr ( _nppTbData , _ptrNppTbData , false ) ;
387388
388- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_DMMREGASDCKDLG , 0 , _ptrNppTbData ) ;
389+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_DMMREGASDCKDLG , 0 , _ptrNppTbData ) ;
389390 // Following message will toogle both menu item state and toolbar button
390- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_SETMENUITEMCHECK , _funcItems . Items [ idFrmGotToLine ] . _cmdID , 1 ) ;
391+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_SETMENUITEMCHECK , PluginBase . _funcItems . Items [ idFrmGotToLine ] . _cmdID , 1 ) ;
391392 }
392393 else
393394 {
394- if ( ! frmGoToLine . Visible )
395- {
396- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_DMMSHOW , 0 , frmGoToLine . Handle ) ;
397- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_SETMENUITEMCHECK , _funcItems . Items [ idFrmGotToLine ] . _cmdID , 1 ) ;
398- }
399- else
400- {
401- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_DMMHIDE , 0 , frmGoToLine . Handle ) ;
402- Win32 . SendMessage ( nppData . _nppHandle , NppMsg . NPPM_SETMENUITEMCHECK , _funcItems . Items [ idFrmGotToLine ] . _cmdID , 0 ) ;
403- }
395+ if ( ! frmGoToLine . Visible )
396+ {
397+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_DMMSHOW , 0 , frmGoToLine . Handle ) ;
398+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_SETMENUITEMCHECK , PluginBase . _funcItems . Items [ idFrmGotToLine ] . _cmdID , 1 ) ;
399+ }
400+ else
401+ {
402+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_DMMHIDE , 0 , frmGoToLine . Handle ) ;
403+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , NppMsg . NPPM_SETMENUITEMCHECK , PluginBase . _funcItems . Items [ idFrmGotToLine ] . _cmdID , 0 ) ;
404+ }
404405 }
405406 frmGoToLine . textBox1 . Focus ( ) ;
406407 }
0 commit comments