From e974342693b3258edd536e4b7f23ac9bf21a6cd7 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 30 Sep 2020 22:41:28 +0200 Subject: [PATCH] Automatically switch on simplified view when there are >= 3 commits --- repository.gd | 27 +++++++++++++++------------ repository.tscn | 4 +++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/repository.gd b/repository.gd index 777abb6..9398003 100644 --- a/repository.gd +++ b/repository.gd @@ -19,6 +19,9 @@ var shell = Shell.new() var objects = {} var mouse_inside = false +# We use this for a heuristic of when to hide trees and blobs. +var _commit_count = 0 + func _ready(): file_browser.shell = shell @@ -118,6 +121,10 @@ func update_objects(): for p in commit_parents(o): c[p] = "" n.children = c + + _commit_count += 1 + if _commit_count >= 3 and not simplified_view: + simplified_view = true "tag": n.children = tag_target(o) @@ -263,22 +270,18 @@ func ref_target(ref): ret = git("show-ref "+ref).split(" ")[0] return ret - -func simplify_view(pressed): - simplified_view = pressed - - for o in objects: - var obj = objects[o] - if obj.type == "tree" or obj.type == "blob": - obj.visible = not pressed - - if there_is_a_git(): - update_objects() - func set_simplified_view(simplify): simplified_view = simplify if simplify_checkbox: simplify_checkbox.pressed = simplify + + for o in objects: + var obj = objects[o] + if obj.type == "tree" or obj.type == "blob": + obj.visible = not simplify + + if there_is_a_git(): + update_objects() func set_editable_path(editable): editable_path = editable diff --git a/repository.tscn b/repository.tscn index 362786c..cf9d538 100644 --- a/repository.tscn +++ b/repository.tscn @@ -93,6 +93,8 @@ __meta__ = { [node name="Nodes" type="Control" parent="Rows/RepoVis"] anchor_right = 1.0 anchor_bottom = 1.0 +margin_top = -1.43991 +margin_bottom = -1.43994 mouse_filter = 2 __meta__ = { "_edit_use_anchors_": false @@ -118,5 +120,5 @@ size_flags_stretch_ratio = 0.16 [connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] [connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] [connection signal="pressed" from="Rows/RepoVis/Button" to="." method="update_everything"] -[connection signal="toggled" from="Rows/RepoVis/SimplifyCheckbox" to="." method="simplify_view"] +[connection signal="toggled" from="Rows/RepoVis/SimplifyCheckbox" to="." method="set_simplified_view"] [connection signal="text_entered" from="Rows/RepoVis/Path" to="." method="set_path"]