183
184
set status_active 0
185
set diff_active 0
186
+set last_clicked {}
187
188
set disable_on_lock [list]
189
set index_lock_type none
352
incr z2 -1
353
display_file \
354
[string range $buf_rdi $z1 $z2] \
354
- [string index $buf_rdi [expr $z1 - 2]]_
355
+ [string index $buf_rdi [expr {$z1 - 2}]]_
356
incr c
357
}
358
if {$c < $n} {
381
incr z2 -1
382
display_file \
383
[string range $buf_rdf $z1 $z2] \
383
- _[string index $buf_rdf [expr $z1 - 2]]
384
+ _[string index $buf_rdf [expr {$z1 - 2}]]
385
incr c
386
}
387
if {$c < $n} {
415
close $fd
416
if {[incr status_active -1] > 0} return
417
418
+ prune_selection
419
unlock_index
420
display_all_files
421
437
set ui_status_value $final
438
}
439
440
+proc prune_selection {} {
441
+ global file_states selected_paths
442
+
443
+ foreach path [array names selected_paths] {
444
+ if {[catch {set still_here $file_states($path)}]} {
445
+ unset selected_paths($path)
446
+ }
447
+ }
448
+}
449
+
450
######################################################################
451
##
452
## diff
509
[lreplace $file_lists($old_w) $lno $lno]
510
incr lno
511
$old_w conf -state normal
500
- $old_w delete $lno.0 [expr $lno + 1].0
512
+ $old_w delete $lno.0 [expr {$lno + 1}].0
513
$old_w conf -state disabled
514
}
515
}
532
}
533
}
534
if {$w ne {} && $lno >= 1} {
523
- $w tag add in_diff $lno.0 [expr $lno + 1].0
535
+ $w tag add in_diff $lno.0 [expr {$lno + 1}].0
536
}
537
538
set s $file_states($path)
833
proc commit_stage3 {fd_wt curHEAD msg} {
834
global single_commit gitdir HEAD PARENT commit_type tcl_platform
835
global ui_status_value ui_comm
824
- global file_states
836
+ global file_states selected_paths
837
838
gets $fd_wt tree_id
839
if {$tree_id eq {} || [catch {close $fd_wt} err]} {
883
}
884
set i [string first "\n" $msg]
885
if {$i >= 0} {
874
- append reflogm {: } [string range $msg 0 [expr $i - 1]]
886
+ append reflogm {: } [string range $msg 0 [expr {$i - 1}]]
887
} else {
888
append reflogm {: } $msg
889
}
946
947
if {$m eq {__}} {
948
unset file_states($path)
949
+ catch {unset selected_paths($path)}
950
} else {
951
lset file_states($path) 0 $m
952
}
1115
}
1116
1117
proc display_file {path state} {
1105
- global file_states file_lists status_active
1118
+ global file_states file_lists selected_paths status_active
1119
1120
set old_m [merge_state $path $state]
1121
if {$status_active} return
1131
if {$lno >= 0} {
1132
incr lno
1133
$old_w conf -state normal
1121
- $old_w delete $lno.0 [expr $lno + 1].0
1134
+ $old_w delete $lno.0 [expr {$lno + 1}].0
1135
$old_w conf -state disabled
1136
}
1137
1145
-name [lindex $s 1] \
1146
-image $new_icon
1147
$new_w insert $lno.1 "[escape_path $path]\n"
1148
+ if {[catch {set in_sel $selected_paths($path)}]} {
1149
+ set in_sel 0
1150
+ }
1151
+ if {$in_sel} {
1152
+ $new_w tag add in_sel $lno.0 [expr {$lno + 1}].0
1153
+ }
1154
$new_w conf -state disabled
1155
} elseif {$new_icon ne [mapicon $old_m $path]} {
1156
$new_w conf -state normal
1160
}
1161
1162
proc display_all_files {} {
1144
- global ui_index ui_other file_states file_lists
1163
+ global ui_index ui_other
1164
+ global file_states file_lists
1165
+ global last_clicked selected_paths
1166
1167
$ui_index conf -state normal
1168
$ui_other conf -state normal
1169
1170
$ui_index delete 0.0 end
1171
$ui_other delete 0.0 end
1172
+ set last_clicked {}
1173
1174
set file_lists($ui_index) [list]
1175
set file_lists($ui_other) [list]
1179
set m [lindex $s 0]
1180
set w [mapcol $m $path]
1181
lappend file_lists($w) $path
1182
+ set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1183
$w image create end \
1184
-align center -padx 5 -pady 1 \
1185
-name [lindex $s 1] \
1186
-image [mapicon $m $path]
1187
$w insert end "[escape_path $path]\n"
1188
+ if {[catch {set in_sel $selected_paths($path)}]} {
1189
+ set in_sel 0
1190
+ }
1191
+ if {$in_sel} {
1192
+ $w tag add in_sel $lno.0 [expr {$lno + 1}].0
1193
+ }
1194
}
1195
1196
$ui_index conf -state disabled
1632
while {$c < $n} {
1633
set cr [string first "\r" $buf $c]
1634
set lf [string first "\n" $buf $c]
1606
- if {$cr < 0} {set cr [expr $n + 1]}
1607
- if {$lf < 0} {set lf [expr $n + 1]}
1635
+ if {$cr < 0} {set cr [expr {$n + 1}]}
1636
+ if {$lf < 0} {set lf [expr {$n + 1}]}
1637
1638
if {$lf < $cr} {
1639
$w.m.t insert end [string range $buf $c $lf]
1966
destroy $w
1967
}
1968
1940
-proc file_left_click {w x y} {
1941
- global file_lists
1969
+proc toggle_or_diff {w x y} {
1970
+ global file_lists ui_index ui_other
1971
+ global last_clicked selected_paths
1972
1973
set pos [split [$w index @$x,$y] .]
1974
set lno [lindex $pos 0]
1975
set col [lindex $pos 1]
1946
- set path [lindex $file_lists($w) [expr $lno - 1]]
1947
- if {$path eq {}} return
1976
+ set path [lindex $file_lists($w) [expr {$lno - 1}]]
1977
+ if {$path eq {}} {
1978
+ set last_clicked {}
1979
+ return
1980
+ }
1981
+
1982
+ set last_clicked [list $w $lno]
1983
+ array unset selected_paths
1984
+ $ui_index tag remove in_sel 0.0 end
1985
+ $ui_other tag remove in_sel 0.0 end
1986
1949
- if {$col > 0} {
1987
+ if {$col == 0} {
1988
+ update_index [list $path]
1989
+ } else {
1990
show_diff $path $w $lno
1991
}
1992
}
1993
1954
-proc file_left_unclick {w x y} {
1994
+proc add_one_to_selection {w x y} {
1995
global file_lists
1996
+ global last_clicked selected_paths
1997
1998
set pos [split [$w index @$x,$y] .]
1999
set lno [lindex $pos 0]
2000
set col [lindex $pos 1]
1960
- set path [lindex $file_lists($w) [expr $lno - 1]]
1961
- if {$path eq {}} return
2001
+ set path [lindex $file_lists($w) [expr {$lno - 1}]]
2002
+ if {$path eq {}} {
2003
+ set last_clicked {}
2004
+ return
2005
+ }
2006
1963
- if {$col == 0} {
1964
- update_index [list $path]
2007
+ set last_clicked [list $w $lno]
2008
+ if {[catch {set in_sel $selected_paths($path)}]} {
2009
+ set in_sel 0
2010
+ }
2011
+ if {$in_sel} {
2012
+ unset selected_paths($path)
2013
+ $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2014
+ } else {
2015
+ set selected_paths($path) 1
2016
+ $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2017
+ }
2018
+}
2019
+
2020
+proc add_range_to_selection {w x y} {
2021
+ global file_lists
2022
+ global last_clicked selected_paths
2023
+
2024
+ if {[lindex $last_clicked 0] ne $w} {
2025
+ toggle_or_diff $w $x $y
2026
+ return
2027
}
2028
+
2029
+ set pos [split [$w index @$x,$y] .]
2030
+ set lno [lindex $pos 0]
2031
+ set lc [lindex $last_clicked 1]
2032
+ if {$lc < $lno} {
2033
+ set begin $lc
2034
+ set end $lno
2035
+ } else {
2036
+ set begin $lno
2037
+ set end $lc
2038
+ }
2039
+
2040
+ foreach path [lrange $file_lists($w) \
2041
+ [expr {$begin - 1}] \
2042
+ [expr {$end - 1}]] {
2043
+ set selected_paths($path) 1
2044
+ }
2045
+ $w tag add in_sel $begin.0 [expr {$end + 1}].0
2046
}
2047
2048
######################################################################
2254
pack $ui_other -side left -fill both -expand 1
2255
.vpane.files add .vpane.files.other -sticky nsew
2256
2177
-$ui_index tag conf in_diff -font font_uibold
2178
-$ui_other tag conf in_diff -font font_uibold
2257
+foreach i [list $ui_index $ui_other] {
2258
+ $i tag conf in_diff -font font_uibold
2259
+ $i tag conf in_sel \
2260
+ -background [$i cget -foreground] \
2261
+ -foreground [$i cget -background]
2262
+}
2263
+unset i
2264
2265
# -- Diff and Commit Area
2266
frame .vpane.lower -height 300 -width 400
2542
bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2543
bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2544
foreach i [list $ui_index $ui_other] {
2460
- bind $i <Button-1> {file_left_click %W %x %y; break}
2461
- bind $i <ButtonRelease-1> {file_left_unclick %W %x %y; break}
2545
+ bind $i <Button-1> "toggle_or_diff $i %x %y; break"
2546
+ bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
2547
+ bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
2548
}
2549
unset i
2550