mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-20 16:20:18 +01:00
Have a file browser in each commit, which shows its content
This commit is contained in:
parent
006e4ba338
commit
6f2700d7fb
4 changed files with 63 additions and 21 deletions
|
@ -1,34 +1,62 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
enum FileBrowserMode {
|
||||||
|
WORKING_DIRECTORY,
|
||||||
|
COMMIT,
|
||||||
|
INDEX
|
||||||
|
}
|
||||||
|
|
||||||
|
export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY
|
||||||
|
|
||||||
var shell
|
var shell
|
||||||
var thread
|
var commit setget _set_commit
|
||||||
|
|
||||||
onready var grid = $Panel/Margin/Rows/Scroll/Grid
|
onready var grid = $Panel/Margin/Rows/Scroll/Grid
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
update()
|
||||||
|
|
||||||
func update():
|
func update():
|
||||||
for item in grid.get_children():
|
if grid:
|
||||||
item.queue_free()
|
for item in grid.get_children():
|
||||||
|
item.queue_free()
|
||||||
var file_string = shell.run("find . -type f")
|
|
||||||
var files = file_string.split("\n")
|
match mode:
|
||||||
files = Array(files)
|
FileBrowserMode.WORKING_DIRECTORY:
|
||||||
# The last entry is an empty string, remove it.
|
if shell:
|
||||||
files.pop_back()
|
var file_string = shell.run("find . -type f")
|
||||||
files.sort_custom(self, "very_best_sort")
|
var files = file_string.split("\n")
|
||||||
for file_path in files:
|
files = Array(files)
|
||||||
file_path = file_path.substr(2)
|
# The last entry is an empty string, remove it.
|
||||||
if file_path.substr(0, 5) == ".git/":
|
files.pop_back()
|
||||||
continue
|
files.sort_custom(self, "very_best_sort")
|
||||||
var item = preload("res://file_browser_item.tscn").instance()
|
for file_path in files:
|
||||||
item.label = file_path
|
file_path = file_path.substr(2)
|
||||||
item.connect("clicked", self, "item_clicked")
|
if file_path.substr(0, 5) == ".git/":
|
||||||
grid.add_child(item)
|
continue
|
||||||
#child.set_editable(0, true)
|
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):
|
func item_clicked(item):
|
||||||
var file_path = item.label
|
var file_path = item.label
|
||||||
shell.run("'%s'/fake-editor-noblock '%s'" % [game.tmp_prefix_inside, file_path])
|
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):
|
func very_best_sort(a,b):
|
||||||
# We're looking at the third character because all entries have the form
|
# We're looking at the third character because all entries have the form
|
||||||
# "./.git/bla".
|
# "./.git/bla".
|
||||||
|
|
|
@ -8,7 +8,7 @@ anchor_right = 0.052
|
||||||
anchor_bottom = 0.093
|
anchor_bottom = 0.093
|
||||||
margin_right = 100.16
|
margin_right = 100.16
|
||||||
margin_bottom = -0.439995
|
margin_bottom = -0.439995
|
||||||
rect_min_size = Vector2( 200, 100 )
|
rect_min_size = Vector2( 150, 100 )
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
|
|
3
node.gd
3
node.gd
|
@ -53,6 +53,8 @@ func content_set(new_content):
|
||||||
|
|
||||||
func type_set(new_type):
|
func type_set(new_type):
|
||||||
type = new_type
|
type = new_type
|
||||||
|
if type == "commit":
|
||||||
|
$FileBrowser.commit = self
|
||||||
if type != "ref":
|
if type != "ref":
|
||||||
$ID.text = $ID.text.substr(0,8)
|
$ID.text = $ID.text.substr(0,8)
|
||||||
#elif type == "ref":
|
#elif type == "ref":
|
||||||
|
@ -111,6 +113,7 @@ func _input(event):
|
||||||
if hovered:
|
if hovered:
|
||||||
if event.is_action_pressed("click"):
|
if event.is_action_pressed("click"):
|
||||||
held = true
|
held = true
|
||||||
|
$FileBrowser.visible = not $FileBrowser.visible
|
||||||
elif event.is_action_pressed("right_click"):
|
elif event.is_action_pressed("right_click"):
|
||||||
var input = get_tree().get_current_scene().find_node("Input")
|
var input = get_tree().get_current_scene().find_node("Input")
|
||||||
input.text += id
|
input.text += id
|
||||||
|
|
13
node.tscn
13
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://node.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2]
|
[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/blob.svg" type="Texture" id=3]
|
||||||
[ext_resource path="res://nodes/pop.wav" type="AudioStream" id=4]
|
[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://drop_area.tscn" type="PackedScene" id=5]
|
||||||
|
[ext_resource path="res://file_browser.tscn" type="PackedScene" id=6]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id=1]
|
[sub_resource type="CircleShape2D" id=1]
|
||||||
radius = 23.6295
|
radius = 23.6295
|
||||||
|
@ -79,6 +80,16 @@ custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_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_entered" from="Rect" to="." method="_on_hover"]
|
||||||
[connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"]
|
[connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"]
|
||||||
[connection signal="mouse_entered" from="Area2D" to="." method="_on_hover"]
|
[connection signal="mouse_entered" from="Area2D" to="." method="_on_hover"]
|
||||||
|
|
Loading…
Reference in a new issue