From 0780ebc692fe007fd75cc6181bfe556a736ee8e5 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Fri, 23 Oct 2020 15:19:25 +0200 Subject: [PATCH] Also show a file browser for the index --- file_browser.gd | 23 ++++++++++++++++++----- repository.gd | 5 +++-- repository.tscn | 21 +++++++++------------ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/file_browser.gd b/file_browser.gd index f6d5afe..df0e9fb 100644 --- a/file_browser.gd +++ b/file_browser.gd @@ -10,17 +10,20 @@ export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY var shell var commit setget _set_commit +var repository onready var grid = $Panel/Margin/Rows/Scroll/Grid func _ready(): update() - + +func clear(): + for item in grid.get_children(): + item.queue_free() + func update(): if grid: - for item in grid.get_children(): - item.queue_free() - + clear() match mode: FileBrowserMode.WORKING_DIRECTORY: if shell: @@ -46,7 +49,17 @@ func update(): for file_path in files: var item = preload("res://file_browser_item.tscn").instance() item.label = file_path - item.connect("clicked", self, "item_clicked") + #item.connect("clicked", self, "item_clicked") + grid.add_child(item) + FileBrowserMode.INDEX: + if repository: + var files = Array(repository.shell.run("git ls-files -s | cut -f2").split("\n")) + # The last entry is an empty string, remove it. + files.pop_back() + for file_path in files: + var item = preload("res://file_browser_item.tscn").instance() + item.label = file_path + #item.connect("clicked", self, "item_clicked") grid.add_child(item) func item_clicked(item): diff --git a/repository.gd b/repository.gd index 1a2a879..b193a33 100644 --- a/repository.gd +++ b/repository.gd @@ -31,6 +31,7 @@ func _ready(): set_simplified_view(simplified_view) set_editable_path(editable_path) set_path(path) + index.repository = self update_everything() update_node_positions() @@ -60,7 +61,7 @@ func update_everything(): remove_gone_stuff() else: if index: - index.text = "" + index.clear() for o in objects: objects[o].queue_free() objects = {} @@ -86,7 +87,7 @@ func set_label(new_label): label_node.text = new_label func update_index(): - index.text = git("ls-files -s --abbrev=8").replace("\t", " ") + index.update() func random_position(): return Vector2(rand_range(0, rect_size.x), rand_range(0, rect_size.y)) diff --git a/repository.tscn b/repository.tscn index 5c9261d..07d1f7a 100644 --- a/repository.tscn +++ b/repository.tscn @@ -43,16 +43,13 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Index" type="Label" parent="Rows/RepoVis"] -margin_left = 8.64569 -margin_top = 63.8375 -margin_right = 359.725 -margin_bottom = 1027.84 -text = "entry1 -entry2" -__meta__ = { -"_edit_use_anchors_": false -} +[node name="Index" parent="Rows/RepoVis" instance=ExtResource( 4 )] +anchor_bottom = 0.0 +margin_left = 22.0 +margin_top = 65.0 +margin_right = -17.0 +margin_bottom = 188.0 +mode = 2 [node name="IndexLabel" type="Label" parent="Rows/RepoVis"] visible = false @@ -93,14 +90,14 @@ __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 +margin_bottom = -6.10352e-05 mouse_filter = 2 __meta__ = { "_edit_use_anchors_": false } [node name="Path" type="LineEdit" parent="Rows/RepoVis"] +visible = false margin_left = 23.0 margin_top = 12.0 margin_right = 374.0