2020-09-22 14:15:36 +03:00
|
|
|
extends Control
|
|
|
|
|
2020-10-23 16:08:51 +03:00
|
|
|
enum FileBrowserMode {
|
|
|
|
WORKING_DIRECTORY,
|
|
|
|
COMMIT,
|
|
|
|
INDEX
|
|
|
|
}
|
|
|
|
|
|
|
|
export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY
|
|
|
|
|
2020-09-22 14:15:36 +03:00
|
|
|
var shell
|
2020-10-23 16:08:51 +03:00
|
|
|
var commit setget _set_commit
|
2020-10-23 16:19:25 +03:00
|
|
|
var repository
|
2020-09-22 14:15:36 +03:00
|
|
|
|
2020-10-23 14:07:16 +03:00
|
|
|
onready var grid = $Panel/Margin/Rows/Scroll/Grid
|
2020-09-22 14:15:36 +03:00
|
|
|
|
2020-10-23 16:08:51 +03:00
|
|
|
func _ready():
|
|
|
|
update()
|
2020-10-23 16:19:25 +03:00
|
|
|
|
|
|
|
func clear():
|
|
|
|
for item in grid.get_children():
|
|
|
|
item.queue_free()
|
|
|
|
|
2020-09-22 14:15:36 +03:00
|
|
|
func update():
|
2020-10-23 16:08:51 +03:00
|
|
|
if grid:
|
2020-10-23 16:19:25 +03:00
|
|
|
clear()
|
2020-10-23 16:08:51 +03:00
|
|
|
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
|
2020-10-23 16:19:25 +03:00
|
|
|
#item.connect("clicked", self, "item_clicked")
|
|
|
|
grid.add_child(item)
|
|
|
|
FileBrowserMode.INDEX:
|
|
|
|
if repository:
|
|
|
|
var files = Array(repository.shell.run("git ls-files -s | cut -f2").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")
|
2020-10-23 16:08:51 +03:00
|
|
|
grid.add_child(item)
|
2020-09-22 14:15:36 +03:00
|
|
|
|
2020-10-23 14:07:16 +03:00
|
|
|
func item_clicked(item):
|
|
|
|
var file_path = item.label
|
2020-10-06 17:50:31 +03:00
|
|
|
shell.run("'%s'/fake-editor-noblock '%s'" % [game.tmp_prefix_inside, file_path])
|
2020-10-23 14:07:16 +03:00
|
|
|
|
2020-10-23 16:08:51 +03:00
|
|
|
func _set_commit(new_commit):
|
|
|
|
commit = new_commit
|
|
|
|
update()
|
|
|
|
|
2020-09-22 16:50:57 +03:00
|
|
|
func very_best_sort(a,b):
|
|
|
|
# We're looking at the third character because all entries have the form
|
|
|
|
# "./.git/bla".
|
|
|
|
if a.substr(2, 1) == "." and b.substr(2, 1) != ".":
|
|
|
|
return false
|
|
|
|
if a.substr(2, 1) != "." and b.substr(2, 1) == ".":
|
|
|
|
return true
|
|
|
|
return a.casecmp_to(b) == -1
|