Thread (4 messages) flat view 4 messages, 1 author, 2016-06-15
DORMANTno replies

Revision v1 of 3 in this series.

Revisions (3)
  1. v1 current
  2. v2 [diff vs current]
  3. v5 [diff vs current]

[PATCH 3/3] gitk: merge views with existing ones

From: Max Kirillov <hidden>
Date: 2016-06-15 23:02:29
Subsystem: the rest · Maintainer: Linus Torvalds

Only new and modified views are saved; old ones are saved also
if there are no new, modified or deleted view with same name.

This allows editing view list in concurrent gitk sessions without
losing the changes.

Signed-off-by: Max Kirillov <redacted>
---
 gitk | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/gitk b/gitk
index 6e22024..3394415 100755
--- a/gitk
+++ b/gitk
@@ -2807,7 +2807,11 @@ proc doprogupdate {} {
 proc config_variable_change_cb {name name2 op} {
     global config_variable_changed
     if {$op eq "write"} {
-	set config_variable_changed($name) 1
+	if {$name2 eq ""} {
+	    set config_variable_changed($name) 1
+	} else {
+	    set config_variable_changed($name,$name2) 1
+	}
     }
 }
 
@@ -2861,12 +2865,38 @@ proc savestuff {w} {
 	puts $f "set geometry(botwidth) [winfo width .bleft]"
 	puts $f "set geometry(botheight) [winfo height .bleft]"
 
+	array set view_save {}
+	array set views {}
+	foreach view $permviews {
+	    set view_save([lindex $view 0]) 1
+	    set views([lindex $view 0]) $view
+	}
 	puts -nonewline $f "set permviews {"
 	for {set v 0} {$v < $current_nextviewnum} {incr v} {
-	    if {$current_viewperm($v)} {
-		puts $f "{[list $current_viewname($v) $current_viewfiles($v) $current_viewargs($v) $current_viewargscmd($v)]}"
+	    if {$config_variable_changed(viewname,$v) ||
+		$config_variable_changed(viewfiles,$v) ||
+		$config_variable_changed(viewargs,$v) ||
+		$config_variable_changed(viewargscmd,$v) ||
+		$config_variable_changed(viewperm,$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
+		}
+		lappend views_modified_names $current_viewname($v)
 	    }
 	}
+	# 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 "}"
 	close $f
 	file rename -force $config_file_tmp $config_file
@@ -12828,6 +12858,12 @@ if {[info exists permviews]} {
 	addviewmenu $n
     }
 }
+foreach var {viewname viewfiles viewargs viewargscmd viewperm} {
+    for {set v 0} {$v < $nextviewnum} {incr v} {
+	set config_variable_changed($var,$v) 0
+    }
+    trace add variable $var write config_variable_change_cb
+}
 
 if {[tk windowingsystem] eq "win32"} {
     focus -force .
-- 
2.0.1.1697.g73c6810
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help