-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPluginDefinition.cpp
806 lines (711 loc) · 24.5 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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
//this file is part of notepad++
//Copyright (C)2003 Don HO <[email protected]>
//
//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 "DockingFeature/SettingsDlg.h"
#include "PluginDefinition.h"
#include "resource.h"
#include "DockingFeature/GitPanelDlg.h"
#include "menuCmdID.h"
#include "stdafx.h"
#include <shlwapi.h>
#include <string>
#include <vector>
const TCHAR configFileName[] = TEXT( "GitSCM.ini" );
const TCHAR sectionName[] = TEXT( "Git" );
const TCHAR iniKeyTortoise[] = TEXT( "Tortoise" );
const TCHAR iniKeyGitPath[] = TEXT( "GitPath" );
const TCHAR iniKeyGitPrompt[] = TEXT( "GitPrompt" );
const TCHAR iniKeyUseNppColors[] = TEXT( "UseNppColors" );
const TCHAR iniKeyRaisePanel[] = TEXT( "RaisePanelorToggle" );
const TCHAR iniKeyRefScnFocus[] = TEXT( "RefreshScnFocus" );
const TCHAR iniKeyDiffWordDiff[] = TEXT( "DiffWordDiff" );
const TCHAR iniKeyDebug[] = TEXT( "Debug" );
const TCHAR iniKeyLVDelay[] = TEXT( "LVDelay" );
const TCHAR iniKeyGitGuiBlame[] = TEXT( "GitGuiBlame" );
DemoDlg _gitPanel;
toolbarIcons g_TBGit;
//
// The plugin data that Notepad++ needs
//
FuncItem funcItem[nbFunc];
//
// The data of Notepad++ that you can use in your plugin commands
//
NppData nppData;
HINSTANCE g_hInst;
TCHAR iniFilePath[MAX_PATH];
TCHAR g_GitPath[MAX_PATH];
TCHAR g_GitPrompt[MAX_PATH];
bool g_useTortoise = false;
bool g_NppReady = false;
bool g_useNppColors = false;
bool g_RaisePanel = false;
bool g_RefScnFocus = false;
bool g_DiffWordDiff = false;
bool g_gitGuiBlame = false;
// g_Debug and g_LVDelay must be set manually in config file ($NPP_DIR\plugins\config\GitSCM.ini)
// ON => Debug=1
// OFF => Debug=0
// LVDelay=<# milliseconds>
// It is read at startup, it is NOT written back to the config file!
// When set ON, use DebugView (DbgView.exe) https://www.sysinternals.com
bool g_Debug = false;
int g_LVDelay = LSV1_REFRESH_DELAY;
std::wstring g_tortoiseLoc;
//
// Initialize your plugin data here
// It will be called while plugin loading
void pluginInit( HANDLE hModule )
{
// Initialize dockable dialog
_gitPanel.init( ( HINSTANCE )hModule, NULL );
}
//
// Here you can do the clean up, save the parameters (if any) for the next session
//
void pluginCleanUp()
{
::WritePrivateProfileString( sectionName, iniKeyTortoise,
g_useTortoise ? TEXT( "1" ) : TEXT( "0" ), iniFilePath );
::WritePrivateProfileString( sectionName, iniKeyGitPath,
g_GitPath, iniFilePath);
::WritePrivateProfileString( sectionName, iniKeyGitPrompt,
g_GitPrompt, iniFilePath);
::WritePrivateProfileString( sectionName, iniKeyUseNppColors,
g_useNppColors ? TEXT( "1" ) : TEXT( "0" ), iniFilePath );
::WritePrivateProfileString( sectionName, iniKeyRaisePanel,
g_RaisePanel ? TEXT( "1" ) : TEXT( "0" ), iniFilePath );
::WritePrivateProfileString( sectionName, iniKeyRefScnFocus,
g_RefScnFocus ? TEXT( "1" ) : TEXT( "0" ), iniFilePath );
::WritePrivateProfileString( sectionName, iniKeyDiffWordDiff,
g_DiffWordDiff ? TEXT( "1" ) : TEXT( "0" ), iniFilePath );
::WritePrivateProfileString( sectionName, iniKeyGitGuiBlame,
g_gitGuiBlame ? TEXT( "1" ) : TEXT( "0" ), iniFilePath);
if (g_TBGit.hToolbarBmp) {
::DeleteObject(g_TBGit.hToolbarBmp);
g_TBGit.hToolbarBmp = nullptr;
}
if (g_TBGit.hToolbarIcon) {
::DestroyIcon(g_TBGit.hToolbarIcon);
g_TBGit.hToolbarIcon = nullptr;
}
}
//
// 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
g_useTortoise = ::GetPrivateProfileInt( sectionName, iniKeyTortoise,
0, iniFilePath );
::GetPrivateProfileString( sectionName, iniKeyGitPath, TEXT(""),
g_GitPath, MAX_PATH, iniFilePath );
::GetPrivateProfileString( sectionName, iniKeyGitPrompt, TEXT("powershell.exe"),
g_GitPrompt, MAX_PATH, iniFilePath );
g_useNppColors = ::GetPrivateProfileInt( sectionName, iniKeyUseNppColors,
0, iniFilePath );
g_RaisePanel = ::GetPrivateProfileInt( sectionName, iniKeyRaisePanel,
0, iniFilePath );
g_RefScnFocus = ::GetPrivateProfileInt( sectionName, iniKeyRefScnFocus,
0, iniFilePath );
g_DiffWordDiff = ::GetPrivateProfileInt( sectionName, iniKeyDiffWordDiff,
0, iniFilePath );
g_gitGuiBlame = ::GetPrivateProfileInt(sectionName, iniKeyGitGuiBlame,
0, iniFilePath);
g_Debug = ::GetPrivateProfileInt( sectionName, iniKeyDebug,
0, iniFilePath );
g_LVDelay = ::GetPrivateProfileInt( sectionName, iniKeyLVDelay,
0, iniFilePath );
if ( g_useTortoise )
{
if ( ! getTortoiseLocation( g_tortoiseLoc ) )
g_useTortoise = false;
}
//--------------------------------------------//
//-- 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
// );
setCommand( 0, TEXT( "Git &GUI" ), gitGui, NULL, false );
setCommand( 1, TEXT( "GiT&k" ), giTk, NULL, false );
setCommand( 2, TEXT( "Git Pro&mpt" ), gitPrompt, NULL, false );
setCommand( 3, TEXT( "-SEPARATOR-" ), NULL, NULL, false );
setCommand( DOCKABLE_INDEX, TEXT( "Git Docking Panel" ), DockableDlg, NULL, _gitPanel.isVisible() ? true : false );
setCommand( 5, TEXT( "-SEPARATOR-" ), NULL, NULL, false );
setCommand( 6, TEXT( "&Add File" ), addFile, NULL, false );
setCommand( 7, TEXT( "&Unstage File" ), unstageFile, NULL, false );
setCommand( 8, TEXT( "&Restore File" ), restoreFile, NULL, false );
setCommand( 9, TEXT( "&Diff File" ), diffFile, NULL, false );
setCommand( 10, TEXT( "&Log File" ), logFile, NULL, false );
setCommand( 11, TEXT( "&Blame File" ), blameFile, NULL, false );
setCommand( 12, TEXT( "-SEPARATOR-" ), NULL, NULL, false );
setCommand( 13, TEXT( "&Pull" ), pullFile, NULL, false );
setCommand( 14, TEXT( "&Status" ), statusAll, NULL, false );
setCommand( 15, TEXT( "Bra&nch/Checkout" ), branchFile, NULL, false );
setCommand( 16, TEXT( "&Commit" ), commitAll, NULL, false );
setCommand( 17, TEXT( "Pus&h" ), pushFile, NULL, false );
setCommand( 18, TEXT( "-SEPARATOR-" ), NULL, NULL, false );
setCommand( TORTOISE_INDEX, TEXT( "Use &TortoiseGit" ), doTortoise, NULL, g_useTortoise ? true : false );
setCommand( 20, TEXT( "S&ettings" ), doSettings, NULL, false );
}
//
// Here you can do the clean up (especially for the shortcut)
//
void commandMenuCleanUp()
{
// Don't forget to deallocate your shortcut here
}
//
// 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;
}
//----------------------------------------------//
//-- STEP 4. DEFINE YOUR ASSOCIATED FUNCTIONS --//
//----------------------------------------------//
///
/// Gets the path to the current file.
///
/// @return Current file path.
///
HWND getCurScintilla()
{
int which = -1;
::SendMessage( nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0,
( LPARAM )&which );
return ( which == 0 ) ? nppData._scintillaMainHandle :
nppData._scintillaSecondHandle;
}
std::wstring getCurrentFile()
{
TCHAR path[MAX_PATH];
::SendMessage( nppData._nppHandle, NPPM_GETFULLCURRENTPATH, MAX_PATH,
( LPARAM )path );
return std::wstring( path );
}
///
/// Gets the path to the current file's directory.
///
/// @return Current file's directory path.
///
std::wstring getCurrentFileDirectory()
{
TCHAR path[MAX_PATH];
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTDIRECTORY, MAX_PATH,
(LPARAM)path);
return std::wstring( path );
}
std::wstring GetLastErrorString(DWORD errorCode)
{
std::wstring errorMsg(_T(""));
// Get the error message, if any.
// If both error codes (passed error n GetLastError) are 0, then return empty
if (errorCode == 0)
errorCode = GetLastError();
if (errorCode == 0)
return errorMsg; //No error message has been recorded
LPWSTR messageBuffer = nullptr;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, nullptr);
errorMsg += messageBuffer;
//Free the buffer.
LocalFree(messageBuffer);
return errorMsg;
}
///
/// Gets the path to the TortioseGit executable from the registry.
///
/// @param loc [out] Location of Tortoise executable
///
/// @return Whether or not the path was successfully retrieved.
/// If false, Tortoise is most likely not installed.
bool getTortoiseLocation( std::wstring &loc )
{
HKEY hKey;
if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "Software\\TortoiseGit" ), 0,
KEY_READ | KEY_WOW64_64KEY, &hKey ) != ERROR_SUCCESS )
return false;
TCHAR procPath[MAX_PATH];
DWORD length = MAX_PATH;
// Modified Douglas Phillips <[email protected]> 2008-12-29 to
// support 32-bit and Non-Vista operating Systems.
if ( RegQueryValueEx(
hKey,
TEXT( "ProcPath" ),
NULL,
NULL,
( LPBYTE )procPath,
&length ) != ERROR_SUCCESS )
return false;
loc = procPath;
return true;
}
std::wstring getGitLocation()
{
std::wstring gp = g_GitPath;
if ( gp.size() == 0 )
return TEXT("");
else
{
gp += TEXT("\\");
return gp;
}
}
///
/// Launches Git using the supplied command
///
/// @param Command line string to execute.
///
/// @return Whether or not Git could be launched.
///
int launchGit( std::wstring &command, bool b_notGui = true )
{
STARTUPINFOW si;
PROCESS_INFORMATION pi;
memset( &si, 0, sizeof( si ) );
memset( &pi, 0, sizeof( pi ) );
si.cb = sizeof( si );
if ( g_Debug )
OutputDebugString( command.c_str() );
int ret = 0;
std::wstring path = getCurrentFileDirectory().c_str();
if ( path.length() > 0 || b_notGui )
ret = CreateProcess(
NULL,
const_cast<LPWSTR>( command.c_str() ),
NULL,
NULL,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
NULL,
const_cast<LPCWSTR>( getCurrentFileDirectory().c_str() ),
&si,
&pi
);
else
ret = CreateProcess(
NULL,
const_cast<LPWSTR>( command.c_str() ),
NULL,
NULL,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&si,
&pi
);
if ( (ret == 0) && (path.length() == 0) )
ret = -1;
return ret;
}
///
/// Builds and executes command line string to send to CreateProcess
///
/// @param cmd Command name to execute.
/// @param all Execute command on all files, or just the current file.
/// @param ignoreFiles No files
/// @param pause Pause after command.
///
void ExecGitCommand(
const std::wstring &cmd,
std::vector<std::wstring> files,
bool ignoreFiles = false,
bool pause = true )
{
std::wstring command = TEXT( "cmd /d/c \"\"" );
command += getGitLocation();
command += TEXT( "git" );
command += cmd + TEXT( " " );
if ( !ignoreFiles )
{
for ( std::vector<std::wstring>::iterator itr = files.begin();
itr != files.end(); itr++ )
{
command += TEXT( "\"" );
command += ( *itr );
command += TEXT( "\"" );
if ( itr != files.end() - 1 )
command += TEXT( " " );
}
}
if ( pause )
command += TEXT( " & pause" );
command += TEXT( "\"" );
bool b_notGui = true;
if ( ignoreFiles && !pause )
b_notGui = false;
int ret = launchGit( command, b_notGui );
if ( ret <= 0 )
{
std::wstring err = TEXT( "Could not launch Git.\n\n" );
err += GetLastErrorString(GetLastError());
if ( ret == -1 )
err += TEXT( "\nCurrent directory is empty.\n Is this a \"new-1\" file or have you saved it?\n Is the file in a current git repo directory?" );
MessageBox( nppData._nppHandle, err.c_str(),
TEXT( "Failed" ), ( MB_OK | MB_ICONWARNING | MB_APPLMODAL ) );
}
updatePanel();
}
///
/// Builds and executes command line string to send to CreateProcess
/// See http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html
/// for TortoiseSVN command line parameters.
///
/// @param cmd Command name to execute.
/// @param all Execute command on all files, or just the current file.
///
void ExecTortoiseCommand(
const std::wstring &cmd,
std::vector<std::wstring> files,
bool ignoreFiles = false,
bool pause = true )
{
std::wstring command = g_tortoiseLoc;
command += TEXT( " /command:" ) + cmd + TEXT( " /path:\"" );
if ( !ignoreFiles )
{
for ( std::vector<std::wstring>::iterator itr = files.begin();
itr != files.end(); itr++ )
{
command += ( *itr );
if ( itr != files.end() - 1 )
command += TEXT( "*" );
}
}
else
command += TEXT( "*" );
if ( pause )
command += TEXT( "\" /closeonend:0" );
else
command += TEXT( "\" /closeonend:2" );
int ret = launchGit( command );
if ( ret <= 0 )
{
std::wstring err = TEXT( "Could not launch TortoiseGit.\n\n" );
err += GetLastErrorString(GetLastError());
if ( ret == -1 )
err += TEXT( "\nCurrent directory is empty.\n Is this a \"new-1\" file or have you saved it?\n Is the file in a current git repo directory?" );
MessageBox( nppData._nppHandle, err.c_str(),
TEXT( "Failed" ), ( MB_OK | MB_ICONWARNING | MB_APPLMODAL ) );
}
updatePanel();
}
////////////////////////////////////////////////////////////////////////////
///
/// Execution commands:
///
void updatePanelLoc()
{
if ( _gitPanel.isVisible() )
{
std::wstring temp;
_gitPanel.updateLoc( temp );
_gitPanel.updateListWithDelay();
}
}
void updatePanel()
{
if ( _gitPanel.isVisible() )
_gitPanel.updateList();
}
void gitPrompt()
{
std::wstring pathName;
if ( _gitPanel.isVisible() )
_gitPanel.updateLoc( pathName );
else
pathName = getCurrentFileDirectory();
ShellExecute( nppData._nppHandle, TEXT("open"), g_GitPrompt, NULL, pathName.c_str(), SW_SHOW );
}
void gitGui()
{
std::vector<std::wstring> files = {};
gitGuiFiles( files );
}
void gitGuiFiles( std::vector<std::wstring> files )
{
ExecGitCommand( TEXT( "-gui\"" ), files, true, false );
}
void giTk()
{
std::vector<std::wstring> files = {};
giTkFiles( files );
}
void giTkFiles( std::vector<std::wstring> files = {} )
{
ExecGitCommand( TEXT( "k\" --all" ), files, true, false );
}
void statusAll()
{
std::vector<std::wstring> files = {};
statusAllFiles( files );
}
void statusAllFiles( std::vector<std::wstring> files = {} )
{
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "repostatus" ), files, true , true);
else
ExecGitCommand( TEXT( "\" status" ), files, true, true);
}
void commitAll()
{
std::vector<std::wstring> files = {};
commitAllFiles( files );
}
void commitAllFiles( std::vector<std::wstring> files = {} )
{
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "commit" ), files, true, true );
else
ExecGitCommand( TEXT( "\" commit" ), files, true, true );
}
void addFile()
{
std::vector<std::wstring> files = {};
addFileFiles( files );
}
void addFileFiles( std::vector<std::wstring> files = {} )
{
if ( files.size() == 0 )
files.push_back( getCurrentFile() );
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "add" ), files, false, false );
else
ExecGitCommand( TEXT( "\" add" ), files, false, false );
}
void diffFile()
{
std::vector<std::wstring> files = {};
diffFileFiles( files );
}
void diffFileFiles( std::vector<std::wstring> files = {} )
{
if ( files.size() == 0 )
files.push_back( getCurrentFile() );
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "diff" ), files, false, true );
else
{
if ( g_DiffWordDiff )
ExecGitCommand( TEXT( "\" diff --word-diff" ), files, false, true );
else
ExecGitCommand( TEXT( "\" diff" ), files, false, true );
}
}
void unstageFile()
{
std::vector<std::wstring> files = {};
unstageFileFiles( files );
}
void unstageFileFiles( std::vector<std::wstring> files = {} )
{
if ( files.size() == 0 )
files.push_back( getCurrentFile() );
ExecGitCommand( TEXT( "\" reset HEAD" ), files, false, false );
}
void restoreFile()
{
std::vector<std::wstring> files = {};
restoreFileFiles( files );
}
void restoreFileFiles( std::vector<std::wstring> files = {} )
{
if ( files.size() == 0 )
files.push_back( getCurrentFile() );
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "revert" ), files, false, false );
else
ExecGitCommand( TEXT( "\" checkout --" ), files, false, false );
}
void logFile()
{
std::vector<std::wstring> files = {};
logFileFiles( files );
}
void logFileFiles( std::vector<std::wstring> files = {} )
{
if ( files.size() == 0 )
files.push_back( getCurrentFile() );
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "log" ), files, false, true );
else
ExecGitCommand( TEXT( "\" log" ), files, false, true );
}
void blameFile()
{
std::vector<std::wstring> files = {};
blameFileFiles( files );
}
void blameFileFiles( std::vector<std::wstring> files = {} )
{
if ( files.size() == 0 )
files.push_back( getCurrentFile() );
Sci_Position pos = (Sci_Position)::SendMessage( getCurScintilla(), SCI_GETCURRENTPOS, 0, 0 );
Sci_Position line = (Sci_Position)::SendMessage( getCurScintilla(), SCI_LINEFROMPOSITION, pos, 0 );
if ( g_useTortoise )
{
std::wstring blame = TEXT( "blame /line:" );
blame += std::to_wstring( line + 1 );
ExecTortoiseCommand( blame, files, false, true );
}
else
{
if (g_gitGuiBlame)
{
std::wstring blame = TEXT( "-gui\" blame --line=" );
blame += std::to_wstring( line + 1 );
ExecGitCommand( blame, files, false, false );
}
else
ExecGitCommand( TEXT( "\" blame" ), files, false, true );
}
}
void branchFile()
{
std::vector<std::wstring> files = {};
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "switch" ), files, true, true );
else
{
MessageBox( nppData._nppHandle, TEXT("Only supported with TortioseGit"), TEXT("Not Implemented"), MB_OK );
// files.push_back( getBranchDlg() );
// branchFileFiles( files );
}
}
void branchFileFiles( std::vector<std::wstring> files = {} )
{
ExecGitCommand( TEXT( "\" branch" ), files, false, false );
ExecGitCommand( TEXT( "\" checkout" ), files, false, true );
}
void pullFile()
{
std::vector<std::wstring> files = {};
pullFileFiles( files );
}
void pullFileFiles( std::vector<std::wstring> files = {} )
{
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "pull" ), files, true, true );
else
ExecGitCommand( TEXT( "\" pull" ), files, true, true );
}
void pushFile()
{
std::vector<std::wstring> files = {};
pushFileFiles( files );
}
void pushFileFiles( std::vector<std::wstring> files = {} )
{
if ( g_useTortoise )
ExecTortoiseCommand( TEXT( "push" ), files, true, true );
else
ExecGitCommand( TEXT( "\" push" ), files, true, true );
}
void doTortoise()
{
// UINT state = ::GetMenuState( ::GetMenu( nppData._nppHandle ),
// funcItem[TORTOISE_INDEX]._cmdID,
// MF_BYCOMMAND );
if ( g_useTortoise )
{
g_useTortoise = false;
::SendMessage( nppData._nppHandle, NPPM_SETMENUITEMCHECK,
funcItem[TORTOISE_INDEX]._cmdID, MF_UNCHECKED );
}
else
{
if ( ! getTortoiseLocation( g_tortoiseLoc ) )
{
MessageBox( nppData._nppHandle, TEXT( "Could not locate TortoiseGit" ),
TEXT( "Not Found" ), ( MB_OK | MB_ICONWARNING | MB_APPLMODAL ) );
g_useTortoise = false;
return;
}
else
{
g_useTortoise = true;
::SendMessage( nppData._nppHandle, NPPM_SETMENUITEMCHECK,
funcItem[TORTOISE_INDEX]._cmdID, MF_CHECKED );
}
}
}
////////////////////////////////////////////////////////////////////////////
///
/// Dockable dialog:
///
void DockableDlg()
{
_gitPanel.setParent( nppData._nppHandle );
tTbData data = {0};
if ( !_gitPanel.isCreated() )
{
_gitPanel.create( &data );
// define the default docking behaviour
data.uMask = DWS_DF_CONT_LEFT | DWS_ICONTAB;
data.hIconTab = ( HICON )::LoadImage( _gitPanel.getHinst(),
MAKEINTRESOURCE( IDI_PLUGINGITPANEL ), IMAGE_ICON, 0, 0,
LR_LOADTRANSPARENT );
data.pszModuleName = _gitPanel.getPluginFileName();
// the dlgDlg should be the index of funcItem where the current function pointer is
// in this case is DOCKABLE_INDEX
data.dlgID = DOCKABLE_INDEX;
::SendMessage( nppData._nppHandle, NPPM_DMMREGASDCKDLG, 0,
( LPARAM )&data );
_gitPanel.setClosed(true);
}
if ( _gitPanel.isClosed() || g_RaisePanel )
{
_gitPanel.display();
_gitPanel.setClosed(false);
::SendMessage( nppData._nppHandle, NPPM_SETMENUITEMCHECK,
funcItem[DOCKABLE_INDEX]._cmdID, MF_CHECKED );
}
else
{
_gitPanel.display( false );
_gitPanel.setClosed(true);
::SendMessage( nppData._nppHandle, NPPM_SETMENUITEMCHECK,
funcItem[DOCKABLE_INDEX]._cmdID, MF_UNCHECKED );
}
}