mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 16:20:19 +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 update():
|
func _ready():
|
||||||
for item in grid.get_children():
|
update()
|
||||||
item.queue_free()
|
|
||||||
|
|
||||||
var file_string = shell.run("find . -type f")
|
func update():
|
||||||
var files = file_string.split("\n")
|
if grid:
|
||||||
files = Array(files)
|
for item in grid.get_children():
|
||||||
# The last entry is an empty string, remove it.
|
item.queue_free()
|
||||||
files.pop_back()
|
|
||||||
files.sort_custom(self, "very_best_sort")
|
match mode:
|
||||||
for file_path in files:
|
FileBrowserMode.WORKING_DIRECTORY:
|
||||||
file_path = file_path.substr(2)
|
if shell:
|
||||||
if file_path.substr(0, 5) == ".git/":
|
var file_string = shell.run("find . -type f")
|
||||||
continue
|
var files = file_string.split("\n")
|
||||||
var item = preload("res://file_browser_item.tscn").instance()
|
files = Array(files)
|
||||||
item.label = file_path
|
# The last entry is an empty string, remove it.
|
||||||
item.connect("clicked", self, "item_clicked")
|
files.pop_back()
|
||||||
grid.add_child(item)
|
files.sort_custom(self, "very_best_sort")
|
||||||
#child.set_editable(0, true)
|
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):
|
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