forked from Minebea-Intec/zbssvn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzbssvn.lua
1673 lines (1422 loc) · 48.6 KB
/
zbssvn.lua
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
local SVN_PLUGIN =
{
name = "SVN plugin",
description = "Plugin to use svn functionality out of zbs",
author = "Klemens Mentel, J.Jørgen von Bargen",
}
--------------------------------------------------
-- common shortcuts
--------------------------------------------------
local sprintf=string.format
local push=table.insert
local join=table.concat
--
-- helper mt to autocreate entries in table
--
local mt_autocreate={}
mt_autocreate.__index=function(t,k) local v=setmetatable({},mt_autocreate) rawset(t,k,v) return v end
--------------------------------------------------
-- common utility/debug functions
--------------------------------------------------
local function gettime()
return wx.wxGetLocalTimeMillis():ToDouble()*0.001
end
local DIRSEP=package.config:sub(1,1)
local function quoteunix(path)
return "'"..path:gsub("'","'\\''").."'"
end
local function quotedos(path)
return '"'..path:gsub('"','""')..'"'
end
local quotepath=({['\\']=quotedos,['/']=quoteunix})[DIRSEP] or error("no quote function for DIRSEP='"..DIRSEP.."'")
local echostatus=({['\\']="&& echo %ERRORLEVEL%",['/']="; echo $?"})[DIRSEP] or error("no echostatus for DIRSEP='"..DIRSEP.."'")
local function quoteshell(value)
if type(value)=="table" then
local q={}
for k,v in ipairs(value) do
q[k]=quotepath(v)
end
return join(q,' ')
end
return quotepath(value)
end
local function d2u(path)
return path:gsub("\\",DIRSEP):gsub("[\\/]$","")
end
local function add(t,k)
if rawget(t,k) then return end
push(t,k) t[k]=#t
end
-----------------------------------------------------
-- read config values
-----------------------------------------------------
local config_svn=ide.config.svn or {}
local verbose=config_svn.verbose or 0 -- 0 only errors
local savetemp=config_svn.savetemp or false
local path_to_diff_tool = config_svn.diff -- or 'meld'
local TEMP=d2u(config_svn.tmp or os.getenv("TEMP") or os.getenv("TMP") or "/tmp")
-----------------------------------------------------
-- load submodules without clobbering global packages
-- cannot use require else ZBS will get confused
-----------------------------------------------------
local source=debug.getinfo(1,"S").source:gsub("^@","")
-- {
-- linedefined=0,
-- lastlinedefined=1088,
-- source="@/home/user/.zbstudio/packages/SVN/svn.lua",
-- what="main",
-- short_src="/home/user/.zbstudio/packages/SVN/svn.lua"
-- }
local sourcedir=source:gsub("\\","/"):gsub("(.*)/.*","%1"):gsub("^~",os.getenv("HOME") or ".")
io.write(">"..sourcedir.."<\n")io.flush()
local svnxml=dofile(sourcedir.."/svnxml.lua")
local utils=dofile(sourcedir.."/utils.lua")
local zbs_svn_plugin_id = ID("svn.zbs_svn_plugin")
-- configuration
-- SET in user.lua to path.diff = [[C:\\Program Files\\ExamDiff Pro\\ExamDiff.exe]]
--path_to_diff_tool='"C:\\Program Files\\TortoiseSVN\\bin\\TortoiseUDiff.exe"'
-- consts..
-- calculate unique IDs
local ID_REFRESH = ID("svn.action.refresh")
local ID_UPDATE = ID("svn.action.update")
local ID_COMMIT = ID("svn.action.commit")
local ID_REVERT = ID("svn.action.revert")
local ID_ADD = ID("svn.action.add")
local ID_DELETE = ID("svn.action.delete")
local ID_RESOLVE = ID("svn.action.resolve")
local ID_DIFF = ID("svn.action.diff")
local ID_BLAME = ID("svn.action.blame")
local ID_IGNORE = ID("svn.action.ignore")
local ID_UNIGNORE= ID("svn.action.unignore")
local ID_CHECKLISTBOX = ID("svn.checklistbox")
local ID_COMBOBOX = ID("svn.combobox")
local ID_TEXTCTRL = ID("svn.textctrl")
local ID_DIFFCTRL = ID("svn.diffctrl")
local ID_LISTCONTROL=ID("svn.listctrl")
local TMP=os.getenv("TEMP")or os.getenv("TMP") or "/tmp"
--============================================================
-- utility functions for debug, functional not needed
--============================================================
local vis=utils.vis
local QW=utils.QW
local vist=utils.vist
local spairs=utils.spairs
local printf=utils.printf
local save_file=utils.save_file
printf("DIRSEP=%q\n",DIRSEP)
--
-- prepare for internal diff view
--
local fontCourier=wx.wxFont(9,wx.wxFONTFAMILY_MODERN,wx.wxFONTSTYLE_NORMAL,wx.wxFONTWEIGHT_NORMAL,
false,"Courier New",wx.wxFONTENCODING_DEFAULT)
wx.wxDARK_GREEN=wx.wxColour(0,128,0);
wx.wxDARK_RED=wx.wxColour(128,0,0);
function SVN_PLUGIN:popen_command(cmd)
local fd=assert(io.popen(cmd.." 2>&1 "..echostatus))
local output=fd:read("*all")
fd:close()
local sts
output=output:gsub("%s*%d+%s*$",function(n) sts=tonumber(n) return ""end)
return output,sts
end
------------------------------------------------------------
-- the OneAndOnly command execute to capture output
------------------------------------------------------------
function SVN_PLUGIN:do_command(cmd,showoutput)
self.SetStatus("Execute %.80s",cmd)
if verbose>=1 then
printf("SVN_PLUGIN:execute[[%s]]\n",cmd)
end
local t0=gettime()
wx.wxBeginBusyCursor()
local output,sts=self:popen_command(cmd)
wx.wxEndBusyCursor()
local t1=gettime()
if showoutput then
if output~="" then DisplayOutputLn(output) end
end
if sts~=0 then
local msg=sprintf("Execution of\n%s\nfailed!\nStatus=%s\nOutput=%s",cmd,vis(sts),vis(output))
wx.wxMessageBox(msg,"Subversion",wx.wxOK+wx.wxCANCEL+wx.wxICON_ERROR)
end
if verbose>=1 then
printf("SVN_PLUGIN:sts=%s in %.3f sec\n",vis(sts),t1-t0)
printf("SVN_PLUGIN:output=%s\n",vis(output,80))
end
self.SetStatus("Did %.80s",cmd)
return output,sts
end
function SVN_PLUGIN:svn_set_ignore(files,remove)
local function QL(text)
local lines={}
for line in text:gmatch("[^\r\n]+") do
lines[line]=true
end
return lines
end
local function keys(t)
local ks={}
for k in pairs(t) do ks[#ks+1]=k end
return ks
end
--------------------------------------------------
-- process arguments
--------------------------------------------------
local PROPERTIES={}
local changed={}
for a,arg in ipairs(files) do
arg=arg:gsub("/$","")
local path,name=arg:match("^(.*)/([^/]+)$")
if not path then path,name=".",arg end
local properties=PROPERTIES[path]
if properties==nil then
local cmd=sprintf("svn propget svn:ignore %s 2>/dev/null",quoteshell(path))
local fd=assert(io.popen(cmd,"r"))
local output=fd:read("*all")
fd:close()
properties=QL(output)
PROPERTIES[path]=properties
end
if remove then
if properties[name] then
properties[name]=nil
changed[path]=properties
end
else
if not properties[name] then
properties[name]=true
changed[path]=properties
end
end
end
utils.ShowData("PROPERTIES",PROPERTIES)
utils.ShowData("changed",changed)
--------------------------------------------------
-- flush changes/new properties
--------------------------------------------------
for dir,properties in pairs(changed) do
printf("properties for '%s' changed\n",dir)
properties=keys(properties)
table.sort(properties)
if #properties>0 then
properties=join(properties,"\n").."\n"
io.write(properties)
local ppath=TEMP.."/properties.txt"
save_file(ppath,properties)
local cmd=sprintf("svn propset svn:ignore -F %s %s",ppath,quoteshell(dir))
local output,sts=self:do_command(cmd)
if sts~=0 then
SVN_PLUGIN:SetStatus("failed %s",cmd)
return nil
end
else
local cmd=sprintf("svn propdel svn:ignore %s",quoteshell(dir))
local output,sts=self:do_command(cmd)
if sts~=0 then
SVN_PLUGIN:SetStatus("failed %s",cmd)
return nil
end
end
end
end
function SVN_PLUGIN:get_svn_xml(action,args)
local cmd="svn "..action.." "..args
SVN_PLUGIN:SetStatus("execute %s",cmd)
local output,sts=self:do_command(cmd)
if sts~=0 then
SVN_PLUGIN:SetStatus("failed %s",cmd)
return nil
end
if savetemp then
save_file(TEMP.."/svn-"..action..".xml",output)
end
SVN_PLUGIN:SetStatus("parse %s",cmd)
local xml=svnxml.parsestr(output) or Error("no xml in \n",action)
if xml:tag()~=action then
Error("expected <%s> have <%s>\n",action,xml:tag())
end
SVN_PLUGIN:SetStatus("svn "..action.." done")
return xml
end
function SVN_PLUGIN:GetSvnLog()
local comments=self.SvnLogComments
if comments==nil then
wx.wxBeginBusyCursor()
local svnlog=self:get_svn_xml("log","--xml --limit 20 "..quoteshell(self.WorkingDir))
wx.wxEndBusyCursor()
comments={}
for logentry in svnlog:elements() do
local msg=(logentry:element"msg":cdata() or ""):gsub("%s+$","")
if msg~="" then
push(comments,msg)
end
end
self.SvnLogComments=comments
end
return comments
end
function SVN_PLUGIN:FixPath(filename)
local fn=wx.wxFileName(filename)
fn:Normalize(wx.wxPATH_NORM_ALL,self.WorkingDir)
return fn:GetFullPath()
end
--============================================================
-- Status data
-- name = name of status in xml (== name of status png)
-- allowed = list of allowed actions on this status
-- show = initial state of show control
--============================================================
local SVN_STATUS=
{
{name="normal", allowed=QW"update delete blame",show=false},
{name="modified", allowed=QW"update commit revert diff blame"},
{name="conflicted", allowed=QW"update revert resolve diff blame"},
{name="added", allowed=QW"commit revert diff"},
{name="deleted", allowed=QW"commit revert"},
{name="incomplete", allowed=QW"update"},
{name="unversioned",allowed=QW"add delete ignore"},
{name="obstructed", },
{name="missing", allowed=QW"update delete"},
{name="none", },
{name="external", allowed=QW"update" ,show=false },
{name="ignored", allowed=QW"delete unignore" ,show=false },
}
-- make the hash tables by name
for i,s in ipairs(SVN_STATUS) do SVN_STATUS[s.name]=s end
local SVN_ACTION=
{
{name="refresh",enable=true}, -- this is always enabled
{name="update",enable=true}, -- this is always enabled
{name="info",enable=true}, -- this is always enabled
{}, -- separator
{name="commit"},
{name="revert"},
{name="resolve"},
{}, -- separator
{name="add"},
{name="delete"},
{name="ignore"},
{name="unignore"},
{}, -- separator
{name="diff"},
{name="blame"},
}
for i,action in ipairs(SVN_ACTION) do if action.name then SVN_ACTION[action.name]=action end end
--============================================================
-- image handling
--============================================================
local function is_file(file)
if wx.wxFileName(file):FileExists() then return file end
end
--
-- Get possible icon from .zbstudio/packages/SVN/PNGs
--
local imgSize = wx.wxSize(16,16)
local function my_getBitmap(name)
--printf("my_getBitmap(%s)\n",name)
local png_file=is_file(sourcedir:gsub("\\","/").."/PNGs/"..name..".png")
if png_file then
-- DisplayOutputLn("PNG_FILE=",png_file)
return wx.wxBitmap(png_file)
end
printf("svn: no .png for %q\n",name)
return wx.wxArtProvider.GetBitmap(name,"OTHER",imgSize)
end
local function CreateImageList(prefix)
--
-- create the image list
--
local img_w,img_h=imgSize:GetWidth(),imgSize:GetHeight()
--DisplayOutputLn("img_w=",img_w,"img_h=",img_h)
local imageList = wx.wxImageList(img_w,img_h);
for i,data in ipairs(SVN_STATUS) do
local bmp=my_getBitmap(prefix.."-"..data.name)
data.bmpId=imageList:Add(bmp) -- 1 = add
bmp:delete()
end
return imageList
end
function SVN_PLUGIN:SetStatus(...)
ide:SetStatus(sprintf(...))
end
function SVN_PLUGIN:CreateMenuFor(enables)
local menu = wx.wxMenu {
--{ ID_REFRESH,TR("Refresh") },
{ ID_UPDATE,TR("Update") },
{ },-- separator
{ ID_COMMIT,TR("Commit") },
{ ID_REVERT,TR("Revert") },
{ },-- separator
{ ID_RESOLVE,TR("Resolve") },
{ },-- separator
{ ID_ADD,TR("Add") },
{ ID_DELETE,TR("Delete") },
{ ID_IGNORE,TR("Ignore") },
{ ID_UNIGNORE,TR("Unignore") },
{ },-- separator
{ ID_DIFF,TR("SVN Diff") },
{ ID_BLAME,TR("SVN Blame") },
}
-- enable menu entry according to svn state
menu:Enable(ID_COMMIT,enables.commit ==true)
menu:Enable(ID_REVERT,enables.revert ==true)
menu:Enable(ID_RESOLVE,enables.resolve==true)
menu:Enable(ID_ADD,enables.add ==true)
menu:Enable(ID_DELETE,enables.delete ==true)
menu:Enable(ID_DIFF,enables.diff ==true)
menu:Enable(ID_IGNORE,enables.ignore ==true)
menu:Enable(ID_UNIGNORE,enables.unignore ==true)
menu:Enable(ID_BLAME,enables.blame ==true)
return menu
end
--
-- render output of diff to a text control
--
local function DiffOutputToTextCtrl(ctrl,output)
ctrl:Clear()
local block,have_color
for line in output:gmatch("[^\r\n]+") do
local want_color=wx.wxBLACK
if line:match("^%+") then
want_color=wx.wxDARK_GREEN
elseif line:match("^%-") then
want_color=wx.wxDARK_RED
end
if have_color~=want_color then
if block then
ctrl:AppendText(block)
block=nil
end
ctrl:SetDefaultStyle(wx.wxTextAttr(want_color))
have_color=want_color
end
block=(block or "")..line.."\n"
end
if block then
ctrl:AppendText(block)
end
end
function SVN_PLUGIN:CreateDialog(Caption,action,FileList,comment_needed,diffallowed)
printf("SVN_PLUGIN:CreateDialog(%s,%s,%s,%s,%s)\n",vis(Caption),vis(action),vist(FileList),vis(comment_needed),vis(diffallowed))
if type(FileList)=="string" then FileList={FileList}end
if #FileList==0 then return end
local frame = self.parent
--
-- the dialog with a sizer
--
local dialog = wx.wxDialog(frame,wx.wxID_ANY,Caption,
wx.wxDefaultPosition,wx.wxDefaultSize,
wx.wxDEFAULT_DIALOG_STYLE+wx.wxRESIZE_BORDER)
local mainSizer = wx.wxBoxSizer(wx.wxVERTICAL)
--
-- the text input area
--
local textCtrl,comboBox
if comment_needed then -- some actions do not need a comment e.g. resolve/revert
textCtrl = wx.wxTextCtrl(dialog,ID_TEXTCTRL,"-please-enter-comment-",
wx.wxDefaultPosition,wx.wxSize(600,120),
wx.wxTE_MULTILINE+wx.wxTE_DONTWRAP)
local comboContent = SVN_PLUGIN:GetSvnLog()
comboBox = wx.wxComboBox(dialog,ID_COMBOBOX,TR("Select last recent comment"),
wx.wxDefaultPosition,wx.wxDefaultSize,
comboContent,
wx.wxTE_PROCESS_ENTER)
mainSizer:Add(textCtrl,0,wx.wxEXPAND+wx.wxALL,5)
mainSizer:Add(comboBox,0,wx.wxEXPAND+wx.wxALL,5)
end
--
-- the checklist box
--
local base=0
if #FileList>1 then
table.insert(FileList,1,"*ALL*")
base=1
end
local checkListBox=wx.wxCheckListBox(dialog,ID_CHECKLISTBOX,wx.wxDefaultPosition,wx.wxDefaultSize,FileList)
for i=0,#FileList-1 do
checkListBox:Check(i,true)
end
mainSizer:Add(checkListBox,0,wx.wxEXPAND+wx.wxALL,5)
--
-- the diff control
--
local diffCtrl=nil
if diffallowed then
diffCtrl=wx.wxTextCtrl(dialog,ID_DIFFCTRL,"...DIFF...",
wx.wxDefaultPosition,wx.wxSize(800,600),
wx.wxTE_MULTILINE+wx.wxTE_DONTWRAP+wx.wxTE_RICH+wx.wxTE_READONLY)
diffCtrl:SetFont(fontCourier)
mainSizer:Add(diffCtrl,1,wx.wxEXPAND+wx.wxALL,5)
end
local buttonSizer = wx.wxBoxSizer( wx.wxHORIZONTAL )
local okButton = wx.wxButton(dialog,wx.wxID_OK,"Ok") -- NEED this for validators to work
okButton:Enable(false)
okButton:SetDefault()
local cancelButton = wx.wxButton(dialog,wx.wxID_CANCEL,"Cancel")
buttonSizer:Add( okButton,0,wx.wxALIGN_CENTER+wx.wxALL,5 )
buttonSizer:Add( cancelButton,0,wx.wxALIGN_CENTER+wx.wxALL,5 )
mainSizer:Add( buttonSizer,0,wx.wxALIGN_CENTER+wx.wxALL,5 )
dialog:SetSizer(mainSizer)
mainSizer:SetSizeHints(dialog)
local function HandleComboBoxSelected(event)
textCtrl:ChangeValue(event:GetString()) -- set comment according to selected combo box item
end
local function HandleCheckBoxSelected(event)
local check_box_text = event:GetString()
if check_box_text=="*ALL*" then
local on=checkListBox:IsChecked(0)
for i=base,#FileList-1 do
checkListBox:Check(i,on)
end
elseif diffCtrl then
local cmd=sprintf("svn diff \"%s\"",self:FixPath(check_box_text))
local output,sts=self:do_command(cmd)
DiffOutputToTextCtrl(diffCtrl,output)
end
local anyChecked=false;
for i=base,#FileList-1 do
if checkListBox:IsChecked(i) then
anyChecked=true
break
end
end
okButton:Enable(anyChecked)
end
-- connect selection of combo box to function
dialog:Connect(ID_COMBOBOX,wx.wxEVT_COMMAND_COMBOBOX_SELECTED,HandleComboBoxSelected)
-- connect selcetion of combo box to function
dialog:Connect(ID_CHECKLISTBOX,wx.wxEVT_COMMAND_CHECKLISTBOX_TOGGLED,HandleCheckBoxSelected)
dialog:Connect(ID_CHECKLISTBOX,wx.wxEVT_COMMAND_LISTBOX_SELECTED,HandleCheckBoxSelected)
local result = dialog:ShowModal()
if result == wx.wxID_OK then
if action=="resolve" then action="resolve --accept working" end
local selected_filenames={}
for i=base,#FileList-1 do
if checkListBox:IsChecked(i) then
push(selected_filenames,quoteshell(self:FixPath(checkListBox:GetString(i))))
end
end
selected_filenames=table.concat(selected_filenames," ")
local cmd
if textCtrl then
local comment=textCtrl:GetValue():gsub("^%s+",""):gsub("%s+$","")
printf("comment is %s\n",vis(comment))
cmd = "svn "..action..' -m '..quoteshell(comment)..' '..selected_filenames
push(self.SvnLogComments,comment)
else
cmd = "svn "..action..' '..selected_filenames
end
printf("cmd=[[%s]]\n",cmd)
self:do_command(cmd,true)
self:UpdateSvnStatus()
end
dialog:Destroy()
end
function SVN_PLUGIN:ShowDiffOutputWindow(Caption,DiffOutput)
local frame = self.parent
-- the dialog
local dialog = wx.wxDialog(frame,wx.wxID_ANY,Caption,
wx.wxDefaultPosition,wx.wxDefaultSize,
wx.wxDEFAULT_DIALOG_STYLE+wx.wxRESIZE_BORDER)
-- the sizer
local mainSizer = wx.wxBoxSizer(wx.wxVERTICAL)
local diffText=wx.wxTextCtrl(dialog,wx.wxID_ANY,"",
wx.wxDefaultPosition,wx.wxSize(800,600),
wx.wxTE_MULTILINE+wx.wxTE_DONTWRAP+wx.wxTE_RICH)
diffText:SetFont(fontCourier)
mainSizer:Add(diffText,1,wx.wxEXPAND+wx.wxALL,5)
local okButton=wx.wxButton(dialog,wx.wxID_OK,"Close") -- NEED this for validators to work
okButton:SetDefault()
local buttonSizer = wx.wxBoxSizer( wx.wxHORIZONTAL )
buttonSizer:Add(okButton,0,wx.wxALIGN_CENTER+wx.wxALL,5 )
mainSizer:Add(buttonSizer,0,wx.wxALIGN_CENTER+wx.wxALL,5 )
dialog:SetSizer(mainSizer)
mainSizer:SetSizeHints(dialog)
DiffOutputToTextCtrl(diffText,DiffOutput)
local result = dialog:ShowModal()
dialog:Destroy()
end
function SVN_PLUGIN:DoAskAction(title,action,filenames)
if filenames and #filenames>0 then
local msg=title.." "..join(filenames,"\n").."?"
for f=1,#filenames do
filenames[f]=self:FixPath(filenames[f])
end
local cmd="svn "..action.." "..quoteshell(filenames)
local btn=wx.wxMessageBox(msg.."\n\n("..cmd..")","Subversion",wx.wxOK+wx.wxCANCEL+wx.wxICON_QUESTION)
if btn==wx.wxOK then
self:do_command(cmd,true)
self:UpdateSvnStatus()
end
end
end
function SVN_PLUGIN:DoAskUpdate(filenames)
if #filenames==0 then push(filenames,self.WorkingDir) end
return self:DoAskAction("Update","update",filenames)
end
function SVN_PLUGIN:DoAskAdd(filenames)
return self:DoAskAction("Add files","add",filenames)
end
function SVN_PLUGIN:DoAskDelete(filenames)
return self:DoAskAction("Delete files","delete",filenames)
end
function SVN_PLUGIN:DoShowDiff(filename)
if filename then
if path_to_diff_tool then
local qname=quoteshell(self:FixPath(filename))
local cmd=path_to_diff_tool.." "..qname
if path_to_diff_tool:match("{{path}}") then
cmd=path_to_diff_tool:gsub("{{path}}",qname)
end
printf("cmd=[[%s]]\n",cmd)
os.execute(cmd.." &")
else
local cmd="svn diff "..quoteshell(self:FixPath(filename))
local output,sts=self:do_command(cmd)
self:ShowDiffOutputWindow(filename,output)
end
end
end
function SVN_PLUGIN:DoShowBlame(filename)
if filename then
local cmd="svn blame "..quoteshell(self:FixPath(filename))
local output,sts=self:do_command(cmd)
self:ShowDiffOutputWindow(filename,output)
end
end
function SVN_PLUGIN:DoOnIgnore(filenames,remove)
utils.ShowData("ignore.filenames",filenames)
for f=1,#filenames do
filenames[f]=self:FixPath(filenames[f])
end
utils.ShowData("ignore.filenames",filenames)
local directories=setmetatable({},mt_autocreate)
for _,filename in ipairs(filenames) do
local dir,name=filename:match("^(.+)/(.+)$")
if not dir then dir='.' name=filename end
if dir then
push(directories[dir].filenames,name)
local ext=filename:match("%.%w+$")
if ext then
add(directories[dir].exts,"*"..ext)
end
end
end
utils.ShowData("ignore.directories",directories)
local arguments={}
local menuEntries={}
local function add_ignore(dir,args)
if args and #args>0 then
local n=#arguments+1
local msg=sprintf("in %s ignore %s",dir,join(args," "))
menuEntries[n]={n,msg}
arguments[n]={dir=dir,args=args}
end
end
for directory,data in spairs(directories) do
add_ignore(directory,data.filenames)
add_ignore(directory,data.exts)
end
utils.ShowData("ignore.arguments",arguments)
utils.ShowData("ignore.menuEntries",menuEntries)
local menu = wx.wxMenu(menuEntries)
local selected_arguments
menu:Connect(wx.wxID_ANY,wx.wxEVT_COMMAND_MENU_SELECTED,function(event)
selected_arguments=arguments[event:GetId()]
end)
self.svnListCtrl:PopupMenu(menu)
if selected_arguments then
local args={}
for a,arg in ipairs(selected_arguments.args) do
push(args,selected_arguments.dir.."/"..arg)
end
local btn=wx.wxMessageBox("svn ignore "..quoteshell(args),"Subversion",wx.wxOK+wx.wxCANCEL+wx.wxICON_QUESTION)
if btn==wx.wxOK then
self:svn_set_ignore(args,remove)
self:UpdateSvnStatus()
end
end
end
function SVN_PLUGIN:GetSelectedListItems()
local filenames={}
local itemId=self.svnListCtrl:GetNextItem(-1,wx.wxLIST_NEXT_ALL,wx.wxLIST_STATE_SELECTED)
while itemId>=0 do
local itemData=self.svnListCtrl:GetItemData(itemId)
local entry=self.svnStatusEntries[itemData]
push(filenames,entry.path)
itemId=self.svnListCtrl:GetNextItem(itemId,wx.wxLIST_NEXT_ALL,wx.wxLIST_STATE_SELECTED)
end
return filenames
end
function SVN_PLUGIN:GetSelectedListItemsForAction(action)
local filenames={}
local itemId=self.svnListCtrl:GetNextItem(-1,wx.wxLIST_NEXT_ALL,wx.wxLIST_STATE_SELECTED)
while itemId>=0 do
local itemData=self.svnListCtrl:GetItemData(itemId)
local entry=self.svnStatusEntries[itemData]
local status=entry.status
local status_allowed=SVN_STATUS[status] and SVN_STATUS[status].allowed
if status_allowed and status_allowed[action] then
push(filenames,entry.path)
end
itemId=self.svnListCtrl:GetNextItem(itemId,wx.wxLIST_NEXT_ALL,wx.wxLIST_STATE_SELECTED)
end
return filenames
end
function SVN_PLUGIN:OnListCtrlRightClick(event) -- create menu items on svn file tree
printf("svn: OnListCtrlRightClick(%s)\n",vis(event))
local selected=self:GetSelectedListItems()
if #selected==0 then return end
local enables=self:GetEnablesForFiles(selected)
local menu = self:CreateMenuFor(enables)
self.svnListCtrl:PopupMenu(menu)
end
--============================================================
-- this is the main function to create and populate the
-- SVN panel "Pending changes"
--============================================================
function SVN_PLUGIN:CreateSvnPanel(parent)
self.parent=parent
--
-- create panel
--
local svnPanel = wx.wxPanel(parent, wx.wxID_ANY)
--
-- vertical sizer to put elements
--
local vSizer = wx.wxBoxSizer(wx.wxVERTICAL)
-------------------------------------------------------------------------
-- Create the action toggle toolbar
-------------------------------------------------------------------------
SVN_ACTION.refresh.onClick=function(event)
self:UpdateSvnStatus()
end
SVN_ACTION.update.onClick=function(event)
self:DoAskUpdate(SVN_PLUGIN:GetSelectedListItemsForAction("update"))
end
SVN_ACTION.add.onClick=function(event)
self:DoAskAdd(SVN_PLUGIN:GetSelectedListItemsForAction("add"))
end
SVN_ACTION.delete.onClick=function(event)
self:DoAskDelete(SVN_PLUGIN:GetSelectedListItemsForAction("delete"))
end
SVN_ACTION.diff.onClick=function(event)
local filenames=SVN_PLUGIN:GetSelectedListItemsForAction("diff")
if #filenames==1 then
self:DoShowDiff(filenames[1])
end
end
SVN_ACTION.blame.onClick=function(event)
local filenames=SVN_PLUGIN:GetSelectedListItemsForAction("blame")
if #filenames==1 then
self:DoShowBlame(filenames[1])
end
end
SVN_ACTION.info.onClick=function(event)
-- create the dialog frame
local dialog=wx.wxDialog(parent,wx.wxID_ANY,TR"svn info",wx.wxDefaultPosition,wx.wxDefaultSize)
local panel = wx.wxPanel(dialog,wx.wxID_ANY)
local mainSizer = wx.wxBoxSizer(wx.wxVERTICAL)
local flexGridSizer=wx.wxFlexGridSizer(0,2,0,0)
local function AddInfo(name,value)
local staticText=wx.wxStaticText(panel,wx.wxID_ANY,name)
local textCtrl=wx.wxStaticText(panel,wx.wxID_ANY,value)
flexGridSizer:Add( staticText,0,wx.wxALIGN_CENTER_VERTICAL+wx.wxALL,1)
flexGridSizer:Add( textCtrl,0,wx.wxGROW+wx.wxALIGN_LEFT+wx.wxALL,1)
end
local info=self:get_svn_xml("info","--xml "..quoteshell(self.WorkingDir))
local entry=info:element("entry")
AddInfo("Revision",entry:attribute"revision")
local url=entry:element("url")
AddInfo("URL",url:cdata())
local wcinfo=entry:element("wc-info")
local path=wcinfo:element("wcroot-abspath")
AddInfo("Path",path:cdata())
local commit=entry:element("commit")
AddInfo("Commit",commit:attribute"revision")
local author=commit:element("author")
AddInfo("Author",author:cdata())
--[[
<?xml version="1.0" encoding="UTF-8"?>
<info>
<entry path="." revision="304757" kind="dir">
<url>https://localhost/repos/zbs/zbssnv/trunk</url>
<relative-url>^/zbssvn/trunk</relative-url>
<repository>
<root>https://localhost/repos/zbs</root>
</repository>
<wc-info>
<wcroot-abspath>/home/user/proj/zbssvn</wcroot-abspath>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit revision="304565">
<author>John.Doe</author>
<date>2017-09-06T13:04:16.239276Z</date>
</commit>
</entry>
</info>
--]]
--dialog:CreateButtonSizer(wx.wxID_CLOSE)
local buttonSizer = wx.wxBoxSizer( wx.wxHORIZONTAL )
local closeButton = wx.wxButton( panel,wx.wxID_OK, "Close")
mainSizer:Add( flexGridSizer, 1, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL, 5 )
buttonSizer:Add( closeButton, 0, wx.wxALIGN_CENTER+wx.wxALL, 5 )
mainSizer:Add( buttonSizer, 0, wx.wxALIGN_CENTER+wx.wxALL, 5 )
panel:SetSizer( mainSizer )
mainSizer:SetSizeHints(dialog )
dialog:ShowModal()
end
SVN_ACTION.ignore.onClick=function(event)
local filenames=SVN_PLUGIN:GetSelectedListItemsForAction("ignore")
self:DoOnIgnore(filenames)
end
SVN_ACTION.unignore.onClick=function(event)
local filenames=SVN_PLUGIN:GetSelectedListItemsForAction("unignore")
self:DoOnIgnore(filenames,true)
end
SVN_ACTION.commit.onClick=function(event)
self:CreateDialog("Commit","commit",SVN_PLUGIN:GetSelectedListItemsForAction("commit"),true,true)
self.SvnLogComments=nil
end
SVN_ACTION.resolve.onClick=function(event)
self:CreateDialog("Resolve","resolve",SVN_PLUGIN:GetSelectedListItemsForAction("resolve"),false,true)
end
SVN_ACTION.revert.onClick=function(event)
self:CreateDialog("Revert","revert",SVN_PLUGIN:GetSelectedListItemsForAction("revert"),false,true)
end
-------------------------------------------------------------------------
-- Create the action toggle toolbar
-------------------------------------------------------------------------
local svnActionShowToolBar = wx.wxToolBar(svnPanel,wx.wxID_ANY,wx.wxDefaultPosition,wx.wxDefaultSize,wx.wxNO_BORDER + wx.wxTB_FLAT)
self.svnActionShowToolBar=svnActionShowToolBar
for i,data in ipairs(SVN_ACTION) do
if data.name then
local bmp=my_getBitmap("action-"..data.name)
local toolId=NewID()
svnActionShowToolBar:AddTool(toolId,data.name,bmp,data.name.." items")
if data.onClick then
svnActionShowToolBar:Connect(toolId,wx.wxEVT_COMMAND_TOOL_CLICKED,data.onClick)
end
data.actionToolId=toolId
bmp:delete()
else
svnActionShowToolBar:AddSeparator()
end
end
svnActionShowToolBar:AddSeparator()
svnActionShowToolBar:AddSeparator()
local function OnToggle(event,status)
local toolId=event:GetId()
local show=svnActionShowToolBar:GetToolState(toolId)
status.show=show
SVN_PLUGIN:Step3aUpdateSvnListControl()
SVN_PLUGIN:Step3bUpdateActionToolbar()
end
--
-- add the "show" toggles to the toolbar
--
for i,data in ipairs(SVN_STATUS) do
local show=data.show if show==nil then show=true end
data.show=show
local bmp=my_getBitmap("status-"..data.name)
local toolId=NewID()
data.statusToolId=toolId
svnActionShowToolBar:AddTool(toolId,data.name,bmp,"show "..data.name.." items",wx.wxITEM_CHECK )
svnActionShowToolBar:ToggleTool(toolId,show)
svnActionShowToolBar:SetToolClientData(toolId,wx.wxObject(data))
bmp:delete()
svnActionShowToolBar:Connect(toolId,wx.wxEVT_COMMAND_TOOL_CLICKED,function(event) OnToggle(event,data)end)
end
--
-- required,else icons wont show
--
svnActionShowToolBar:Realize()
local svnListCtrl = wx.wxListCtrl(svnPanel,ID_LISTCONTROL,wx.wxDefaultPosition,wx.wxDefaultSize,
wx.wxLC_ALIGN_LEFT+ wx.wxLC_REPORT)
svnListCtrl:Connect(ID_LISTCONTROL,wx.wxEVT_COMMAND_LIST_ITEM_SELECTED,function()
SVN_PLUGIN:Step3bUpdateActionToolbar()
end)
svnListCtrl:Connect(ID_LISTCONTROL,wx.wxEVT_COMMAND_LIST_ITEM_DESELECTED,function()
SVN_PLUGIN:Step3bUpdateActionToolbar()
end)