-
Notifications
You must be signed in to change notification settings - Fork 5
/
GitPanelDlg.cpp
891 lines (761 loc) · 31.4 KB
/
GitPanelDlg.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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
//this file is part of notepad++
//Copyright (C)2003 Don HO ( donho@altern.org )
//
//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 "ContextMenu.h"
#include "GitPanelDlg.h"
#include "Process.h"
#include "SettingsDlg.h"
#include "resource.h"
#include <algorithm>
#include <codecvt>
#include <commctrl.h>
#include <fstream>
#include <locale>
#include <shlobj.h>
#include <vector>
#include <windowsx.h>
extern TCHAR g_GitPath[MAX_PATH];
extern TCHAR g_GitPrompt[MAX_PATH];
extern bool g_useTortoise;
extern bool g_NppReady;
extern bool g_useNppColors;
extern bool g_RaisePanel;
extern bool g_Debug;
LVITEM LvItem;
LVCOLUMN LvCol;
COLORREF colorBg;
COLORREF colorFg;
// #define COL_CHK 0
#define COL_I 0
#define COL_W 1
#define COL_FILE 2
#define TIMER_ID 1
#define LSV1_REFRESH_DELAY 1500
const int WS_TOOLBARSTYLE = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER;
/* WS_CHILD | WS_VISIBLE | CCS_NORESIZE | CCS_ADJUSTABLE */
TBBUTTON tbButtonsAdd1[] =
{
{MAKELONG( 0, 0 ), IDC_BTN_GITGUI, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 1, 0 ), IDC_BTN_GITK, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 2, 0 ), IDC_BTN_PROMPT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{0, 0, 0, BTNS_SEP, {0}, 0, 0},
{MAKELONG( 3, 0 ), IDC_BTN_PULL, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 4, 0 ), IDC_BTN_STATUS, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{0, 0, 0, BTNS_SEP, {0}, 0, 0},
{MAKELONG( 5, 0 ), IDC_BTN_COMMIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 6, 0 ), IDC_BTN_PUSH, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0}
};
const int sizeButtonArray1 = sizeof( tbButtonsAdd1 ) / sizeof( TBBUTTON );
const int numButtons1 = sizeButtonArray1 - 2 /* separators */;
TBBUTTON tbButtonsAdd2[] =
{
{MAKELONG( 0, 0 ), IDC_BTN_ADD, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 1, 0 ), IDC_BTN_UNSTAGE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 2, 0 ), IDC_BTN_RESTORE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 3, 0 ), IDC_BTN_DIFF, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{0, 0, 0, BTNS_SEP, {0}, 0, 0},
{MAKELONG( 4, 0 ), IDC_BTN_LOG, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{MAKELONG( 5, 0 ), IDC_BTN_BLAME, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0},
{0, 0, 0, BTNS_SEP, {0}, 0, 0},
{MAKELONG( 6, 0 ), IDC_BTN_SETTINGS, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0, 0}
};
const int sizeButtonArray2 = sizeof( tbButtonsAdd2 ) / sizeof( TBBUTTON );
const int numButtons2 = sizeButtonArray2 - 2 /* separators */;
static LPCTSTR szToolTip[16] = {
TEXT("Git GUI"),
TEXT("GiTk"),
TEXT("Git Prompt"),
TEXT("Pull"),
TEXT("Status"),
TEXT("Commit"),
TEXT("Push"),
TEXT("Add"),
TEXT("Unstage"),
TEXT("Restore"),
TEXT("Diff"),
TEXT("Log"),
TEXT("Blame"),
TEXT("Settings")
};
LPCTSTR GetNameStrFromCmd( UINT_PTR resID )
{
if ((IDC_BTN_GITGUI <= resID) && (resID <= IDC_BTN_SETTINGS)) {
return szToolTip[resID - IDC_BTN_GITGUI];
}
return NULL;
}
void imageToolbar( HINSTANCE hInst, HWND hWndToolbar, UINT ToolbarID, const int numButtons )
{
HBITMAP hbm = LoadBitmap( hInst, MAKEINTRESOURCE( ToolbarID ) );
BITMAP bm = {0};
GetObject( hbm, sizeof( BITMAP ), &bm );
int iImageWidth = bm.bmWidth / numButtons;
int iImageHeight = bm.bmHeight;
HIMAGELIST himlToolBar1 = ( HIMAGELIST )SendMessage( hWndToolbar, TB_GETIMAGELIST, 0, 0 );
ImageList_Destroy( himlToolBar1 );
himlToolBar1 = ImageList_Create( iImageWidth, iImageHeight, ILC_COLOR32 | ILC_MASK, numButtons, 0 );
ImageList_AddMasked( himlToolBar1, hbm, RGB( 192, 192, 192 ) );
SendMessage( hWndToolbar, TB_SETIMAGELIST, 0, ( LPARAM )himlToolBar1 );
}
void DemoDlg::doRefreshTimer()
{
KillTimer( _hSelf, TIMER_ID );
SetTimer( _hSelf, TIMER_ID, LSV1_REFRESH_DELAY, NULL );
}
std::vector<std::wstring> DemoDlg::split( std::wstring stringToBeSplitted,
std::wstring delimeter )
{
std::vector<std::wstring> splittedString;
size_t startIndex = 0;
size_t endIndex = 0;
while ( ( endIndex = stringToBeSplitted.find( delimeter,
startIndex ) ) < stringToBeSplitted.size() )
{
std::wstring val = stringToBeSplitted.substr( startIndex,
endIndex - startIndex );
splittedString.push_back( val );
startIndex = endIndex + delimeter.size();
}
if ( startIndex < stringToBeSplitted.size() )
{
std::wstring val = stringToBeSplitted.substr( startIndex );
splittedString.push_back( val );
}
return splittedString;
}
// void DemoDlg::convertProcessText2Wide( std::wstring outputW, std::wstring &wide )
// {
// std::string output(outputW.begin(), outputW.end());
// output.assign(outputW.begin(), outputW.end());
// std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
// wide = converter.from_bytes(output.c_str());
// }
void DemoDlg::clearList()
{
SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_DELETEALLITEMS, 0, 0 );
}
bool DemoDlg::updateLoc( std::wstring &loc )
{
TCHAR pathName[MAX_PATH] = {0};
SendMessage( _hParent, NPPM_GETCURRENTDIRECTORY, MAX_PATH, ( LPARAM )pathName );
SendMessage( GetDlgItem( _hSelf, IDC_EDT_DIR ), WM_SETTEXT, 0, ( LPARAM )pathName );
loc = pathName;
return true;
}
void DemoDlg::setListColumns( unsigned int uItem, std::wstring strI, std::wstring strW,
std::wstring strFile )
{
// https://www.codeproject.com/Articles/2890/Using-ListView-control-under-Win32-API
memset( &LvItem, 0, sizeof( LvItem ) ); // Zero struct's Members
LvItem.mask = LVIF_TEXT; // Text Style
LvItem.cchTextMax = MAX_PATH; // Max size of text
LvItem.iItem = uItem; // choose item
// LvItem.iSubItem = COL_CHK; // Put in first coluom
// LvItem.pszText = TEXT( "" );
// SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_INSERTITEM, 0, ( LPARAM )&LvItem );
LvItem.iSubItem = COL_I; // Put in second coluom
LvItem.pszText = const_cast<LPWSTR>( strI.c_str() );
SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_INSERTITEM, 0, ( LPARAM )&LvItem );
LvItem.iSubItem = COL_W; // Put in third coluom
LvItem.pszText = const_cast<LPWSTR>( strW.c_str() );
SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_SETITEM, 0, ( LPARAM )&LvItem );
LvItem.iSubItem = COL_FILE; // Put in fourth coluom
LvItem.pszText = const_cast<LPWSTR>( strFile.c_str() );
SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_SETITEM, 0, ( LPARAM )&LvItem );
}
std::vector<std::wstring> DemoDlg::getListSelected(void)
{
std::vector<std::wstring> selectedItems;
int itemInt = -1;
itemInt = ( int )::SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_GETNEXTITEM, itemInt, LVNI_SELECTED );
if ( itemInt == -1 )
return selectedItems;
std::wstring wide = TEXT( "" );
if ( execCommand( TEXT( "git.exe rev-parse --show-toplevel" ), wide ) )
{
wide.erase(std::remove(wide.begin(), wide.end(), '\n'), wide.end());
for (itemInt = -1; ( itemInt = ( int )::SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_GETNEXTITEM, itemInt, LVNI_SELECTED ) ) != -1; )
{
TCHAR file[MAX_PATH] = {0};
memset( &LvItem, 0, sizeof(LvItem) );
LvItem.mask = LVIF_TEXT;
LvItem.iSubItem = COL_FILE;
LvItem.pszText = file;
LvItem.cchTextMax = MAX_PATH;
LvItem.iItem = itemInt;
SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_GETITEMTEXT, itemInt, (LPARAM)&LvItem );
std::wstring tempPath = wide;
tempPath += TEXT( "\\" );
tempPath += file;
DWORD fileOrDir = GetFileAttributes( tempPath.c_str() );
if ( fileOrDir == INVALID_FILE_ATTRIBUTES )
{
selectedItems = {};
return selectedItems;
}
for (unsigned int j = 0; j < tempPath.size(); j++) {
if (tempPath[j] == '/') {
tempPath[j] = '\\';
}
}
selectedItems.push_back( tempPath );
}
}
return selectedItems;
}
bool DemoDlg::execCommand( std::wstring command, std::wstring &wide )
{
wide = TEXT( "" );
std::wstring pathName = TEXT( "" );
updateLoc( pathName );
if ( pathName.empty() )
return false;
const TCHAR *programPath = TEXT( "\0" ); // Overridden as NULL in Process.cpp
const TCHAR *pProgramDir = pathName.c_str();
const TCHAR *progInput = TEXT( "" );
const TCHAR *progOutput = TEXT( "" );
generic_string progInputStr = progInput ? progInput : TEXT( "" );
generic_string progOutputStr = progOutput ? progOutput : TEXT( "" );
generic_string paramInput = getGitLocation();
paramInput += command;
if ( g_Debug )
OutputDebugString( paramInput.c_str() );
Process program( programPath, paramInput.c_str(), pProgramDir,
CONSOLE_PROG );
program.run();
if ( !program.hasStderr() )
{
const char *pOutput = NULL;
size_t pOutputLen = 0;
// If progOutput is defined, then we search the file to read
if ( progOutputStr != TEXT( "" ) )
{
if ( ::PathFileExists( progOutputStr.c_str() ) )
{
// open the file for binary reading
std::ifstream file;
file.open( progOutputStr.c_str(), std::ios_base::binary );
std::vector<byte> fileContent;
if ( file.is_open() )
{
// get the length of the file
file.seekg( 0, std::ios::end );
pOutputLen = static_cast<size_t>( file.tellg() );
file.seekg( 0, std::ios::beg );
// create a vector to hold all the bytes in the file
fileContent.resize( pOutputLen, 0 );
// read the file
file.read( reinterpret_cast<char *>( &fileContent[0] ),
( std::streamsize )pOutputLen );
// close the file
file.close();
pOutput = reinterpret_cast<const char *>( &fileContent[0] );
}
const char errMsg[] = "ERROR: NO FILE CONTENT";
if ( !pOutput || !( pOutput[0] ) )
{
pOutput = errMsg;
pOutputLen = strlen( errMsg );
}
}
else
{
::MessageBox( NULL, TEXT( "The file is invalid" ), progOutputStr.c_str(),
MB_OK );
wide = progOutputStr.c_str();
return false;
}
}
// otherwise, we look in stdout
else if ( program.hasStdout() )
{
// convertProcessText2Wide( program.getStdout(), wide );
wide = program.getStdout();
return true;
}
}
else
{
// convertProcessText2Wide( program.getStderr(), wide );
wide = program.getStderr();
return false;
}
return false;
}
void DemoDlg::updateListWithDelay()
{
if ( ! g_NppReady )
return;
doRefreshTimer();
}
void DemoDlg::updateList()
{
KillTimer( _hSelf, TIMER_ID );
if ( ! g_NppReady )
return;
clearList();
std::wstring wide = TEXT( "" );
if ( execCommand( TEXT( "git.exe status --porcelain --branch" ), wide ) )
{
std::vector<std::wstring> splittedStrings = split( wide, TEXT( "\n" ) );
std::wstring strBranch = splittedStrings[0].erase(0, 3);
SendMessage( GetDlgItem( _hSelf, IDC_EDT_BRANCH ), WM_SETTEXT, 0, ( LPARAM )strBranch.c_str() );
for ( unsigned int i = 1; i < splittedStrings.size() ; i++ )
{
std::wstring strI = splittedStrings[i].substr(0, 1);
std::wstring strW = splittedStrings[i].substr(1, 1);
std::wstring strFile = splittedStrings[i].erase(0, 3);
setListColumns( i-1, strI, strW, strFile );
}
}
else
{
SendMessage( GetDlgItem( _hSelf, IDC_EDT_BRANCH ), WM_SETTEXT, 0, ( LPARAM )wide.c_str() );
setListColumns( 0, TEXT( "" ), TEXT( "" ), TEXT( "" ) );
}
}
void DemoDlg::SetNppColors()
{
colorBg = ( COLORREF )::SendMessage( getCurScintilla(), SCI_STYLEGETBACK, 0, 0 );
colorFg = ( COLORREF )::SendMessage( getCurScintilla(), SCI_STYLEGETFORE, 0, 0 );
}
void DemoDlg::SetSysColors()
{
colorBg = GetSysColor( COLOR_WINDOW );
colorFg = GetSysColor( COLOR_WINDOWTEXT );
}
void DemoDlg::ChangeColors()
{
HWND hList = GetDlgItem( _hSelf, IDC_LSV1 );
::SendMessage(hList, WM_SETREDRAW, FALSE, 0);
ListView_SetBkColor( hList, colorBg );
ListView_SetTextBkColor( hList, colorBg);
ListView_SetTextColor( hList, colorFg);
::SendMessage(hList, WM_SETREDRAW, TRUE, 0);
::RedrawWindow(hList, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
}
void DemoDlg::refreshDialog()
{
SendMessage( GetDlgItem( _hSelf, IDC_CHK_TORTOISE ), BM_SETCHECK,
( WPARAM )( g_useTortoise ? 1 : 0 ), 0 );
SendMessage( GetDlgItem( _hSelf, IDC_CHK_NPPCOLOR ), BM_SETCHECK,
( WPARAM )( g_useNppColors ? 1 : 0 ), 0 );
SendMessage( GetDlgItem( _hSelf, IDC_CHK_PANELTOGGLE ), BM_SETCHECK,
( WPARAM )( g_RaisePanel ? 1 : 0 ), 0 );
}
void DemoDlg::initDialog()
{
INITCOMMONCONTROLSEX ic;
ic.dwSize = sizeof( INITCOMMONCONTROLSEX );
ic.dwICC = ICC_BAR_CLASSES | ICC_PAGESCROLLER_CLASS;
InitCommonControlsEx( &ic );
HWND hWndToolbar1, hWndToolbar2, hWndPager1, hWndPager2;
HMODULE module_name = GetModuleHandle( _moduleName.c_str() );
// TOOLBAR1
// Create pager. The parent window is the parent.
hWndPager1 = CreateWindow( WC_PAGESCROLLER, NULL, WS_VISIBLE | WS_CHILD | PGS_HORZ,
0, 0, 200, 32, _hSelf, (HMENU) IDB_PAGER1, module_name, NULL );
// Create Toolbar. The parent window is the Pager.
hWndToolbar1 = CreateWindowEx( 0, TOOLBARCLASSNAME, NULL, WS_TOOLBARSTYLE,
0, 0, 200, 32, hWndPager1, ( HMENU ) IDB_TOOLBAR1, module_name, NULL );
SendMessage( hWndToolbar1, TB_BUTTONSTRUCTSIZE, sizeof( TBBUTTON ), 0 );
SendMessage( hWndToolbar1, TB_SETEXTENDEDSTYLE, 0, ( LPARAM ) TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DRAWDDARROWS );
SendMessage( hWndToolbar1, TB_ADDBUTTONS, sizeButtonArray1, ( LPARAM )tbButtonsAdd1 );
SendMessage( hWndToolbar1, TB_AUTOSIZE, 0, 0 );
// Notify the pager that it contains the toolbar
SendMessage(hWndPager1, PGM_SETCHILD, 0, (LPARAM) hWndToolbar1);
imageToolbar( module_name, hWndToolbar1, IDB_TOOLBAR1, numButtons1 );
// TOOLBAR2
// Create pager. The parent window is the parent.
hWndPager2 = CreateWindow( WC_PAGESCROLLER, NULL, WS_VISIBLE | WS_CHILD | PGS_HORZ,
0, 32, 200, 32, _hSelf, (HMENU) IDB_PAGER2, module_name, NULL );
// Create Toolbar. The parent window is the Pager.
hWndToolbar2 = CreateWindowEx( 0, TOOLBARCLASSNAME, NULL, WS_TOOLBARSTYLE,
0, 0, 200, 32, hWndPager2, ( HMENU ) IDB_TOOLBAR2, module_name, NULL );
SendMessage( hWndToolbar2, TB_BUTTONSTRUCTSIZE, sizeof( TBBUTTON ), 0 );
SendMessage( hWndToolbar1, TB_SETEXTENDEDSTYLE, 0, ( LPARAM ) TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DRAWDDARROWS );
SendMessage( hWndToolbar2, TB_ADDBUTTONS, sizeButtonArray2, ( LPARAM )tbButtonsAdd2 );
SendMessage( hWndToolbar2, TB_AUTOSIZE, 0, 0 );
// in CreateWindowEx()
SendMessage(hWndPager2, PGM_SETCHILD, 0, (LPARAM) hWndToolbar2);
imageToolbar( module_name, hWndToolbar2, IDB_TOOLBAR2, numButtons2 );
// Edit and List controls
if ( g_useNppColors )
SetNppColors();
else
SetSysColors();
ChangeColors();
refreshDialog();
HWND hList = GetDlgItem( _hSelf, IDC_LSV1 );
// https://www.codeproject.com/Articles/2890/Using-ListView-control-under-Win32-API
SendMessage( hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ( LVS_EX_FULLROWSELECT /*| LVS_EX_CHECKBOXES*/ ) );
memset( &LvCol, 0, sizeof( LvCol ) ); // Zero Members
LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; // Type of mask
// Column I and W are Index and Working from:
// https://git-scm.com/docs/git-status
// LvCol.cx = 25; // width between each coloum
// LvCol.pszText = TEXT( "" ); // First Header Text
// SendMessage( hList, LVM_INSERTCOLUMN, COL_CHK, ( LPARAM )&LvCol );
LvCol.cx = 25; // width between each coloum
LvCol.pszText = TEXT( "I" ); // Second Header Text
SendMessage( hList, LVM_INSERTCOLUMN, COL_I, ( LPARAM )&LvCol );
LvCol.cx = 25; // width between each coloum
LvCol.pszText = TEXT( "W" ); // Third Header Text
SendMessage( hList, LVM_INSERTCOLUMN, COL_W, ( LPARAM )&LvCol );
LvCol.cx = 25; // width of column
LvCol.pszText = TEXT( "File" ); // Fourth Header Text
SendMessage( hList, LVM_INSERTCOLUMN, COL_FILE, ( LPARAM )&LvCol );
SendMessage( hList, LVM_SETCOLUMNWIDTH, COL_FILE, LVSCW_AUTOSIZE_USEHEADER );
updateList();
}
void DemoDlg::gotoFile()
{
std::vector<std::wstring> files = getListSelected();
if ( files.size() == 0 )
return;
for ( unsigned int i = 0; i < files.size(); i++ )
{
DWORD fileOrDir = GetFileAttributes( files[i].c_str() );
if ( fileOrDir == INVALID_FILE_ATTRIBUTES )
return;
else if ( fileOrDir & FILE_ATTRIBUTE_DIRECTORY )
{
std::wstring err = TEXT( "" );
err += files[i];
err += TEXT( "\n\nIs a directory. Continue to open all files?" );
int ret = ( int )::MessageBox( _hSelf, err.c_str(), TEXT( "Continue?" ), ( MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL ) );
if ( ret == IDYES )
SendMessage( _hParent, NPPM_DOOPEN, 0, ( LPARAM )files[i].c_str() );
}
else
SendMessage( _hParent, NPPM_DOOPEN, 0, ( LPARAM )files[i].c_str() );
}
}
INT_PTR CALLBACK DemoDlg::run_dlgProc( UINT message, WPARAM wParam, LPARAM lParam )
{
switch ( message )
{
case WM_COMMAND :
{
switch ( wParam )
{
case IDC_BTN_GITGUI :
{
gitGui();
return TRUE;
}
case IDC_BTN_GITK :
{
giTk();
return TRUE;
}
case IDC_BTN_PROMPT :
{
std::wstring pathName = TEXT( "" );
updateLoc( pathName );
ShellExecute( _hParent, TEXT("open"), g_GitPrompt, NULL, pathName.c_str(), SW_SHOW );
return TRUE;
}
case IDC_BTN_DIFF :
{
std::vector<std::wstring> files = getListSelected();
if ( files.size() == 0 )
diffFile();
else
diffFileFiles( files );
doRefreshTimer();
return TRUE;
}
case IDC_BTN_ADD :
{
std::vector<std::wstring> files = getListSelected();
if ( files.size() == 0 )
addFile();
else
addFileFiles( files );
doRefreshTimer();
return TRUE;
}
case IDC_BTN_UNSTAGE :
{
std::vector<std::wstring> files = getListSelected();
if ( files.size() == 0 )
unstageFile();
else
unstageFileFiles( files );
doRefreshTimer();
return TRUE;
}
case IDC_BTN_RESTORE :
{
std::vector<std::wstring> files = getListSelected();
if ( files.size() == 0 )
restoreFile();
else
restoreFileFiles( files );
doRefreshTimer();
return TRUE;
}
case IDC_BTN_LOG :
{
logFile();
return TRUE;
}
case IDC_BTN_BLAME :
{
blameFile();
return TRUE;
}
case IDC_BTN_PULL :
{
pullFile();
doRefreshTimer();
return TRUE;
}
case IDC_BTN_STATUS :
{
statusAll();
doRefreshTimer();
return TRUE;
}
case IDC_BTN_COMMIT :
{
commitAll();
doRefreshTimer();
return TRUE;
}
case IDC_BTN_PUSH :
{
pushFile();
return TRUE;
}
case IDB_BTN_BRANCH :
{
branchFile();
doRefreshTimer();
return TRUE;
}
case IDC_BTN_SETTINGS :
{
doSettings();
return TRUE;
}
case IDC_CHK_TORTOISE :
{
doTortoise();
return TRUE;
}
case IDC_CHK_NPPCOLOR:
{
int check = ( int )::SendMessage( GetDlgItem( _hSelf, IDC_CHK_NPPCOLOR ),
BM_GETCHECK, 0, 0 );
if ( check & BST_CHECKED )
{
SetNppColors();
g_useNppColors = true;
}
else
{
SetSysColors();
g_useNppColors = false;
}
ChangeColors();
refreshDialog();
return TRUE;
}
case IDC_CHK_PANELTOGGLE:
{
int check = ( int )::SendMessage( GetDlgItem( _hSelf, IDC_CHK_PANELTOGGLE ),
BM_GETCHECK, 0, 0 );
if ( check & BST_CHECKED )
g_RaisePanel = true;
else
g_RaisePanel = false;
return TRUE;
}
case IDB_BTN_GOTOREMOTE:
{
std::wstring wide = TEXT( "" );
if ( execCommand( TEXT( "git config --get remote.origin.url" ), wide ) )
{
ShellExecute(_hSelf, TEXT("open"), wide.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
return TRUE;
}
case MAKELONG( IDC_EDT_BRANCH, EN_SETFOCUS ) :
case MAKELONG( IDC_EDT_DIR, EN_SETFOCUS ) :
{
doRefreshTimer();
return TRUE;
}
// Trap VK_ENTER in the LISTVIEW
case IDOK :
{
HWND hWndCtrl = GetFocus();
if ( hWndCtrl == GetDlgItem( _hSelf, IDC_LSV1 ) )
gotoFile();
return TRUE;
}
// Trap VK_ESCAPE
case IDCANCEL :
{
::SetFocus( getCurScintilla() );
return TRUE;
}
}
return FALSE;
}
case WM_TIMER:
{
KillTimer( _hSelf, TIMER_ID );
updateList();
return FALSE;
}
case WM_NOTIFY:
{
LPNMHDR nmhdr = (LPNMHDR)lParam;
switch ( nmhdr->code )
{
case NM_DBLCLK:
{
if ( nmhdr->hwndFrom == GetDlgItem( _hSelf, IDC_LSV1 ) )
{
POINT pt = {0};
LVHITTESTINFO ht = {0};
DWORD dwpos = ::GetMessagePos();
pt.x = GET_X_LPARAM(dwpos);
pt.y = GET_Y_LPARAM(dwpos);
ht.pt = pt;
::ScreenToClient( GetDlgItem( _hSelf, IDC_LSV1 ), &ht.pt);
ListView_SubItemHitTest( GetDlgItem( _hSelf, IDC_LSV1 ), &ht);
if ( ht.iItem == -1 )
break;
std::vector<std::wstring> files = getListSelected();
if ( files.size() == 0 )
break;
if ( ht.iSubItem == COL_I )
{
unstageFileFiles( files );
doRefreshTimer();
}
else if ( ht.iSubItem == COL_W )
{
addFileFiles( files );
doRefreshTimer();
}
else if ( ht.iSubItem == COL_FILE )
{
for ( unsigned int i = 0; i < files.size(); i++ )
{
DWORD fileOrDir = GetFileAttributes( files[i].c_str() );
if ( fileOrDir == INVALID_FILE_ATTRIBUTES )
break;
else if ( fileOrDir & FILE_ATTRIBUTE_DIRECTORY )
{
std::wstring err = TEXT( "" );
err += files[i];
err += TEXT( "\n\nIs a directory. Continue to open all files?" );
int ret = ( int )::MessageBox( _hSelf, err.c_str(), TEXT( "Continue?" ), ( MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL ) );
if ( ret == IDYES )
SendMessage( _hParent, NPPM_DOOPEN, 0, ( LPARAM )files[i].c_str() );
}
else
SendMessage( _hParent, NPPM_DOOPEN, 0, ( LPARAM )files[i].c_str() );
}
}
}
return TRUE;
}
case NM_RCLICK:
{
if ( nmhdr->hwndFrom == GetDlgItem( _hSelf, IDC_LSV1 ) )
{
POINT pt = {0};
LVHITTESTINFO ht = {0};
DWORD dwpos = ::GetMessagePos();
pt.x = GET_X_LPARAM(dwpos);
pt.y = GET_Y_LPARAM(dwpos);
ContextMenu cm;
std::vector<std::wstring> files = getListSelected();
if ( files.size() == 0 )
break;
cm.SetObjects( files );
cm.ShowContextMenu( _hInst, _hParent, _hSelf, pt );
}
return TRUE;
}
case TTN_GETDISPINFO: /* TTN_NEEDTEXT */
{
UINT_PTR idButton;
LPTOOLTIPTEXT lpttt;
lpttt = (LPTOOLTIPTEXT) lParam;
lpttt->hinst = NULL;
idButton = lpttt->hdr.idFrom;
lpttt->lpszText = const_cast<LPTSTR>( GetNameStrFromCmd( idButton ) );
return TRUE;
}
case LVN_KEYDOWN:
{
LPNMLVKEYDOWN pnkd = (LPNMLVKEYDOWN) lParam;
if ( ( nmhdr->hwndFrom == GetDlgItem( _hSelf, IDC_LSV1 ) ) &&
( ( pnkd->wVKey == VK_RETURN )
|| ( pnkd->wVKey == VK_SPACE )
) )
{
gotoFile();
}
return TRUE;
}
}
return FALSE;
}
case WM_SIZE:
case WM_MOVE:
{
RECT rc = {0};
getClientRect( rc );
::SetWindowPos( GetDlgItem( _hSelf, IDC_EDT_BRANCH ), NULL,
rc.left + 5, rc.top + 120, rc.right - 75, 20,
SWP_NOZORDER | SWP_SHOWWINDOW );
::SetWindowPos( GetDlgItem( _hSelf, IDB_BTN_BRANCH ), NULL,
rc.right - 65, rc.top + 120, 60, 20,
SWP_NOZORDER | SWP_SHOWWINDOW );
::SetWindowPos( GetDlgItem( _hSelf, IDC_EDT_DIR ), NULL,
rc.left + 5, rc.top + 150, rc.right - 10, 20,
SWP_NOZORDER | SWP_SHOWWINDOW );
::SetWindowPos( GetDlgItem( _hSelf, IDC_LSV1 ), NULL,
rc.left + 5, rc.top + 180, rc.right - 10, rc.bottom - 185,
SWP_NOZORDER | SWP_SHOWWINDOW );
SendMessage( GetDlgItem( _hSelf, IDC_LSV1 ), LVM_SETCOLUMNWIDTH, COL_FILE, LVSCW_AUTOSIZE_USEHEADER );
// redraw();
return FALSE;
}
case WM_PAINT:
{
::RedrawWindow( _hSelf, NULL, NULL, TRUE);
return FALSE;
}
case WM_INITDIALOG :
{
initDialog();
return FALSE;
}
default :
return DockingDlgInterface::run_dlgProc( message, wParam, lParam );
}
// return FALSE;
}