Added File Browser for Repository Scene

This commit is contained in:
bleeptrack 2020-09-22 13:15:36 +02:00
parent 9f657b012f
commit 1a264e2beb
8 changed files with 169 additions and 35 deletions

30
file_browser.gd Normal file
View file

@ -0,0 +1,30 @@
extends Control
var shell
var thread
func _ready():
pass
func update():
$FileTree.clear()
var root_item = $FileTree.create_item()
root_item.set_text(0, "FILES")
var file_string = shell.run("find -type f")
var files = file_string.split("\n")
files = Array(files)
files.sort()
for file_path in files:
file_path = file_path.substr(2)
var child = $FileTree.create_item(root_item)
child.set_text(0, file_path)
#child.set_editable(0, true)
func _on_item_selected():
var item = $FileTree.get_selected()
var file_path = item.get_text(0)
shell.run("/tmp/fake-editor-noblock "+file_path)

21
file_browser.tscn Normal file
View file

@ -0,0 +1,21 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://file_browser.gd" type="Script" id=1]
[node name="FileBrowser" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="FileTree" type="Tree" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
allow_reselect = true
hide_root = true
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="item_selected" from="FileTree" to="." method="_on_item_selected"]

17
game.gd
View file

@ -7,15 +7,20 @@ var fake_editor
func _ready():
global_shell = Shell.new()
fake_editor = copy_file_to_game_env("fake-editor")
copy_file_to_game_env("fake-editor-noblock")
func copy_file_to_game_env(filename):
# Copy fake-editor to tmp directory (because the original might be in a .pck file).
var fake_editor_outside = tmp_prefix + "fake-editor"
fake_editor = "/tmp/fake-editor"
var content = game.read_file("res://scripts/fake-editor", "")
var file_outside = tmp_prefix + filename
var file_inside = "/tmp/"+filename
var content = game.read_file("res://scripts/"+filename, "")
if content.empty():
push_error("fake-editor could not be read.")
write_file(fake_editor_outside, content)
global_shell.run("chmod u+x " + fake_editor)
push_error(filename + " could not be read.")
write_file(file_outside, content)
global_shell.run("chmod u+x " + file_inside)
return file_inside
func read_file(path, fallback_string):
if debug_file_io:

View file

@ -78,6 +78,7 @@ margin_bottom = 1070.0
size_flags_horizontal = 3
size_flags_vertical = 3
label = "Goal"
file_browser_active = false
[node name="ActiveRepository" parent="HBoxContainer/Repositories" instance=ExtResource( 3 )]
anchor_right = 0.0

View file

@ -1,7 +1,20 @@
extends Control
export(NodePath) var index_path
onready var index = get_node(index_path)
export(NodePath) var nodes_path
onready var nodes = get_node(nodes_path)
export(NodePath) var file_browser_path
onready var file_browser = get_node(file_browser_path)
export(NodePath) var label_node_path
onready var label_node = get_node(label_node_path)
export var label: String setget set_label
export var path: String setget set_path, get_path
export var file_browser_active = true setget set_file_browser_active
var node = preload("res://node.tscn")
@ -12,7 +25,12 @@ var mouse_inside = false
var _simplified_view = false
func _ready():
$Nodes.rect_pivot_offset = $Nodes.rect_size / 2
nodes.rect_pivot_offset = nodes.rect_size / 2
file_browser.shell = shell
# Trigger these again because nodes were not ready before.
set_label(label)
set_file_browser_active(file_browser_active)
func _process(_delta):
if path:
@ -20,15 +38,16 @@ func _process(_delta):
func _input(event):
if mouse_inside:
if event.is_action_pressed("zoom_out") and $Nodes.rect_scale.x > 0.3:
$Nodes.rect_scale -= Vector2(0.05, 0.05)
if event.is_action_pressed("zoom_in") and $Nodes.rect_scale.x < 2:
$Nodes.rect_scale += Vector2(0.05, 0.05)
if event.is_action_pressed("zoom_out") and nodes.rect_scale.x > 0.3:
nodes.rect_scale -= Vector2(0.05, 0.05)
if event.is_action_pressed("zoom_in") and nodes.rect_scale.x < 2:
nodes.rect_scale += Vector2(0.05, 0.05)
func there_is_a_git():
return shell.run("test -d .git && echo yes || echo no") == "yes\n"
func update_everything():
file_browser.update()
if there_is_a_git():
update_head()
update_refs()
@ -36,7 +55,8 @@ func update_everything():
update_objects()
remove_gone_stuff()
else:
$Index.text = ""
index.text = ""
func set_path(new_path):
path = new_path
@ -51,10 +71,11 @@ func get_path():
func set_label(new_label):
label = new_label
$Label.text = new_label
if label_node:
label_node.text = new_label
func update_index():
$Index.text = git("ls-files -s --abbrev=8").replace("\t", " ")
index.text = git("ls-files -s --abbrev=8").replace("\t", " ")
func random_position():
return Vector2(rand_range(0, rect_size.x), rand_range(0, rect_size.y))
@ -94,7 +115,7 @@ func update_objects():
n.children = tag_target(o)
n.position = find_position(n)
$Nodes.add_child(n)
nodes.add_child(n)
objects[o] = n
func update_refs():
@ -108,7 +129,7 @@ func update_refs():
objects[r] = n
n.children = {ref_target(r): ""}
n.position = find_position(n)
$Nodes.add_child(n)
nodes.add_child(n)
var n = objects[r]
n.children = {ref_target(r): ""}
@ -166,7 +187,7 @@ func update_head():
n.position = find_position(n)
objects["HEAD"] = n
$Nodes.add_child(n)
nodes.add_child(n)
var n = objects["HEAD"]
n.children = {ref_target("HEAD"): ""}
@ -266,3 +287,10 @@ func _on_mouse_entered():
func _on_mouse_exited():
mouse_inside = false
func set_file_browser_active(active):
file_browser_active = active
if file_browser:
file_browser.visible = active

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://repository.gd" type="Script" id=1]
[ext_resource path="res://styles/theme.tres" type="Theme" id=2]
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=3]
[ext_resource path="res://file_browser.tscn" type="PackedScene" id=4]
[node name="Repository" type="Control"]
anchor_right = 1.0
@ -10,8 +11,28 @@ anchor_bottom = 1.0
mouse_filter = 1
theme = ExtResource( 2 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
index_path = NodePath("VSplitContainer/RepoVis/Index")
nodes_path = NodePath("VSplitContainer/RepoVis/Nodes")
file_browser_path = NodePath("VSplitContainer/FileBrowser")
label_node_path = NodePath("VSplitContainer/RepoVis/Label")
[node name="Label" type="Label" parent="."]
[node name="VSplitContainer" type="VSplitContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="RepoVis" type="Control" parent="VSplitContainer"]
margin_right = 1920.0
margin_bottom = 894.0
rect_clip_content = true
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="VSplitContainer/RepoVis"]
margin_left = 5.60091
margin_top = -0.518692
margin_right = 204.601
@ -22,7 +43,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Index" type="Label" parent="."]
[node name="Index" type="Label" parent="VSplitContainer/RepoVis"]
margin_left = 8.64569
margin_top = 63.8375
margin_right = 359.725
@ -33,7 +54,7 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="IndexLabel" type="Label" parent="."]
[node name="IndexLabel" type="Label" parent="VSplitContainer/RepoVis"]
visible = false
margin_left = 21.0
margin_top = 65.0
@ -44,33 +65,48 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" type="Button" parent="."]
[node name="Button" type="Button" parent="VSplitContainer/RepoVis"]
visible = false
margin_left = 36.5602
margin_top = 67.9891
margin_right = 94.5602
margin_right = 119.56
margin_bottom = 109.989
text = "Update"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SimplifyCheckbox" type="CheckBox" parent="."]
anchor_top = 1.0
anchor_bottom = 1.0
margin_left = 2.87984
margin_top = -23.2002
margin_right = 195.88
margin_bottom = 1.7998
[node name="SimplifyCheckbox" type="CheckBox" parent="VSplitContainer/RepoVis"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -208.715
margin_top = 17.9594
margin_right = -15.7146
margin_bottom = 42.9594
focus_mode = 0
enabled_focus_mode = 0
text = "Hide trees and blobs"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Nodes" type="Control" parent="."]
[node name="Nodes" type="Control" parent="VSplitContainer/RepoVis"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="FileBrowser" parent="VSplitContainer" instance=ExtResource( 4 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 906.0
margin_right = 1920.0
margin_bottom = 1080.0
size_flags_vertical = 3
size_flags_stretch_ratio = 0.2
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
[connection signal="pressed" from="Button" to="." method="update_everything"]
[connection signal="toggled" from="SimplifyCheckbox" to="." method="simplify_view"]
[connection signal="pressed" from="VSplitContainer/RepoVis/Button" to="." method="update_everything"]
[connection signal="toggled" from="VSplitContainer/RepoVis/SimplifyCheckbox" to="." method="simplify_view"]

14
scripts/fake-editor-noblock Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env perl
use IO::Socket;
$socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1",
PeerPort => 1234,
Proto => "tcp",
Type => SOCK_STREAM);
# Send the length of the first argument as a byte.
$socket->send(chr(length($ARGV[0])));
# Send the first argument as a string.
$socket->send($ARGV[0]);

View file

@ -16,8 +16,7 @@ func _process(_delta):
var length = _client_connection.get_u8()
var filename = _client_connection.get_string(length)
var regex = RegEx.new()
regex.compile("(\\.git\\/.*)")
filename = regex.search(filename).get_string()
filename = filename.replace("/tmp/active/", "")
open(filename)
func open(filename):