-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginDefinition.cpp
545 lines (495 loc) · 18.7 KB
/
PluginDefinition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
//this file is part of notepad++
//Copyright (C) 2011 AustinYoung<pattazl@gmail.com>
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "PluginDefinition.h"
#include "menuCmdID.h"
//
// put the headers you need here
//
#include "stdafx.h"
#include <stdlib.h>
#include <time.h>
#include <shlwapi.h>
#include "DockingFeature/LNhistoryDlg.h"
LocationNavigateDlg _LNhistory;
#ifdef UNICODE
#define generic_itoa _itow
#else
#define generic_itoa itoa
#endif
FuncItem funcItem[nbFunc];
bool menuState[nbFunc];
HWND hToolbar;
int IconID[nbFunc];
//
// The data of Notepad++ that you can use in your plugin commands
//
NppData nppData;
toolbarIcons g_TBPrevious;
toolbarIcons g_TBNext;
toolbarIcons g_TBPreviousChg;
toolbarIcons g_TBNextChg;
TCHAR iniFilePath[MAX_PATH];
//bool SaveRecording = false;
//#define DOCKABLE_LNH_INDEX 4
//
// Initialize your plugin data here
// It will be called while plugin loading
void pluginInit( HANDLE hModule )
{
// Initialize dialog
_LNhistory.init( ( HINSTANCE )hModule, NULL );
//InitializeCriticalSection(&criCounter);
}
//
// Here you can do the clean up, save the parameters (if any) for the next session
//
void pluginCleanUp()
{
//DeleteCriticalSection(&criCounter);
TCHAR str[500] = {0};
wsprintf( str, TEXT( "%d" ), MaxOffset );
::WritePrivateProfileString( sectionName, strMaxOffset, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), MaxList );
::WritePrivateProfileString( sectionName, strMaxList, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), AutoClean ? 1 : 0 );
::WritePrivateProfileString( sectionName, strAutoClean, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), AlwaysRecord ? 1 : 0 );
::WritePrivateProfileString( sectionName, strAlwaysRecord, str,
iniFilePath );
wsprintf( str, TEXT( "%d" ), SaveRecord ? 1 : 0 );
::WritePrivateProfileString( sectionName, strSaveRecord, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), InCurr ? 1 : 0 );
::WritePrivateProfileString( sectionName, strInCurr, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), bAutoRecord ? 1 : 0 );
::WritePrivateProfileString( sectionName, strAutoRecord, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), NeedMark ? 1 : 0 );
::WritePrivateProfileString( sectionName, strNeedMark, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), ByBookMark );
::WritePrivateProfileString( sectionName, strByBookMark, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), MarkColor );
::WritePrivateProfileString( sectionName, strMarkColor, str, iniFilePath );
wsprintf( str, TEXT( "%d" ), SaveColor );
::WritePrivateProfileString( sectionName, strSaveColor, str, iniFilePath );
if ( SaveRecord )
{
//SaveRecording = true;
TCHAR iniContent[RecordConentMax] = {0};
// ???????,??? locationlist ??
for ( size_t i = 0; i < LocationSave.size(); i++ )
{
TCHAR tmp[300] = {0};
wsprintf( tmp, TEXT( "%d<%d>%s|" ), LocationSave[i].changed ? 1 : 0,
LocationSave[i].position, LocationSave[i].FilePath );
lstrcat( iniContent, tmp );
}
::WritePrivateProfileString( sectionName, strRecordContent, iniContent,
iniFilePath );
}
else
{
::WritePrivateProfileString( sectionName, strRecordContent, NULL,
iniFilePath );
}
LocationList.clear();
LocationSave.clear();
_LNhistory.destroy();
if ( g_TBPreviousChg.hToolbarBmp )
::DeleteObject( g_TBPreviousChg.hToolbarBmp );
if ( g_TBPrevious.hToolbarBmp )
::DeleteObject( g_TBPrevious.hToolbarBmp );
if ( g_TBNext.hToolbarBmp )
::DeleteObject( g_TBNext.hToolbarBmp );
if ( g_TBNextChg.hToolbarBmp )
::DeleteObject( g_TBNextChg.hToolbarBmp );
}
//
// Initialization of your plugin commands
// You should fill your plugins commands here
void commandMenuInit()
{
//
// Firstly we get the parameters from your plugin config file (if any)
//
// get path of plugin configuration
::SendMessage( nppData._nppHandle, NPPM_GETPLUGINSCONFIGDIR, MAX_PATH,
( LPARAM )iniFilePath );
// if config path doesn't exist, we create it
if ( PathFileExists( iniFilePath ) == FALSE )
::CreateDirectory( iniFilePath, NULL );
// make your plugin config file full file path name
PathAppend( iniFilePath, configFileName );
// get the parameter value from plugin config
MaxOffset = ::GetPrivateProfileInt( sectionName, strMaxOffset, 100,
iniFilePath );
MaxList = ::GetPrivateProfileInt( sectionName, strMaxList, 50,
iniFilePath ) ;
AutoClean = ( ::GetPrivateProfileInt( sectionName, strAutoClean, 0,
iniFilePath ) == 1 ) ;
AlwaysRecord = ( ::GetPrivateProfileInt( sectionName, strAlwaysRecord, 0,
iniFilePath ) == 1 ) ;
SaveRecord = ( ::GetPrivateProfileInt( sectionName, strSaveRecord, 0,
iniFilePath ) == 1 ) ;
InCurr = ( ::GetPrivateProfileInt( sectionName, strInCurr, 0,
iniFilePath ) == 1 ) ;
bAutoRecord = ( ::GetPrivateProfileInt( sectionName, strAutoRecord, 1,
iniFilePath ) == 1 ) ;
NeedMark = ( ::GetPrivateProfileInt( sectionName, strNeedMark, 1,
iniFilePath ) == 1 ) ;
ByBookMark = ( MarkType )::GetPrivateProfileInt( sectionName, strByBookMark,
0, iniFilePath );
MarkColor = ::GetPrivateProfileInt( sectionName, strMarkColor, DefaultColor,
iniFilePath );
SaveColor = ::GetPrivateProfileInt( sectionName, strSaveColor,
DefaultSaveColor, iniFilePath );
//--------------------------------------------//
//-- STEP 3. CUSTOMIZE YOUR PLUGIN COMMANDS --//
//--------------------------------------------//
// with function :
// setCommand(int index, // zero based number to indicate the order of command
// TCHAR *commandName, // the command name that you want to see in plugin menu
// PFUNCPLUGINCMD functionPointer, // the symbol of function (function pointer) associated with this command. The body should be defined below. See Step 4.
// ShortcutKey *shortcut, // optional. Define a shortcut to trigger this command
// bool check0nInit // optional. Make this menu item be checked visually
// );
#define VK_OEM_MINUS 0xBD
ShortcutKey *PreviousKey = new ShortcutKey;
PreviousKey->_isAlt = false;
PreviousKey->_isCtrl = true;
PreviousKey->_isShift = false;
PreviousKey->_key = VK_OEM_MINUS;
ShortcutKey *NextKey = new ShortcutKey;
NextKey->_isAlt = false;
NextKey->_isCtrl = true;
NextKey->_isShift = true;
NextKey->_key = VK_OEM_MINUS;
ShortcutKey *PreChgKey = new ShortcutKey;
PreChgKey->_isAlt = true;
PreChgKey->_isCtrl = true;
PreChgKey->_isShift = false;
PreChgKey->_key = 0x5A ; //VK_Z
ShortcutKey *NextChgKey = new ShortcutKey;
NextChgKey->_isAlt = true;
NextChgKey->_isCtrl = true;
NextChgKey->_isShift = false;
NextChgKey->_key = 0x59; //VK_Y
ShortcutKey *optionsKey = new ShortcutKey;
optionsKey->_isAlt = false;
optionsKey->_isCtrl = true;
optionsKey->_isShift = true;
optionsKey->_key = VK_OEM_PLUS;
/*
ShortcutKey *AutoKey = new ShortcutKey;
AutoKey->_isAlt = true;
AutoKey->_isCtrl = true;
AutoKey->_isShift = false;
AutoKey->_key = VK_F9;
ShortcutKey *ManualKey = new ShortcutKey;
ManualKey->_isAlt = false;
ManualKey->_isCtrl = false;
ManualKey->_isShift = false;
ManualKey->_key = VK_F9;
ShortcutKey *ClearRecordsKey = new ShortcutKey;
ClearRecordsKey->_isAlt = true;
ClearRecordsKey->_isCtrl = true;
ClearRecordsKey->_isShift = true;
ClearRecordsKey->_key = VK_F9;
ShortcutKey *incurrKey = new ShortcutKey;
incurrKey->_isAlt = true;
incurrKey->_isCtrl = false;
incurrKey->_isShift = false;
incurrKey->_key = VK_OEM_MINUS;
ShortcutKey *markKey = new ShortcutKey;
markKey->_isAlt = true;
markKey->_isCtrl = true;
markKey->_isShift = false;
markKey->_key = 0x4D; // VK_Y
*/
setCommand( menuPrevious, TEXT( "Previous Location" ), PreviousLocation,
PreviousKey, false );
setCommand( menuNext, TEXT( "Next Location" ), NextLocation, NextKey,
false );
setCommand( menuChgPrevious, TEXT( "Previous Changed" ),
PreviousChangedLocation, PreChgKey, false );
setCommand( menuChgNext, TEXT( "Next Changed" ), NextChangedLocation,
NextChgKey, false );
setCommand( menuOption, TEXT( "Show List and Option" ),
LocationNavigateHistoryDlg, optionsKey, false );
setCommand( menuSeparator0, TEXT( "-SEPARATOR-" ), NULL, NULL, false );
setCommand( menuAutoRecord, TEXT( "Auto Record" ), AutoRecord, NULL,
false );
setCommand( menuManualRecord, TEXT( "Manual Record" ), ManualRecord, NULL,
false );
setCommand( menuClearRecords, TEXT( "Clear All Records" ), ClearAllRecords,
NULL, false );
setCommand( menuInCurr, TEXT( "In Current File" ), NavigateInCurr, NULL,
false );
setCommand( menuNeedMark, TEXT( "Mark Changed Line" ), MarkChange, NULL,
false );
setCommand( menuSeparator1, TEXT( "-SEPARATOR-" ), NULL, NULL, false );
setCommand( menuCheckUpdate, TEXT( "Check for update" ), checkUpdate, NULL,
false );
setCommand( menuAbout, TEXT( "About Location Navigate" ), ShowAbout, NULL,
false );
}
//
// Here you can do the clean up (especially for the shortcut)
//
void commandMenuCleanUp()
{
// Don't forget to deallocate your shortcut here
delete funcItem[menuPrevious]._pShKey;
delete funcItem[menuNext]._pShKey;
delete funcItem[menuChgPrevious]._pShKey;
delete funcItem[menuChgNext]._pShKey;
delete funcItem[menuOption]._pShKey;
/*
delete funcItem[menuInCurr]._pShKey;
delete funcItem[menuNeedMark]._pShKey;
*/
}
//----------------------------------------------//
//-- STEP 4. DEFINE YOUR ASSOCIATED FUNCTIONS --//
//----------------------------------------------//
void PreviousLocation()
{
if ( LocationPos > 0 )
{
if ( InCurr )
{
int pos = LocationPos;
while ( --pos >= 0 )
{
if ( lstrcmp( LocationList[pos].FilePath, currFile ) == 0 )
{
// ???????????????,???????
if ( LocationList[pos].position !=
LocationList[LocationPos].position )
{
LocationPos = pos;
break;
}
}
}
}
else
LocationPos--;
SetPosByIndex();
_LNhistory.refreshDlg();
}
}
void NextLocation()
{
if ( LocationPos < (long)LocationList.size() - 1 )
{
// ????????????
if ( InCurr )
{
size_t pos = LocationPos;
while ( ++pos <= LocationList.size() - 1 )
{
if ( lstrcmp( LocationList[pos].FilePath, currFile ) == 0 )
{
// ???????????????,???????
if ( LocationList[pos].position !=
LocationList[LocationPos].position )
{
LocationPos = pos;
break;
};
}
}
}
else
LocationPos++;
SetPosByIndex();
_LNhistory.refreshDlg();
}
}
void PreviousChangedLocation()
{
int tmpPos = LocationPos;
int len = LocationList.size() - 1;
if ( tmpPos > len )
tmpPos = len;
while ( tmpPos > 0 )
{
// ???????
int pos = --tmpPos;
if ( LocationList[pos].changed )
{
// ??????????
bool samefile = true;
if ( InCurr )
{
samefile = ( lstrcmp( LocationList[pos].FilePath, currFile ) == 0 );
if ( samefile )
{
//if ( lstrcmp(LocationList[LocationPos].FilePath,currFile)==0 )
// ???????????????,???????
samefile = ( LocationList[pos].position !=
LocationList[LocationPos].position );
}
}
if ( samefile )
{
LocationPos = pos;
SetPosByIndex();
_LNhistory.refreshDlg();
break;
}
}
}
}
void NextChangedLocation()
{
int tmpPos = LocationPos;
int len = LocationList.size() - 1;
if ( tmpPos > len )
tmpPos = len;
while ( tmpPos < len )
{
// ???????
int pos = ++tmpPos;
if ( LocationList[pos].changed )
{
bool samefile = true;
if ( InCurr )
{
samefile = ( lstrcmp( LocationList[pos].FilePath, currFile ) == 0 );
if ( samefile )
{
// ???????????????,???????
samefile = ( LocationList[pos].position !=
LocationList[LocationPos].position );
}
}
if ( samefile )
{
LocationPos = pos;
SetPosByIndex();
_LNhistory.refreshDlg();
break;
}
}
}
}
void AutoRecord()
{
//
bAutoRecord = !bAutoRecord;
// ????
::CheckMenuItem( ::GetMenu( nppData._nppHandle ),
funcItem[menuAutoRecord]._cmdID,
MF_BYCOMMAND | ( bAutoRecord ? MF_CHECKED : MF_UNCHECKED ) );
::EnableMenuItem( ::GetMenu( nppData._nppHandle ),
funcItem[menuManualRecord]._cmdID,
MF_BYCOMMAND | ( bAutoRecord ? MF_GRAYED : MF_ENABLED ) );
}
void ManualRecord()
{
//
AddList( true );
}
void ClearAllRecords()
{
ClearLocationList();
_LNhistory.refreshDlg();
}
void NavigateInCurr()
{
InCurr = !InCurr;
// ????
::CheckMenuItem( ::GetMenu( nppData._nppHandle ),
funcItem[menuInCurr]._cmdID,
MF_BYCOMMAND | ( InCurr ? MF_CHECKED : MF_UNCHECKED ) );
// ??????
_LNhistory.refreshDlg();
if ( _LNhistory.isCreated() )
{
::SendMessage( _LNhistory._hInCurr, BM_SETCHECK,
( LPARAM )( InCurr ? 1 : 0 ), 0 );
}
}
void MarkChange()
{
NeedMark = !NeedMark;
// ????
::CheckMenuItem( ::GetMenu( nppData._nppHandle ),
funcItem[menuNeedMark]._cmdID,
MF_BYCOMMAND | ( NeedMark ? MF_CHECKED : MF_UNCHECKED ) );
// ??????
if ( _LNhistory.isCreated() )
{
::SendMessage( _LNhistory._hMark, BM_SETCHECK,
( LPARAM )( NeedMark ? 1 : 0 ), 0 );
}
}
//
// This function help you to initialize your plugin commands
//
bool setCommand( size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc,
ShortcutKey *sk, bool check0nInit )
{
if ( index >= nbFunc )
return false;
if ( !pFunc )
return false;
lstrcpy( funcItem[index]._itemName, cmdName );
funcItem[index]._pFunc = pFunc;
funcItem[index]._init2Check = check0nInit;
funcItem[index]._pShKey = sk;
return true;
}
void LocationNavigateHistoryDlg()
{
_LNhistory.setParent( nppData._nppHandle );
tTbData data = {0};
if ( !_LNhistory.isCreated() )
{
_LNhistory.create( &data );
// define the default docking behaviour
data.uMask = DWS_DF_CONT_RIGHT | DWS_ICONTAB;
data.pszModuleName = _LNhistory.getPluginFileName();
// the dlgDlg should be the index of funcItem where the current function pointer is
data.dlgID = menuOption;
data.hIconTab = ( HICON )::LoadImage( _LNhistory.getHinst(),
MAKEINTRESOURCE( IDI_ICON1 ), IMAGE_ICON, 0, 0,
LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT );
::SendMessage( nppData._nppHandle, NPPM_DMMREGASDCKDLG, 0,
( LPARAM )&data );
}
UINT state = ::GetMenuState( ::GetMenu( nppData._nppHandle ),
funcItem[menuOption]._cmdID, MF_BYCOMMAND );
if ( state & MF_CHECKED )
_LNhistory.display( false );
else
_LNhistory.display();
::SendMessage( nppData._nppHandle, NPPM_SETMENUITEMCHECK,
funcItem[menuOption]._cmdID, !( state & MF_CHECKED ) );
}
void ShowAbout()
{
::MessageBox( nppData._nppHandle,
TEXT( " You can use Ctrl+ - jump to previous cursor position \n You can use Ctrl+Shift+ - jump to next cursor position \n You can use Ctrl+Alt+ Z jump to previous changed position \n You can use Ctrl+Alt+ Y jump to next changed position \n 'Auto clear when close'- Will remove the file's record when file closed.\n 'Always record'- Will always record the position even after you jumped.\n 'Save record when App exit'- Record data when application exit and it will be loaded in next run \n 'In Curr'- If checked, navigate only in current file\n 'Mark'- If checked, modified line will be marked by bookmark or color\n 'Mark Color/Save Color'- Available if not select mark with bookmark, you could mark with different symbol. \n\n Version: 0.4.7.7 Author: Austin Young<pattazl@gmail.com>" ),
TEXT( "About Location Navigate" ), MB_OK );
}
void checkUpdate()
{
ShellExecute( NULL, TEXT( "open" ),
TEXT( "http://sourceforge.net/projects/locationnav/files" ), NULL, NULL,
SW_SHOW );
}