gitk: Only write changed configuration variables
When gitk contains some changed parameter, and there is an existing instance of gitk where the parameter is still old, it is reverted to that old value when that instance exits. Instead, store a parameter in config only if it has been modified in the exiting instance. Otherwise, preserve the value which currently is in file. This allows editing the configuration when several instances are running, without rollback of the modification if some other instance where the configuration was not edited is closed last. For scalar variables, use trace(3tcl) to detect their change. Since `trace` can send bogus events, doublecheck if the value has really been changed, but once it is marked as changed, do not reset it back to unchanged ever, because if user has restored the original value, it's the decision which should be stored as well as modified value. Treat view list especially: instead of rewriting the whole list, merge individual views. Place old and updated views in their old places, add new ones to the end of list. Collect modified views explicitly, in newviewok{} and delview{}. Do not merge geometry values. They are almost always changing because user moves and resises windows, and there is no way to find which one of the geometries is most desired. Just overwrite them unconditionally, like earlier. Signed-off-by: Max Kirillov <max@max630.net> Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:
parent
122b807992
commit
995f792b99
86
gitk
86
gitk
@ -2783,12 +2783,38 @@ proc doprogupdate {} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc config_init_trace {name} {
|
||||||
|
global config_variable_changed config_variable_original
|
||||||
|
|
||||||
|
upvar #0 $name var
|
||||||
|
set config_variable_changed($name) 0
|
||||||
|
set config_variable_original($name) $var
|
||||||
|
}
|
||||||
|
|
||||||
|
proc config_variable_change_cb {name name2 op} {
|
||||||
|
global config_variable_changed config_variable_original
|
||||||
|
|
||||||
|
upvar #0 $name var
|
||||||
|
if {$op eq "write" &&
|
||||||
|
(![info exists config_variable_original($name)] ||
|
||||||
|
$config_variable_original($name) ne $var)} {
|
||||||
|
set config_variable_changed($name) 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proc savestuff {w} {
|
proc savestuff {w} {
|
||||||
global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
|
|
||||||
global use_ttk
|
|
||||||
global stuffsaved
|
global stuffsaved
|
||||||
global config_file config_file_tmp
|
global config_file config_file_tmp
|
||||||
global config_variables
|
global config_variables config_variable_changed
|
||||||
|
global viewchanged
|
||||||
|
|
||||||
|
upvar #0 viewname current_viewname
|
||||||
|
upvar #0 viewfiles current_viewfiles
|
||||||
|
upvar #0 viewargs current_viewargs
|
||||||
|
upvar #0 viewargscmd current_viewargscmd
|
||||||
|
upvar #0 viewperm current_viewperm
|
||||||
|
upvar #0 nextviewnum current_nextviewnum
|
||||||
|
upvar #0 use_ttk current_use_ttk
|
||||||
|
|
||||||
if {$stuffsaved} return
|
if {$stuffsaved} return
|
||||||
if {![winfo viewable .]} return
|
if {![winfo viewable .]} return
|
||||||
@ -2800,16 +2826,24 @@ proc savestuff {w} {
|
|||||||
if {$::tcl_platform(platform) eq {windows}} {
|
if {$::tcl_platform(platform) eq {windows}} {
|
||||||
file attributes $config_file_tmp -hidden true
|
file attributes $config_file_tmp -hidden true
|
||||||
}
|
}
|
||||||
|
if {[file exists $config_file]} {
|
||||||
|
source $config_file
|
||||||
|
}
|
||||||
foreach var_name $config_variables {
|
foreach var_name $config_variables {
|
||||||
upvar #0 $var_name var
|
upvar #0 $var_name var
|
||||||
|
upvar 0 $var_name old_var
|
||||||
|
if {!$config_variable_changed($var_name) && [info exists old_var]} {
|
||||||
|
puts $f [list set $var_name $old_var]
|
||||||
|
} else {
|
||||||
puts $f [list set $var_name $var]
|
puts $f [list set $var_name $var]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
puts $f "set geometry(main) [wm geometry .]"
|
puts $f "set geometry(main) [wm geometry .]"
|
||||||
puts $f "set geometry(state) [wm state .]"
|
puts $f "set geometry(state) [wm state .]"
|
||||||
puts $f "set geometry(topwidth) [winfo width .tf]"
|
puts $f "set geometry(topwidth) [winfo width .tf]"
|
||||||
puts $f "set geometry(topheight) [winfo height .tf]"
|
puts $f "set geometry(topheight) [winfo height .tf]"
|
||||||
if {$use_ttk} {
|
if {$current_use_ttk} {
|
||||||
puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
|
puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
|
||||||
puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
|
puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
|
||||||
} else {
|
} else {
|
||||||
@ -2819,11 +2853,33 @@ proc savestuff {w} {
|
|||||||
puts $f "set geometry(botwidth) [winfo width .bleft]"
|
puts $f "set geometry(botwidth) [winfo width .bleft]"
|
||||||
puts $f "set geometry(botheight) [winfo height .bleft]"
|
puts $f "set geometry(botheight) [winfo height .bleft]"
|
||||||
|
|
||||||
puts -nonewline $f "set permviews {"
|
array set view_save {}
|
||||||
for {set v 0} {$v < $nextviewnum} {incr v} {
|
array set views {}
|
||||||
if {$viewperm($v)} {
|
if {![info exists permviews]} { set permviews {} }
|
||||||
puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
|
foreach view $permviews {
|
||||||
|
set view_save([lindex $view 0]) 1
|
||||||
|
set views([lindex $view 0]) $view
|
||||||
}
|
}
|
||||||
|
puts -nonewline $f "set permviews {"
|
||||||
|
for {set v 1} {$v < $current_nextviewnum} {incr v} {
|
||||||
|
if {$viewchanged($v)} {
|
||||||
|
if {$current_viewperm($v)} {
|
||||||
|
set views($current_viewname($v)) [list $current_viewname($v) $current_viewfiles($v) $current_viewargs($v) $current_viewargscmd($v)]
|
||||||
|
} else {
|
||||||
|
set view_save($current_viewname($v)) 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# write old and updated view to their places and append remaining to the end
|
||||||
|
foreach view $permviews {
|
||||||
|
set view_name [lindex $view 0]
|
||||||
|
if {$view_save($view_name)} {
|
||||||
|
puts $f "{$views($view_name)}"
|
||||||
|
}
|
||||||
|
unset views($view_name)
|
||||||
|
}
|
||||||
|
foreach view_name [array names views] {
|
||||||
|
puts $f "{$views($view_name)}"
|
||||||
}
|
}
|
||||||
puts $f "}"
|
puts $f "}"
|
||||||
close $f
|
close $f
|
||||||
@ -4245,7 +4301,7 @@ proc allviewmenus {n op args} {
|
|||||||
|
|
||||||
proc newviewok {top n {apply 0}} {
|
proc newviewok {top n {apply 0}} {
|
||||||
global nextviewnum newviewperm newviewname newishighlight
|
global nextviewnum newviewperm newviewname newishighlight
|
||||||
global viewname viewfiles viewperm selectedview curview
|
global viewname viewfiles viewperm viewchanged selectedview curview
|
||||||
global viewargs viewargscmd newviewopts viewhlmenu
|
global viewargs viewargscmd newviewopts viewhlmenu
|
||||||
|
|
||||||
if {[catch {
|
if {[catch {
|
||||||
@ -4266,6 +4322,7 @@ proc newviewok {top n {apply 0}} {
|
|||||||
incr nextviewnum
|
incr nextviewnum
|
||||||
set viewname($n) $newviewname($n)
|
set viewname($n) $newviewname($n)
|
||||||
set viewperm($n) $newviewopts($n,perm)
|
set viewperm($n) $newviewopts($n,perm)
|
||||||
|
set viewchanged($n) 1
|
||||||
set viewfiles($n) $files
|
set viewfiles($n) $files
|
||||||
set viewargs($n) $newargs
|
set viewargs($n) $newargs
|
||||||
set viewargscmd($n) $newviewopts($n,cmd)
|
set viewargscmd($n) $newviewopts($n,cmd)
|
||||||
@ -4278,6 +4335,7 @@ proc newviewok {top n {apply 0}} {
|
|||||||
} else {
|
} else {
|
||||||
# editing an existing view
|
# editing an existing view
|
||||||
set viewperm($n) $newviewopts($n,perm)
|
set viewperm($n) $newviewopts($n,perm)
|
||||||
|
set viewchanged($n) 1
|
||||||
if {$newviewname($n) ne $viewname($n)} {
|
if {$newviewname($n) ne $viewname($n)} {
|
||||||
set viewname($n) $newviewname($n)
|
set viewname($n) $newviewname($n)
|
||||||
doviewmenu .bar.view 5 [list showview $n] \
|
doviewmenu .bar.view 5 [list showview $n] \
|
||||||
@ -4300,7 +4358,7 @@ proc newviewok {top n {apply 0}} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc delview {} {
|
proc delview {} {
|
||||||
global curview viewperm hlview selectedhlview
|
global curview viewperm hlview selectedhlview viewchanged
|
||||||
|
|
||||||
if {$curview == 0} return
|
if {$curview == 0} return
|
||||||
if {[info exists hlview] && $hlview == $curview} {
|
if {[info exists hlview] && $hlview == $curview} {
|
||||||
@ -4309,6 +4367,7 @@ proc delview {} {
|
|||||||
}
|
}
|
||||||
allviewmenus $curview delete
|
allviewmenus $curview delete
|
||||||
set viewperm($curview) 0
|
set viewperm($curview) 0
|
||||||
|
set viewchanged($curview) 1
|
||||||
showview 0
|
showview 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12129,6 +12188,10 @@ set config_variables {
|
|||||||
linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
|
linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
|
||||||
indexcirclecolor circlecolors linkfgcolor circleoutlinecolor
|
indexcirclecolor circlecolors linkfgcolor circleoutlinecolor
|
||||||
}
|
}
|
||||||
|
foreach var $config_variables {
|
||||||
|
config_init_trace $var
|
||||||
|
trace add variable $var write config_variable_change_cb
|
||||||
|
}
|
||||||
|
|
||||||
parsefont mainfont $mainfont
|
parsefont mainfont $mainfont
|
||||||
eval font create mainfont [fontflags mainfont]
|
eval font create mainfont [fontflags mainfont]
|
||||||
@ -12256,6 +12319,7 @@ set highlight_related [mc "None"]
|
|||||||
set highlight_files {}
|
set highlight_files {}
|
||||||
set viewfiles(0) {}
|
set viewfiles(0) {}
|
||||||
set viewperm(0) 0
|
set viewperm(0) 0
|
||||||
|
set viewchanged(0) 0
|
||||||
set viewargs(0) {}
|
set viewargs(0) {}
|
||||||
set viewargscmd(0) {}
|
set viewargscmd(0) {}
|
||||||
|
|
||||||
@ -12314,6 +12378,7 @@ if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
|
|||||||
set viewargs(1) $revtreeargs
|
set viewargs(1) $revtreeargs
|
||||||
set viewargscmd(1) $revtreeargscmd
|
set viewargscmd(1) $revtreeargscmd
|
||||||
set viewperm(1) 0
|
set viewperm(1) 0
|
||||||
|
set viewchanged(1) 0
|
||||||
set vdatemode(1) 0
|
set vdatemode(1) 0
|
||||||
addviewmenu 1
|
addviewmenu 1
|
||||||
.bar.view entryconf [mca "Edit view..."] -state normal
|
.bar.view entryconf [mca "Edit view..."] -state normal
|
||||||
@ -12329,6 +12394,7 @@ if {[info exists permviews]} {
|
|||||||
set viewargs($n) [lindex $v 2]
|
set viewargs($n) [lindex $v 2]
|
||||||
set viewargscmd($n) [lindex $v 3]
|
set viewargscmd($n) [lindex $v 3]
|
||||||
set viewperm($n) 1
|
set viewperm($n) 1
|
||||||
|
set viewchanged($n) 0
|
||||||
addviewmenu $n
|
addviewmenu $n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user