forked from eranif/codelite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubversion_view.cpp
1490 lines (1259 loc) · 54.5 KB
/
subversion_view.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
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : subversion_view.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// 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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include <wx/app.h>
#include "event_notifier.h"
#include "svn_overlay_tool.h"
#include "diff_dialog.h"
#include "file_logger.h"
#include "svn_checkout_dialog.h"
#include "subversion2_ui.h"
#include "wx_tree_traverser.h"
#include <wx/settings.h>
#include "svn_select_local_repo_dlg.h"
#include <wx/filedlg.h>
#include <wx/textdlg.h>
#include "plugin.h"
#include "svn_local_properties.h"
#include "svn_props_dialog.h"
#include "procutils.h"
#include "bitmap_loader.h"
#include "svn_login_dialog.h"
#include "svn_command_handlers.h"
#include "svn_copy_dialog.h"
#include "svn_default_command_handler.h"
#include <wx/menu.h>
#include <wx/dirdlg.h>
#include "fileextmanager.h"
#include "svnsettingsdata.h"
#include "svnstatushandler.h"
#include <wx/wupdlock.h>
#include "subversion_strings.h"
#include "subversion_view.h"
#include <wx/xrc/xmlres.h>
#include "svntreedata.h"
#include <wx/imaglist.h>
#include "imanager.h"
#include "workspace.h"
#include "subversion2.h"
#include "svn_console.h"
#include "globals.h"
#include "SvnInfoDialog.h"
#include <map>
#include "cl_command_event.h"
#include "workspacesvnsettings.h"
#include <wx/cmdline.h>
#include "dirsaver.h"
#include "clcommandlineparser.h"
#include "DiffSideBySidePanel.h"
#include <wx/aui/auibar.h>
BEGIN_EVENT_TABLE(SubversionView, SubversionPageBase)
EVT_UPDATE_UI(XRCID("svn_stop"), SubversionView::OnStopUI)
EVT_UPDATE_UI(XRCID("clear_svn_output"), SubversionView::OnClearOuptutUI)
EVT_MENU(XRCID("svn_link_editor"), SubversionView::OnLinkEditor)
EVT_MENU(XRCID("svn_commit"), SubversionView::OnCommit)
EVT_MENU(XRCID("svn_update"), SubversionView::OnUpdate)
EVT_MENU(XRCID("svn_revert"), SubversionView::OnRevert)
EVT_MENU(XRCID("svn_tag"), SubversionView::OnTag)
EVT_MENU(XRCID("svn_branch"), SubversionView::OnBranch)
EVT_MENU(XRCID("svn_diff"), SubversionView::OnDiff)
EVT_MENU(XRCID("svn_patch"), SubversionView::OnPatch)
EVT_MENU(XRCID("svn_patch_dry_run"), SubversionView::OnPatchDryRun)
EVT_MENU(XRCID("svn_resolve"), SubversionView::OnResolve)
EVT_MENU(XRCID("svn_add"), SubversionView::OnAdd)
EVT_MENU(XRCID("svn_delete"), SubversionView::OnDelete)
EVT_MENU(XRCID("svn_ignore_file"), SubversionView::OnIgnoreFile)
EVT_MENU(XRCID("svn_ignore_file_pattern"), SubversionView::OnIgnoreFilePattern)
EVT_MENU(XRCID("svn_blame"), SubversionView::OnBlame)
EVT_MENU(XRCID("svn_checkout"), SubversionView::OnCheckout)
EVT_MENU(XRCID("svn_open_file"), SubversionView::OnOpenFile)
EVT_MENU(XRCID("svn_switch"), SubversionView::OnSwitch)
EVT_MENU(XRCID("svn_properties"), SubversionView::OnProperties)
EVT_MENU(XRCID("svn_log"), SubversionView::OnLog)
EVT_MENU(XRCID("svn_lock"), SubversionView::OnLock)
EVT_MENU(XRCID("svn_unlock"), SubversionView::OnUnLock)
EVT_MENU(XRCID("svn_rename"), SubversionView::OnRename)
EVT_MENU(XRCID("svn_open_local_repo_browser"), SubversionView::OnChangeRootDir)
END_EVENT_TABLE()
static int FOLDER_IMG_ID = wxNOT_FOUND;
static int MODIFIED_IMG_ID = wxNOT_FOUND;
static int NEW_IMG_ID = wxNOT_FOUND;
static int DELETED_IMG_ID = wxNOT_FOUND;
static int CONFLICT_IMG_ID = wxNOT_FOUND;
static int UNVERSIONED_IMG_ID = wxNOT_FOUND;
static int PROJECT_IMG_ID = wxNOT_FOUND;
static int WORKSPACE_IMG_ID = wxNOT_FOUND;
static int LOCKED_IMG_ID = wxNOT_FOUND;
/**
* @class DiffCmdHandler
* Handle diff "codelite-echo" command output
* Once we have our 3 lines output, we can "finalize" the diff
*/
class DiffCmdHandler : public IProcessCallback
{
SubversionView* m_view;
wxString m_output;
wxFileName m_filename; // the file which we want to diff
public:
DiffCmdHandler(SubversionView* view, const wxFileName& filename)
: m_view(view)
, m_filename(filename)
{
}
~DiffCmdHandler() {}
virtual void OnProcessOutput(const wxString& str)
{
m_output << str;
wxArrayString lines = ::wxStringTokenize(m_output, "\n", wxTOKEN_STRTOK);
if(lines.GetCount() == 3) {
// we got all the info we need
m_view->FinishDiff(lines.Item(2).Trim(), m_filename);
}
}
/**
* @brief the process has terminated, delete the instance and
* ourself
*/
virtual void OnProcessTerminated() { delete this; }
const wxFileName& GetFilename() const { return m_filename; }
};
SubversionView::SubversionView(wxWindow* parent, Subversion2* plugin)
: SubversionPageBase(parent)
, m_plugin(plugin)
, m_simpleCommand(plugin)
, m_diffCommand(plugin)
, m_fileExplorerLastBaseImgIdx(-1)
, m_codeliteEcho(NULL)
{
CreatGUIControls();
m_themeHelper = new ThemeHandlerHelper(this);
EventNotifier::Get()->Connect(
wxEVT_WORKSPACE_LOADED, wxCommandEventHandler(SubversionView::OnWorkspaceLoaded), NULL, this);
EventNotifier::Get()->Connect(
wxEVT_WORKSPACE_CLOSED, wxCommandEventHandler(SubversionView::OnWorkspaceClosed), NULL, this);
EventNotifier::Get()->Connect(wxEVT_FILE_SAVED, clCommandEventHandler(SubversionView::OnFileSaved), NULL, this);
EventNotifier::Get()->Connect(
wxEVT_PROJ_FILE_ADDED, clCommandEventHandler(SubversionView::OnFileAdded), NULL, this);
EventNotifier::Get()->Connect(wxEVT_FILE_RENAMED, wxCommandEventHandler(SubversionView::OnFileRenamed), NULL, this);
EventNotifier::Get()->Connect(
wxEVT_ACTIVE_EDITOR_CHANGED, wxCommandEventHandler(SubversionView::OnActiveEditorChanged), NULL, this);
::clRecalculateSTCHScrollBar(m_sci);
}
SubversionView::~SubversionView()
{
wxDELETE(m_themeHelper);
DisconnectEvents();
}
void SubversionView::OnChangeRootDir(wxCommandEvent& event)
{
wxUnusedVar(event);
wxString newPath = ::wxDirSelector(_("Choose directory"));
if(!newPath.IsEmpty()) {
DoRootDirChanged(newPath);
}
}
void SubversionView::OnTreeMenu(wxTreeEvent& event)
{
// Popup the menu
wxArrayTreeItemIds items;
size_t count = m_treeCtrl->GetSelections(items);
if(count) {
SvnTreeData::SvnNodeType type = DoGetSelectionType(items);
if(type == SvnTreeData::SvnNodeTypeInvalid)
// Mix or an invalid selection
return;
wxMenu menu;
switch(type) {
case SvnTreeData::SvnNodeTypeFile:
CreateFileMenu(&menu);
break;
case SvnTreeData::SvnNodeTypeRoot:
CreateRootMenu(&menu);
break;
case SvnTreeData::SvnNodeTypeAddedRoot:
case SvnTreeData::SvnNodeTypeDeletedRoot:
case SvnTreeData::SvnNodeTypeModifiedRoot:
case SvnTreeData::SvnNodeTypeFolder:
CreateSecondRootMenu(&menu);
break;
default:
return;
}
PopupMenu(&menu);
}
}
void SubversionView::CreatGUIControls()
{
MSWSetNativeTheme(m_treeCtrl);
// Assign the image list
BitmapLoader* bmpLoader = m_plugin->GetManager()->GetStdIcons();
// Prepare a default image list which contains all the mimetypes knows to FileExtManager
wxImageList* imageList = bmpLoader->MakeStandardMimeImageList();
// Append the subversion unique icons
FOLDER_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("mime/16/folder")));
MODIFIED_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("subversion/16/modified")));
NEW_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("subversion/16/new")));
DELETED_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("subversion/16/deleted")));
CONFLICT_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("subversion/16/conflict")));
UNVERSIONED_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("subversion/16/unversioned")));
PROJECT_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("workspace/16/project")));
WORKSPACE_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("workspace/16/workspace")));
LOCKED_IMG_ID = imageList->Add(bmpLoader->LoadBitmap(wxT("subversion/16/locked")));
m_treeCtrl->AssignImageList(imageList);
// Add toolbar
// Create the toolbar
BitmapLoader* bmpLdr = m_plugin->GetManager()->GetStdIcons();
wxAuiToolBar* tb = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_TB_PLAIN_BACKGROUND);
tb->AddTool(XRCID("svn_link_editor"),
_("Link Editor"),
wxXmlResource::Get()->LoadBitmap(wxT("link_editor")),
_("Link Editor"),
wxITEM_CHECK);
tb->ToggleTool(XRCID("svn_link_editor"), m_plugin->GetSettings().GetFlags() & SvnLinkEditor);
tb->AddTool(XRCID("svn_open_local_repo_browser"),
_("Select a Directory to View..."),
bmpLdr->LoadBitmap(wxT("toolbars/16/standard/file_open")),
_("Select a Directory to View..."),
wxITEM_NORMAL);
tb->AddSeparator();
tb->AddTool(XRCID("svn_stop"),
_("Stop current svn process"),
bmpLdr->LoadBitmap(wxT("subversion/16/stop")),
_("Stop current svn process"));
tb->AddTool(
XRCID("svn_cleanup"), _("Svn Cleanup"), bmpLdr->LoadBitmap(wxT("subversion/16/cleanup")), _("Svn Cleanup"));
tb->AddSeparator();
tb->AddTool(
XRCID("svn_checkout"), _("Svn Checkout"), bmpLdr->LoadBitmap(wxT("subversion/16/checkout")), _("Svn Checkout"));
tb->AddSeparator();
tb->AddTool(
XRCID("svn_refresh"), _("Refresh View"), bmpLdr->LoadBitmap(wxT("subversion/16/refresh")), _("Refresh View"));
tb->AddSeparator();
tb->AddTool(XRCID("clear_svn_output"),
_("Clear Svn Output Tab"),
bmpLdr->LoadBitmap(wxT("output-pane/16/clear")),
_("Clear Svn Output Tab"),
wxITEM_NORMAL);
tb->AddTool(XRCID("svn_settings"),
_("Svn Settings..."),
bmpLdr->LoadBitmap(wxT("subversion/16/settings")),
_("Svn Settings..."));
tb->AddTool(XRCID("svn_info"), _("Svn Info"), bmpLdr->LoadBitmap(wxT("subversion/16/info")), _("Svn Info"));
tb->Connect(XRCID("clear_svn_output"),
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(SubversionView::OnClearOuptut),
NULL,
this);
tb->Connect(
XRCID("svn_stop"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(SubversionView::OnStop), NULL, this);
tb->Connect(XRCID("svn_cleanup"),
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(SubversionView::OnCleanup),
NULL,
this);
tb->Connect(XRCID("svn_info"),
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(SubversionView::OnShowSvnInfo),
NULL,
this);
tb->Connect(XRCID("svn_refresh"),
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(SubversionView::OnRefreshView),
NULL,
this);
tb->Connect(XRCID("svn_settings"),
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(SubversionView::OnSettings),
NULL,
this);
wxSizer* sz = GetSizer();
sz->Insert(0, tb, 0, wxEXPAND);
tb->Realize();
m_subversionConsole = new SvnConsole(m_sci, m_plugin);
DoRootDirChanged(wxGetCwd());
BuildTree();
}
void SubversionView::BuildTree() { BuildTree(DoGetCurRepoPath()); }
void SubversionView::BuildTree(const wxString& root)
{
if(root.IsEmpty()) return;
DoChangeRootPathUI(root);
wxString command;
command << m_plugin->GetSvnExeName() << wxT(" status");
m_simpleCommand.Execute(command, root, new SvnStatusHandler(m_plugin, wxNOT_FOUND, NULL), m_plugin);
}
void SubversionView::BuildExplorerTree(const wxString& root)
{
if(root.IsEmpty()) return;
wxString command;
command << m_plugin->GetSvnExeName() << wxT(" status");
m_simpleCommand.Execute(command, root, new SvnStatusHandler(m_plugin, wxNOT_FOUND, NULL, true, root), m_plugin);
}
void SubversionView::OnWorkspaceLoaded(wxCommandEvent& event)
{
event.Skip();
// Workspace changes its directory to the workspace path, update the SVN path
wxString path = ::wxGetCwd();
m_workspaceFile = event.GetString();
WorkspaceSvnSettings conf(m_workspaceFile);
wxString customizedRepo = conf.Load().GetRepoPath();
if(!customizedRepo.IsEmpty()) {
path.swap(customizedRepo);
}
DoRootDirChanged(path);
BuildTree();
}
void SubversionView::OnWorkspaceClosed(wxCommandEvent& event)
{
event.Skip();
// Save the local svn settings
if(m_workspaceFile.IsOk() && m_workspaceFile.Exists()) {
WorkspaceSvnSettings conf(m_workspaceFile);
conf.SetRepoPath(m_curpath);
conf.Save();
}
m_workspaceFile.Clear();
DoChangeRootPathUI(_("<No repository path is selected>"));
m_plugin->GetConsole()->Clear();
}
void SubversionView::ClearAll() { m_treeCtrl->DeleteAllItems(); }
void SubversionView::UpdateTree(const wxArrayString& modifiedFiles,
const wxArrayString& conflictedFiles,
const wxArrayString& unversionedFiles,
const wxArrayString& newFiles,
const wxArrayString& deletedFiles,
const wxArrayString& lockedFiles,
const wxArrayString& ignoreFiles,
bool fileExplorerOnly,
const wxString& sRootDir)
{
wxString rootDir = sRootDir;
if(rootDir.IsEmpty()) rootDir = DoGetCurRepoPath();
if(!fileExplorerOnly) {
#ifdef __WXMSW__
wxWindowUpdateLocker locker(m_treeCtrl);
#else
clWindowUpdateLocker locker(m_treeCtrl);
#endif
ClearAll();
// Add root node
wxTreeItemId root = m_treeCtrl->AddRoot(
rootDir, FOLDER_IMG_ID, FOLDER_IMG_ID, new SvnTreeData(SvnTreeData::SvnNodeTypeRoot, rootDir));
if(root.IsOk() == false) return;
DoAddNode(svnMODIFIED_FILES, MODIFIED_IMG_ID, SvnTreeData::SvnNodeTypeModifiedRoot, modifiedFiles);
DoAddNode(svnADDED_FILES, NEW_IMG_ID, SvnTreeData::SvnNodeTypeAddedRoot, newFiles);
DoAddNode(svnDELETED_FILES, DELETED_IMG_ID, SvnTreeData::SvnNodeTypeDeletedRoot, deletedFiles);
DoAddNode(svnCONFLICTED_FILES, CONFLICT_IMG_ID, SvnTreeData::SvnNodeTypeConflictRoot, conflictedFiles);
DoAddNode(svnLOCKED_FILES, LOCKED_IMG_ID, SvnTreeData::SvnNodeTypeLockedRoot, lockedFiles);
DoAddNode(svnUNVERSIONED_FILES, UNVERSIONED_IMG_ID, SvnTreeData::SvnNodeTypeUnversionedRoot, unversionedFiles);
if(m_treeCtrl->ItemHasChildren(root)) {
m_treeCtrl->Expand(root);
}
DoLinkEditor();
}
#ifdef __WXMSW__
return;
#endif
DoCreateFileExplorerImages();
#if 0
if(m_fileExplorerLastBaseImgIdx != -1) {
// Unified all the arrays into a single map
SvnFileExplorerTraverser::Map_t mymap;
wxTreeCtrl* fileExplorer = m_plugin->GetManager()->GetTree(TreeFileExplorer);
wxTreeItemId feRootItem = fileExplorer->GetItemByFullPath(rootDir);
#ifdef __WXMSW__
wxWindowUpdateLocker locker(fileExplorer);
#else
clWindowUpdateLocker locker(fileExplorer);
#endif
DoAddArrayToMap(modifiedFiles, mymap, SvnFileExplorerTraverser::Modified, rootDir);
DoAddArrayToMap(newFiles, mymap, SvnFileExplorerTraverser::New, rootDir);
DoAddArrayToMap(deletedFiles, mymap, SvnFileExplorerTraverser::Deleted, rootDir);
DoAddArrayToMap(conflictedFiles, mymap, SvnFileExplorerTraverser::Conflicted, rootDir);
DoAddArrayToMap(lockedFiles, mymap, SvnFileExplorerTraverser::Locked, rootDir);
DoAddArrayToMap(unversionedFiles, mymap, SvnFileExplorerTraverser::Unversioned, rootDir);
DoAddArrayToMap(ignoreFiles, mymap, SvnFileExplorerTraverser::Ignored, rootDir);
if (feRootItem.IsOk()) {
CL_DEBUG(wxT("wxTreeTraverser started..."));
SvnFileExplorerTraverser traverser(fileExplorer, mymap, m_fileExplorerLastBaseImgIdx, DoGetCurRepoPath());
traverser.Traverse(feRootItem);
CL_DEBUG(wxT("wxTreeTraverser started...end"));
}
}
#endif
}
void SubversionView::DoAddNode(const wxString& title,
int imgId,
SvnTreeData::SvnNodeType nodeType,
const wxArrayString& files)
{
wxTreeItemId root = m_treeCtrl->GetRootItem();
wxString basePath = DoGetCurRepoPath();
// Add the basic four root items
if(files.IsEmpty() == false) {
wxTreeItemId parent = m_treeCtrl->AppendItem(root, title, imgId, imgId, new SvnTreeData(nodeType, wxT("")));
// Set the parent node with bold font
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
font.SetWeight(wxFONTWEIGHT_BOLD);
m_treeCtrl->SetItemFont(parent, font);
// Add all children items
for(size_t i = 0; i < files.GetCount(); i++) {
wxFileName filename(files.Item(i));
wxTreeItemId folderParent = DoGetParentNode(files.Item(i), parent);
m_treeCtrl->AppendItem(folderParent,
filename.GetFullName(),
DoGetIconIndex(filename.GetFullName()),
DoGetIconIndex(filename.GetFullName()),
new SvnTreeData(SvnTreeData::SvnNodeTypeFile, files.Item(i)));
}
if(nodeType != SvnTreeData::SvnNodeTypeUnversionedRoot) {
m_treeCtrl->Expand(parent);
// Expand the top level children as well
wxTreeItemIdValue cookie;
wxTreeItemId child = m_treeCtrl->GetFirstChild(parent, cookie);
while(child.IsOk()) {
if(m_treeCtrl->ItemHasChildren(child)) {
m_treeCtrl->Expand(child);
}
child = m_treeCtrl->GetNextChild(parent, cookie);
}
}
}
}
int SubversionView::DoGetIconIndex(const wxString& filename)
{
FileExtManager::Init();
int iconIndex = m_plugin->GetManager()->GetStdIcons()->GetMimeImageId(filename);
if(iconIndex == wxNOT_FOUND)
iconIndex =
m_plugin->GetManager()->GetStdIcons()->GetMimeImageId(wxT("file.txt")); // text file icon is the default
return iconIndex;
}
SvnTreeData::SvnNodeType SubversionView::DoGetSelectionType(const wxArrayTreeItemIds& items)
{
m_selectionInfo.Clear();
SvnTreeData::SvnNodeType type(SvnTreeData::SvnNodeTypeInvalid);
for(size_t i = 0; i < items.GetCount(); i++) {
if(items.Item(i).IsOk() == false) {
m_selectionInfo.Clear();
return m_selectionInfo.m_selectionType; // Invalid
}
SvnTreeData* data = (SvnTreeData*)m_treeCtrl->GetItemData(items.Item(i));
if(!data) {
m_selectionInfo.Clear();
return m_selectionInfo.m_selectionType; // Invalid
}
if(data->GetType() == SvnTreeData::SvnNodeTypeRoot && items.GetCount() == 1) {
// populate the list of paths with all the added paths
DoGetPaths(items.Item(i), m_selectionInfo.m_paths);
m_selectionInfo.m_selectionType = SvnTreeData::SvnNodeTypeRoot;
return m_selectionInfo.m_selectionType;
}
if(data->GetType() == SvnTreeData::SvnNodeTypeAddedRoot && items.GetCount() == 1) {
// populate the list of paths with all the added paths
DoGetPaths(items.Item(i), m_selectionInfo.m_paths);
m_selectionInfo.m_selectionType = SvnTreeData::SvnNodeTypeAddedRoot;
return m_selectionInfo.m_selectionType;
}
if(data->GetType() == SvnTreeData::SvnNodeTypeDeletedRoot && items.GetCount() == 1) {
// populate the list of paths with all the deleted paths
DoGetPaths(items.Item(i), m_selectionInfo.m_paths);
m_selectionInfo.m_selectionType = SvnTreeData::SvnNodeTypeDeletedRoot;
return m_selectionInfo.m_selectionType;
}
if(data->GetType() == SvnTreeData::SvnNodeTypeConflictRoot && items.GetCount() == 1) {
// populate the list of paths with all the conflicted paths
DoGetPaths(items.Item(i), m_selectionInfo.m_paths);
m_selectionInfo.m_selectionType = SvnTreeData::SvnNodeTypeConflictRoot;
return m_selectionInfo.m_selectionType;
}
if(data->GetType() == SvnTreeData::SvnNodeTypeModifiedRoot && items.GetCount() == 1) {
// populate the list of paths with all the conflicted paths
DoGetPaths(items.Item(i), m_selectionInfo.m_paths);
m_selectionInfo.m_selectionType = SvnTreeData::SvnNodeTypeModifiedRoot;
return m_selectionInfo.m_selectionType;
}
if(data->GetType() == SvnTreeData::SvnNodeTypeFolder && items.GetCount() == 1) {
// populate the list of paths with all the conflicted paths
DoGetPaths(items.Item(i), m_selectionInfo.m_paths);
m_selectionInfo.m_selectionType = SvnTreeData::SvnNodeTypeFolder;
return m_selectionInfo.m_selectionType;
}
if(type == SvnTreeData::SvnNodeTypeInvalid &&
(data->GetType() == SvnTreeData::SvnNodeTypeFile || data->GetType() == SvnTreeData::SvnNodeTypeRoot)) {
type = data->GetType();
m_selectionInfo.m_selectionType = type;
m_selectionInfo.m_paths.Add(data->GetFilepath());
} else if(type == SvnTreeData::SvnNodeTypeInvalid) {
type = data->GetType();
} else if(data->GetType() != type) {
m_selectionInfo.m_paths.Clear();
return SvnTreeData::SvnNodeTypeInvalid;
} else {
// Same type, just add the path
m_selectionInfo.m_paths.Add(data->GetFilepath());
}
}
return type;
}
void SubversionView::CreateSecondRootMenu(wxMenu* menu)
{
menu->Append(XRCID("svn_commit"), wxT("Commit"));
menu->Append(XRCID("svn_update"), wxT("Update"));
menu->AppendSeparator();
menu->Append(XRCID("svn_revert"), wxT("Revert"));
menu->Append(XRCID("svn_add"), wxT("Add"));
menu->AppendSeparator();
menu->Append(XRCID("svn_diff"), _("Create Diff..."));
}
void SubversionView::CreateFileMenu(wxMenu* menu)
{
menu->Append(XRCID("svn_open_file"), _("Open File..."));
menu->AppendSeparator();
menu->Append(XRCID("svn_commit"), wxT("Commit"));
menu->Append(XRCID("svn_update"), wxT("Update"));
menu->AppendSeparator();
menu->Append(XRCID("svn_revert"), wxT("Revert"));
menu->AppendSeparator();
menu->Append(XRCID("svn_lock"), wxT("Lock"));
menu->Append(XRCID("svn_unlock"), wxT("Unlock"));
menu->AppendSeparator();
menu->Append(XRCID("svn_add"), wxT("Add"));
menu->Append(XRCID("svn_delete"), wxT("Delete"));
menu->Append(XRCID("svn_rename"), wxT("Rename"));
menu->AppendSeparator();
menu->Append(XRCID("svn_resolve"), wxT("Resolve"));
menu->AppendSeparator();
menu->Append(XRCID("svn_diff"), _("Create Diff..."));
menu->AppendSeparator();
menu->Append(XRCID("svn_blame"), _("Blame..."));
menu->AppendSeparator();
wxMenu* subMenu;
subMenu = new wxMenu;
subMenu->Append(XRCID("svn_ignore_file"), _("Ignore this file"));
subMenu->Append(XRCID("svn_ignore_file_pattern"), _("Ignore this file pattern"));
menu->Append(wxID_ANY, wxT("Ignore"), subMenu);
}
void SubversionView::CreateRootMenu(wxMenu* menu)
{
menu->Append(XRCID("svn_commit"), wxT("Commit"));
menu->Append(XRCID("svn_update"), wxT("Update"));
menu->AppendSeparator();
menu->Append(XRCID("svn_revert"), wxT("Revert"));
menu->AppendSeparator();
menu->Append(XRCID("svn_tag"), _("Create Tag"));
menu->Append(XRCID("svn_branch"), _("Create Branch"));
menu->AppendSeparator();
menu->Append(XRCID("svn_switch"), _("Switch URL..."));
menu->AppendSeparator();
menu->Append(XRCID("svn_diff"), _("Create Diff..."));
menu->Append(XRCID("svn_patch"), _("Apply Patch..."));
menu->Append(XRCID("svn_patch_dry_run"), _("Apply Patch - Dry Run..."));
menu->AppendSeparator();
menu->Append(XRCID("svn_log"), _("Change Log..."));
menu->AppendSeparator();
menu->Append(XRCID("svn_properties"), _("Properties..."));
}
void SubversionView::DoGetPaths(const wxTreeItemId& parent, wxArrayString& paths)
{
if(m_treeCtrl->ItemHasChildren(parent) == false) {
return;
}
wxTreeItemIdValue cookie;
wxTreeItemId item = m_treeCtrl->GetFirstChild(parent, cookie);
while(item.IsOk()) {
SvnTreeData* data = (SvnTreeData*)m_treeCtrl->GetItemData(item);
if(data) {
if(data->GetFilepath().IsEmpty() == false && data->GetType() == SvnTreeData::SvnNodeTypeFile) {
paths.Add(data->GetFilepath());
}
if((data->GetType() == SvnTreeData::SvnNodeTypeAddedRoot ||
data->GetType() == SvnTreeData::SvnNodeTypeModifiedRoot ||
data->GetType() == SvnTreeData::SvnNodeTypeDeletedRoot ||
data->GetType() == SvnTreeData::SvnNodeTypeFolder) &&
m_treeCtrl->ItemHasChildren(item)) {
DoGetPaths(item, paths);
}
}
item = m_treeCtrl->GetNextChild(parent, cookie);
}
}
////////////////////////////////////////////
// Source control command handlers
////////////////////////////////////////////
void SubversionView::OnUpdate(wxCommandEvent& event)
{
wxString command;
wxString loginString;
if(m_plugin->LoginIfNeeded(event, DoGetCurRepoPath(), loginString) == false) {
return;
}
bool nonInteractive = m_plugin->GetNonInteractiveMode(event);
command << m_plugin->GetSvnExeName(nonInteractive) << loginString << wxT(" update ");
m_plugin->AddCommandLineOption(command, Subversion2::kOpt_ForceInteractive);
if(m_selectionInfo.m_selectionType != SvnTreeData::SvnNodeTypeRoot) {
// Concatenate list of files to be updated
for(size_t i = 0; i < m_selectionInfo.m_paths.GetCount(); i++) {
command << wxT("\"") << m_selectionInfo.m_paths.Item(i) << wxT("\" ");
}
}
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnUpdateHandler(m_plugin, event.GetId(), this), true, true);
}
void SubversionView::OnCommit(wxCommandEvent& event)
{
m_plugin->DoCommit(m_selectionInfo.m_paths, DoGetCurRepoPath(), event);
}
void SubversionView::OnAdd(wxCommandEvent& event)
{
wxString command;
wxString loginString;
if(m_plugin->LoginIfNeeded(event, DoGetCurRepoPath(), loginString) == false) {
return;
}
command << m_plugin->GetSvnExeName(false) << loginString << wxT(" add ");
// Concatenate list of files to be updated
for(size_t i = 0; i < m_selectionInfo.m_paths.GetCount(); i++) {
command << wxT("\"") << m_selectionInfo.m_paths.Item(i) << wxT("\" ");
}
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, event.GetId(), this));
}
void SubversionView::OnRevert(wxCommandEvent& event)
{
wxString command;
// Svn revert does not require login string
command << m_plugin->GetSvnExeName(false) << wxT(" revert --recursive ");
if(m_selectionInfo.m_selectionType != SvnTreeData::SvnNodeTypeRoot) {
// Concatenate list of files to be updated
for(size_t i = 0; i < m_selectionInfo.m_paths.GetCount(); i++) {
command << wxT("\"") << m_selectionInfo.m_paths.Item(i) << wxT("\" ");
}
} else {
command << wxT(".");
}
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, event.GetId(), this));
}
void SubversionView::OnBranch(wxCommandEvent& event)
{
wxString command;
command << m_plugin->GetSvnExeName() << wxT("info --xml ");
SvnInfo svnInfo;
m_plugin->DoGetSvnInfoSync(svnInfo, DoGetCurRepoPath());
command.Clear();
wxString loginString;
if(m_plugin->LoginIfNeeded(event, DoGetCurRepoPath(), loginString) == false) {
return;
}
// Prompt user for URLs + comment
SvnCopyDialog dlg(m_plugin->GetManager()->GetTheApp()->GetTopWindow());
dlg.SetTitle(_("Create Branch"));
dlg.SetSourceURL(svnInfo.m_sourceUrl);
dlg.SetTargetURL(svnInfo.m_sourceUrl);
if(dlg.ShowModal() == wxID_OK) {
command.Clear();
// Prepare the 'copy' command
bool nonInteractive = m_plugin->GetNonInteractiveMode(event);
command << m_plugin->GetSvnExeName(nonInteractive) << loginString << wxT(" copy ") << dlg.GetSourceURL()
<< wxT(" ") << dlg.GetTargetURL() << wxT(" -m \"") << dlg.GetMessage() << wxT("\"");
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, event.GetId(), this));
}
}
void SubversionView::OnTag(wxCommandEvent& event)
{
wxString command;
command << m_plugin->GetSvnExeName() << wxT("info --xml ");
SvnInfo svnInfo;
m_plugin->DoGetSvnInfoSync(svnInfo, DoGetCurRepoPath());
// Prompt the login dialog now
command.Clear();
wxString loginString;
if(m_plugin->LoginIfNeeded(event, DoGetCurRepoPath(), loginString) == false) {
return;
}
// Prompt user for URLs + comment
SvnCopyDialog dlg(m_plugin->GetManager()->GetTheApp()->GetTopWindow());
dlg.SetTitle(_("Create Tag"));
dlg.SetSourceURL(svnInfo.m_sourceUrl);
dlg.SetTargetURL(svnInfo.m_sourceUrl);
if(dlg.ShowModal() == wxID_OK) {
// Prepare the 'copy' command
bool nonInteractive = m_plugin->GetNonInteractiveMode(event);
command.Clear();
command << m_plugin->GetSvnExeName(nonInteractive) << loginString << wxT(" copy ") << dlg.GetSourceURL()
<< wxT(" ") << dlg.GetTargetURL() << wxT(" -m \"") << dlg.GetMessage() << wxT("\"");
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, event.GetId(), this));
}
}
void SubversionView::OnDelete(wxCommandEvent& event)
{
wxString command;
wxString loginString;
if(m_plugin->LoginIfNeeded(event, DoGetCurRepoPath(), loginString) == false) {
return;
}
bool nonInteractive = m_plugin->GetNonInteractiveMode(event);
command << m_plugin->GetSvnExeName(nonInteractive) << loginString << wxT(" --force delete ");
// Concatenate list of files to be updated
for(size_t i = 0; i < m_selectionInfo.m_paths.GetCount(); i++) {
command << wxT("\"") << m_selectionInfo.m_paths.Item(i) << wxT("\" ");
}
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, event.GetId(), this));
}
void SubversionView::OnResolve(wxCommandEvent& event)
{
wxString command;
wxString loginString;
if(m_plugin->LoginIfNeeded(event, DoGetCurRepoPath(), loginString) == false) {
return;
}
command << m_plugin->GetSvnExeName(false) << loginString << wxT(" resolved ");
// Concatenate list of files to be updated
for(size_t i = 0; i < m_selectionInfo.m_paths.GetCount(); i++) {
command << wxT("\"") << m_selectionInfo.m_paths.Item(i) << wxT("\" ");
}
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, event.GetId(), this));
}
void SubversionView::OnDiff(wxCommandEvent& event)
{
wxString loginString;
if(m_plugin->LoginIfNeeded(event, DoGetCurRepoPath(), loginString) == false) {
return;
}
bool nonInteractive = m_plugin->GetNonInteractiveMode(event);
DiffDialog dlg(this, m_plugin->GetManager());
if(dlg.ShowModal() == wxID_OK) {
wxString from = dlg.GetFromRevision();
wxString to = dlg.GetToRevision();
if(to.IsEmpty() == false) {
to.Prepend(wxT(":"));
}
// Simple diff
wxString diff_cmd;
diff_cmd << m_plugin->GetSvnExeNameNoConfigDir(nonInteractive) << loginString;
SvnSettingsData ssd = m_plugin->GetSettings();
if(ssd.GetFlags() & SvnUseExternalDiff) {
diff_cmd << " --diff-cmd=\"" << ssd.GetExternalDiffViewer() << "\" ";
}
diff_cmd << " diff ";
if(dlg.IgnoreWhitespaces() && !(ssd.GetFlags() & SvnUseExternalDiff)) {
diff_cmd << " -x -w ";
}
diff_cmd << " -r " << from << to << " ";
for(size_t i = 0; i < m_selectionInfo.m_paths.GetCount(); i++) {
diff_cmd << wxT("\"") << m_selectionInfo.m_paths.Item(i) << wxT("\" ");
}
m_plugin->GetConsole()->Execute(
diff_cmd, DoGetCurRepoPath(), new SvnDiffHandler(m_plugin, event.GetId(), this), false);
}
}
void SubversionView::OnPatch(wxCommandEvent& event) { m_plugin->Patch(false, DoGetCurRepoPath(), this, event.GetId()); }
void SubversionView::OnPatchDryRun(wxCommandEvent& event)
{
m_plugin->Patch(true, DoGetCurRepoPath(), this, event.GetId());
}
void SubversionView::OnCleanup(wxCommandEvent& event)
{
wxUnusedVar(event);
wxString command;
command << m_plugin->GetSvnExeName(false) << wxT(" cleanup ");
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, wxNOT_FOUND, NULL));
}
void SubversionView::OnStop(wxCommandEvent& event)
{
wxUnusedVar(event);
m_plugin->GetConsole()->Stop();
}
void SubversionView::OnClearOuptut(wxCommandEvent& event)
{
wxUnusedVar(event);
m_plugin->GetConsole()->Clear();
}
void SubversionView::OnRefreshView(wxCommandEvent& event)
{
event.Skip();
BuildTree();
}
void SubversionView::OnFileAdded(clCommandEvent& event)
{
event.Skip();
typedef std::map<wxString, bool> StringBoolMap_t;
StringBoolMap_t path_in_svn;
// svn is setup ?
int flags = event.GetInt();
if(flags & kEventImportingFolder) return;
SvnSettingsData ssd = m_plugin->GetSettings();
if(ssd.GetFlags() & SvnAddFileToSvn) {
const wxArrayString& files = event.GetStrings();
bool addToSvn(false);
wxString command;
command << m_plugin->GetSvnExeName() << wxT(" add ");
for(size_t i = 0; i < files.GetCount(); i++) {
wxString currentFilePath = files.Item(i).BeforeLast(wxFILE_SEP_PATH);
bool curPathUnderSvn = false;
if(path_in_svn.count(currentFilePath)) {
// use the cached result
curPathUnderSvn = path_in_svn.find(currentFilePath)->second;
} else {
// query svn and cache the result for future use
curPathUnderSvn = m_plugin->IsPathUnderSvn(currentFilePath);
path_in_svn.insert(std::make_pair(currentFilePath, curPathUnderSvn));
}
if(curPathUnderSvn) {
command << wxT("\"") << files.Item(i) << wxT("\" ");
addToSvn = true;
}
}
if(addToSvn) {
command.RemoveLast();
m_plugin->GetConsole()->Execute(
command, DoGetCurRepoPath(), new SvnDefaultCommandHandler(m_plugin, event.GetId(), this));
}
}
}
void SubversionView::OnFileRenamed(wxCommandEvent& event)
{
wxArrayString* files = (wxArrayString*)event.GetClientData();
// If the Svn Client Version is set to 0.0 it means that we dont have SVN client installed
if(m_plugin->GetSvnClientVersion() && files && (m_plugin->GetSettings().GetFlags() & SvnRenameFileInRepo)) {
wxString oldName = files->Item(0);
wxString newName = files->Item(1);