Have a file browser in each commit, which shows its content

This commit is contained in:
Sebastian Morr 2020-10-23 15:08:51 +02:00
parent 006e4ba338
commit 6f2700d7fb
4 changed files with 63 additions and 21 deletions

View file

@ -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".

View file

@ -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

View file

@ -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

View file

@ -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"]