Also show a file browser for the index

This commit is contained in:
Sebastian Morr 2020-10-23 15:19:25 +02:00
parent 6f2700d7fb
commit 0780ebc692
3 changed files with 30 additions and 19 deletions

View file

@ -10,17 +10,20 @@ export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY
var shell var shell
var commit setget _set_commit var commit setget _set_commit
var repository
onready var grid = $Panel/Margin/Rows/Scroll/Grid onready var grid = $Panel/Margin/Rows/Scroll/Grid
func _ready(): func _ready():
update() update()
func clear():
for item in grid.get_children():
item.queue_free()
func update(): func update():
if grid: if grid:
for item in grid.get_children(): clear()
item.queue_free()
match mode: match mode:
FileBrowserMode.WORKING_DIRECTORY: FileBrowserMode.WORKING_DIRECTORY:
if shell: if shell:
@ -46,7 +49,17 @@ func update():
for file_path in files: for file_path in files:
var item = preload("res://file_browser_item.tscn").instance() var item = preload("res://file_browser_item.tscn").instance()
item.label = file_path 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) grid.add_child(item)
func item_clicked(item): func item_clicked(item):

View file

@ -31,6 +31,7 @@ func _ready():
set_simplified_view(simplified_view) set_simplified_view(simplified_view)
set_editable_path(editable_path) set_editable_path(editable_path)
set_path(path) set_path(path)
index.repository = self
update_everything() update_everything()
update_node_positions() update_node_positions()
@ -60,7 +61,7 @@ func update_everything():
remove_gone_stuff() remove_gone_stuff()
else: else:
if index: if index:
index.text = "" index.clear()
for o in objects: for o in objects:
objects[o].queue_free() objects[o].queue_free()
objects = {} objects = {}
@ -86,7 +87,7 @@ func set_label(new_label):
label_node.text = new_label label_node.text = new_label
func update_index(): func update_index():
index.text = git("ls-files -s --abbrev=8").replace("\t", " ") index.update()
func random_position(): func random_position():
return Vector2(rand_range(0, rect_size.x), rand_range(0, rect_size.y)) return Vector2(rand_range(0, rect_size.x), rand_range(0, rect_size.y))

View file

@ -43,16 +43,13 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Index" type="Label" parent="Rows/RepoVis"] [node name="Index" parent="Rows/RepoVis" instance=ExtResource( 4 )]
margin_left = 8.64569 anchor_bottom = 0.0
margin_top = 63.8375 margin_left = 22.0
margin_right = 359.725 margin_top = 65.0
margin_bottom = 1027.84 margin_right = -17.0
text = "entry1 margin_bottom = 188.0
entry2" mode = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="IndexLabel" type="Label" parent="Rows/RepoVis"] [node name="IndexLabel" type="Label" parent="Rows/RepoVis"]
visible = false visible = false
@ -93,14 +90,14 @@ __meta__ = {
[node name="Nodes" type="Control" parent="Rows/RepoVis"] [node name="Nodes" type="Control" parent="Rows/RepoVis"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_top = -1.43991 margin_bottom = -6.10352e-05
margin_bottom = -1.43994
mouse_filter = 2 mouse_filter = 2
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Path" type="LineEdit" parent="Rows/RepoVis"] [node name="Path" type="LineEdit" parent="Rows/RepoVis"]
visible = false
margin_left = 23.0 margin_left = 23.0
margin_top = 12.0 margin_top = 12.0
margin_right = 374.0 margin_right = 374.0