git-gui: Disable diff actions when no diff is active.
There is no reason why the user should be able to operate on the diff buffer if there is no currently selected diff; likewise the "File:" label text appears rather silly looking all by itself when no diff is being shown in the diff buffer. So now we only enable widgets (like menu items) if there is a diff currently showing, and we disable them when a diff isn't showing. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 15, 2006 at 18:55 UTC
e8ab64461968392f126b0a0e2fef4ce8bdcca623
1 file changed
+118
-68
git-gui
+118
-68
@@ -455,34 +455,33 @@ proc prune_selection {} {
455
## diff
456
457
proc clear_diff {} {
458
- global ui_diff ui_fname_value ui_fstatus_value ui_index ui_other
458
+ global ui_diff current_diff ui_index ui_other
459
460
$ui_diff conf -state normal
461
$ui_diff delete 0.0 end
462
$ui_diff conf -state disabled
463
464
- set ui_fname_value {}
465
- set ui_fstatus_value {}
464
+ set current_diff {}
465
466
$ui_index tag remove in_diff 0.0 end
467
$ui_other tag remove in_diff 0.0 end
468
}
469
470
proc reshow_diff {} {
472
- global ui_fname_value ui_status_value file_states
471
+ global current_diff ui_status_value file_states
472
474
- if {$ui_fname_value eq {}
475
- || [catch {set s $file_states($ui_fname_value)}]} {
473
+ if {$current_diff eq {}
474
+ || [catch {set s $file_states($current_diff)}]} {
475
clear_diff
476
} else {
478
- show_diff $ui_fname_value
477
+ show_diff $current_diff
478
}
479
}
480
481
proc handle_empty_diff {} {
483
- global ui_fname_value file_states file_lists
482
+ global current_diff file_states file_lists
483
485
- set path $ui_fname_value
484
+ set path $current_diff
485
set s $file_states($path)
486
if {[lindex $s 0] ne {_M}} return
487
@@ -520,7 +519,7 @@ files list, to prevent possible confusion.
519
proc show_diff {path {w {}} {lno {}}} {
520
global file_states file_lists
521
global PARENT diff_3way diff_active repo_config
523
- global ui_diff ui_fname_value ui_fstatus_value ui_status_value
522
+ global ui_diff current_diff ui_status_value
523
524
if {$diff_active || ![lock_index read]} return
525
@@ -542,8 +541,7 @@ proc show_diff {path {w {}} {lno {}}} {
541
set m [lindex $s 0]
542
set diff_3way 0
543
set diff_active 1
545
- set ui_fname_value $path
546
- set ui_fstatus_value [mapdesc $m $path]
544
+ set current_diff $path
545
set ui_status_value "Loading diff of [escape_path $path]..."
546
547
set cmd [list | git diff-index]
@@ -1261,7 +1259,7 @@ proc update_index {msg pathList after} {
1259
1260
proc write_update_index {fd pathList totalCnt batch msg after} {
1261
global update_index_cp update_index_rsd ui_status_value
1264
- global file_states ui_fname_value
1262
+ global file_states current_diff
1263
1264
if {$update_index_cp >= $totalCnt} {
1265
close $fd
@@ -1296,7 +1294,7 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
1294
puts -nonewline $fd $path
1295
puts -nonewline $fd "\0"
1296
display_file $path $new
1299
- if {$ui_fname_value eq $path} {
1297
+ if {$current_diff eq $path} {
1298
set update_index_rsd 1
1299
}
1300
}
@@ -2384,71 +2382,105 @@ pack .vpane.lower.commarea.buffer -side left -fill y
2382
2383
# -- Commit Message Buffer Context Menu
2384
#
2387
-menu $ui_comm.ctxm -tearoff 0
2388
-$ui_comm.ctxm add command -label "Cut" \
2385
+set ctxm .vpane.lower.commarea.buffer.ctxm
2386
+menu $ctxm -tearoff 0
2387
+$ctxm add command \
2388
+ -label {Cut} \
2389
-font font_ui \
2390
- -command "tk_textCut $ui_comm"
2391
-$ui_comm.ctxm add command -label "Copy" \
2390
+ -command {tk_textCut $ui_comm}
2391
+$ctxm add command \
2392
+ -label {Copy} \
2393
-font font_ui \
2393
- -command "tk_textCopy $ui_comm"
2394
-$ui_comm.ctxm add command -label "Paste" \
2394
+ -command {tk_textCopy $ui_comm}
2395
+$ctxm add command \
2396
+ -label {Paste} \
2397
-font font_ui \
2396
- -command "tk_textPaste $ui_comm"
2397
-$ui_comm.ctxm add command -label "Delete" \
2398
+ -command {tk_textPaste $ui_comm}
2399
+$ctxm add command \
2400
+ -label {Delete} \
2401
-font font_ui \
2399
- -command "$ui_comm delete sel.first sel.last"
2400
-$ui_comm.ctxm add separator
2401
-$ui_comm.ctxm add command -label "Select All" \
2402
+ -command {$ui_comm delete sel.first sel.last}
2403
+$ctxm add separator
2404
+$ctxm add command \
2405
+ -label {Select All} \
2406
-font font_ui \
2403
- -command "$ui_comm tag add sel 0.0 end"
2404
-$ui_comm.ctxm add command -label "Copy All" \
2407
+ -command {$ui_comm tag add sel 0.0 end}
2408
+$ctxm add command \
2409
+ -label {Copy All} \
2410
-font font_ui \
2406
- -command "
2411
+ -command {
2412
$ui_comm tag add sel 0.0 end
2413
tk_textCopy $ui_comm
2414
$ui_comm tag remove sel 0.0 end
2410
- "
2411
-$ui_comm.ctxm add separator
2412
-$ui_comm.ctxm add command -label "Sign Off" \
2415
+ }
2416
+$ctxm add separator
2417
+$ctxm add command \
2418
+ -label {Sign Off} \
2419
-font font_ui \
2420
-command do_signoff
2415
-bind_button3 $ui_comm "tk_popup $ui_comm.ctxm %X %Y"
2421
+bind_button3 $ui_comm "tk_popup $ctxm %X %Y"
2422
2423
# -- Diff Header
2418
-set ui_fname_value {}
2419
-set ui_fstatus_value {}
2424
+set current_diff {}
2425
+set diff_actions [list]
2426
+proc current_diff_trace {varname args} {
2427
+ global current_diff diff_actions file_states
2428
+ if {$current_diff eq {}} {
2429
+ set s {}
2430
+ set f {}
2431
+ set p {}
2432
+ set o disabled
2433
+ } else {
2434
+ set p $current_diff
2435
+ set s [mapdesc [lindex $file_states($p) 0] $p]
2436
+ set f {File:}
2437
+ set p [escape_path $p]
2438
+ set o normal
2439
+ }
2440
+
2441
+ .vpane.lower.diff.header.status configure -text $s
2442
+ .vpane.lower.diff.header.file configure -text $f
2443
+ .vpane.lower.diff.header.path configure -text $p
2444
+ foreach w $diff_actions {
2445
+ uplevel #0 $w $o
2446
+ }
2447
+}
2448
+trace add variable current_diff write current_diff_trace
2449
+
2450
frame .vpane.lower.diff.header -background orange
2421
-label .vpane.lower.diff.header.l4 \
2422
- -textvariable ui_fstatus_value \
2451
+label .vpane.lower.diff.header.status \
2452
-background orange \
2453
-width $max_status_desc \
2454
-anchor w \
2455
-justify left \
2456
-font font_ui
2428
-label .vpane.lower.diff.header.l1 -text {File:} \
2457
+label .vpane.lower.diff.header.file \
2458
-background orange \
2459
+ -anchor w \
2460
+ -justify left \
2461
-font font_ui
2431
-set ui_fname .vpane.lower.diff.header.l2
2432
-label $ui_fname \
2433
- -textvariable ui_fname_value \
2462
+label .vpane.lower.diff.header.path \
2463
-background orange \
2464
-anchor w \
2465
-justify left \
2466
-font font_ui
2438
-menu $ui_fname.ctxm -tearoff 0
2439
-$ui_fname.ctxm add command -label "Copy" \
2467
+pack .vpane.lower.diff.header.status -side left
2468
+pack .vpane.lower.diff.header.file -side left
2469
+pack .vpane.lower.diff.header.path -fill x
2470
+set ctxm .vpane.lower.diff.header.ctxm
2471
+menu $ctxm -tearoff 0
2472
+$ctxm add command \
2473
+ -label {Copy} \
2474
-font font_ui \
2475
-command {
2476
clipboard clear
2477
clipboard append \
2478
-format STRING \
2479
-type STRING \
2446
- -- $ui_fname_value
2480
+ -- $current_diff
2481
}
2448
-bind_button3 $ui_fname "tk_popup $ui_fname.ctxm %X %Y"
2449
-pack .vpane.lower.diff.header.l4 -side left
2450
-pack .vpane.lower.diff.header.l1 -side left
2451
-pack $ui_fname -fill x
2482
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2483
+bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
2484
2485
# -- Diff Body
2486
frame .vpane.lower.diff.body
@@ -2478,48 +2510,63 @@ $ui_diff tag conf bold -font font_diffbold
2510
2511
# -- Diff Body Context Menu
2512
#
2481
-menu $ui_diff.ctxm -tearoff 0
2482
-$ui_diff.ctxm add command -label "Copy" \
2513
+set ctxm .vpane.lower.diff.body.ctxm
2514
+menu $ctxm -tearoff 0
2515
+$ctxm add command \
2516
+ -label {Copy} \
2517
-font font_ui \
2484
- -command "tk_textCopy $ui_diff"
2485
-$ui_diff.ctxm add command -label "Select All" \
2518
+ -command {tk_textCopy $ui_diff}
2519
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2520
+$ctxm add command \
2521
+ -label {Select All} \
2522
-font font_ui \
2487
- -command "$ui_diff tag add sel 0.0 end"
2488
-$ui_diff.ctxm add command -label "Copy All" \
2523
+ -command {$ui_diff tag add sel 0.0 end}
2524
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2525
+$ctxm add command \
2526
+ -label {Copy All} \
2527
-font font_ui \
2490
- -command "
2528
+ -command {
2529
$ui_diff tag add sel 0.0 end
2530
tk_textCopy $ui_diff
2531
$ui_diff tag remove sel 0.0 end
2494
- "
2495
-$ui_diff.ctxm add separator
2496
-$ui_diff.ctxm add command -label "Decrease Font Size" \
2532
+ }
2533
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2534
+$ctxm add separator
2535
+$ctxm add command \
2536
+ -label {Decrease Font Size} \
2537
-font font_ui \
2538
-command {incr_font_size font_diff -1}
2499
-$ui_diff.ctxm add command -label "Increase Font Size" \
2539
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2540
+$ctxm add command \
2541
+ -label {Increase Font Size} \
2542
-font font_ui \
2543
-command {incr_font_size font_diff 1}
2502
-$ui_diff.ctxm add separator
2503
-$ui_diff.ctxm add command -label "Show Less Context" \
2544
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2545
+$ctxm add separator
2546
+$ctxm add command \
2547
+ -label {Show Less Context} \
2548
-font font_ui \
2505
- -command {if {$ui_fname_value ne {}
2506
- && $repo_config(gui.diffcontext) >= 2} {
2549
+ -command {if {$repo_config(gui.diffcontext) >= 2} {
2550
incr repo_config(gui.diffcontext) -1
2551
reshow_diff
2552
}}
2510
-$ui_diff.ctxm add command -label "Show More Context" \
2553
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2554
+$ctxm add command \
2555
+ -label {Show More Context} \
2556
-font font_ui \
2512
- -command {if {$ui_fname_value ne {}} {
2557
+ -command {
2558
incr repo_config(gui.diffcontext)
2559
reshow_diff
2515
- }}
2516
-$ui_diff.ctxm add separator
2517
-$ui_diff.ctxm add command -label {Options...} \
2560
+ }
2561
+lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
2562
+$ctxm add separator
2563
+$ctxm add command -label {Options...} \
2564
-font font_ui \
2565
-command do_options
2520
-bind_button3 $ui_diff "tk_popup $ui_diff.ctxm %X %Y"
2566
+bind_button3 $ui_diff "tk_popup $ctxm %X %Y"
2567
2568
# -- Status Bar
2569
+#
2570
set ui_status_value {Initializing...}
2571
label .status -textvariable ui_status_value \
2572
-anchor w \
@@ -2530,6 +2577,7 @@ label .status -textvariable ui_status_value \
2577
pack .status -anchor w -side bottom -fill x
2578
2579
# -- Load geometry
2580
+#
2581
catch {
2582
set gm $repo_config(gui.geometry)
2583
wm geometry . [lindex $gm 0]
@@ -2543,6 +2591,7 @@ unset gm
2591
}
2592
2593
# -- Key Bindings
2594
+#
2595
bind $ui_comm <$M1B-Key-Return> {do_commit;break}
2596
bind $ui_comm <$M1B-Key-i> {do_include_all;break}
2597
bind $ui_comm <$M1B-Key-I> {do_include_all;break}
@@ -2590,6 +2639,7 @@ unset i
2639
2640
set file_lists($ui_index) [list]
2641
set file_lists($ui_other) [list]
2642
+set current_diff {}
2643
2644
wm title . "$appname ([file normalize [file dirname $gitdir]])"
2645
focus -force $ui_comm