diff --git a/file_browser.gd b/file_browser.gd index c2cf73b..f6d5afe 100644 --- a/file_browser.gd +++ b/file_browser.gd @@ -1,34 +1,62 @@ extends Control +enum FileBrowserMode { + WORKING_DIRECTORY, + COMMIT, + INDEX +} + +export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY + var shell -var thread +var commit setget _set_commit onready var grid = $Panel/Margin/Rows/Scroll/Grid +func _ready(): + update() + func update(): - for item in grid.get_children(): - item.queue_free() - - var file_string = shell.run("find . -type f") - var files = file_string.split("\n") - files = Array(files) - # The last entry is an empty string, remove it. - files.pop_back() - files.sort_custom(self, "very_best_sort") - for file_path in files: - file_path = file_path.substr(2) - if file_path.substr(0, 5) == ".git/": - continue - var item = preload("res://file_browser_item.tscn").instance() - item.label = file_path - item.connect("clicked", self, "item_clicked") - grid.add_child(item) - #child.set_editable(0, true) + if grid: + for item in grid.get_children(): + item.queue_free() + + match mode: + FileBrowserMode.WORKING_DIRECTORY: + if shell: + var file_string = shell.run("find . -type f") + var files = file_string.split("\n") + files = Array(files) + # The last entry is an empty string, remove it. + files.pop_back() + files.sort_custom(self, "very_best_sort") + for file_path in files: + file_path = file_path.substr(2) + if file_path.substr(0, 5) == ".git/": + continue + var item = preload("res://file_browser_item.tscn").instance() + item.label = file_path + item.connect("clicked", self, "item_clicked") + grid.add_child(item) + FileBrowserMode.COMMIT: + if commit: + var files = Array(commit.repository.shell.run("git ls-tree --name-only -r %s" % commit.id).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): var file_path = item.label shell.run("'%s'/fake-editor-noblock '%s'" % [game.tmp_prefix_inside, file_path]) +func _set_commit(new_commit): + commit = new_commit + update() + func very_best_sort(a,b): # We're looking at the third character because all entries have the form # "./.git/bla". diff --git a/file_browser_item.tscn b/file_browser_item.tscn index d082c09..5fcec84 100644 --- a/file_browser_item.tscn +++ b/file_browser_item.tscn @@ -8,7 +8,7 @@ anchor_right = 0.052 anchor_bottom = 0.093 margin_right = 100.16 margin_bottom = -0.439995 -rect_min_size = Vector2( 200, 100 ) +rect_min_size = Vector2( 150, 100 ) script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false diff --git a/node.gd b/node.gd index 8ddc50f..bb428d8 100644 --- a/node.gd +++ b/node.gd @@ -53,6 +53,8 @@ func content_set(new_content): func type_set(new_type): type = new_type + if type == "commit": + $FileBrowser.commit = self if type != "ref": $ID.text = $ID.text.substr(0,8) #elif type == "ref": @@ -111,6 +113,7 @@ func _input(event): if hovered: if event.is_action_pressed("click"): held = true + $FileBrowser.visible = not $FileBrowser.visible elif event.is_action_pressed("right_click"): var input = get_tree().get_current_scene().find_node("Input") input.text += id diff --git a/node.tscn b/node.tscn index f2cd14a..efb6e74 100644 --- a/node.tscn +++ b/node.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://node.gd" type="Script" id=1] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2] [ext_resource path="res://nodes/blob.svg" type="Texture" id=3] [ext_resource path="res://nodes/pop.wav" type="AudioStream" id=4] [ext_resource path="res://drop_area.tscn" type="PackedScene" id=5] +[ext_resource path="res://file_browser.tscn" type="PackedScene" id=6] [sub_resource type="CircleShape2D" id=1] radius = 23.6295 @@ -79,6 +80,16 @@ custom_colors/font_color = Color( 1, 1, 1, 1 ) __meta__ = { "_edit_use_anchors_": false } + +[node name="FileBrowser" parent="." instance=ExtResource( 6 )] +visible = false +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 32.0 +margin_top = -25.0 +margin_right = 460.0 +margin_bottom = 93.0 +mode = 1 [connection signal="mouse_entered" from="Rect" to="." method="_on_hover"] [connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"] [connection signal="mouse_entered" from="Area2D" to="." method="_on_hover"]