From 833475e80b2124f0caecee2b060ef4548d7553ca Mon Sep 17 00:00:00 2001 From: blinry Date: Wed, 18 Nov 2020 18:36:29 +0100 Subject: [PATCH] Display index versions of items --- scenes/file_browser.gd | 71 ++++++++++++++++++++++++++---------------- scenes/item.gd | 12 +++++-- scenes/text_editor.gd | 1 + 3 files changed, 56 insertions(+), 28 deletions(-) diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index 940b3e7..0a02f0b 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -33,23 +33,23 @@ func _input(event): if event.is_action_pressed("save"): if text_edit.visible: save() - if event.is_action_pressed("down", true): - player.move(Vector2(0,1)) - if event.is_action_pressed("up", true): - player.move(Vector2(0,-1)) - if event.is_action_pressed("right", true): - player.move(Vector2(1,0)) - if event.is_action_pressed("left", true): - player.move(Vector2(-1,0)) - if event.is_action_pressed("pickup"): - if player.held: - player.held = null - else: - for item in world.get_children(): - if item.label != "": - if item.position == player.position: - player.held = item - print("player picked up item " + item.label) +# if event.is_action_pressed("down", true): +# player.move(Vector2(0,1)) +# if event.is_action_pressed("up", true): +# player.move(Vector2(0,-1)) +# if event.is_action_pressed("right", true): +# player.move(Vector2(1,0)) +# if event.is_action_pressed("left", true): +# player.move(Vector2(-1,0)) +# if event.is_action_pressed("pickup"): +# if player.held: +# player.held = null +# else: +# for item in world.get_children(): +# if item.label != "": +# if item.position == player.position: +# player.held = item +# print("player picked up item " + item.label) func clear(): pass @@ -66,6 +66,8 @@ func update(): match mode: FileBrowserMode.WORKING_DIRECTORY: if shell: + # Populate working directory. + var wd_files = Array(shell.run("find . -type f").split("\n")) # The last entry is an empty string, remove it. wd_files.pop_back() @@ -79,22 +81,39 @@ func update(): var files = wd_files + deleted_files files.sort_custom(self, "very_best_sort") - #var is_visible = false for file_path in files: if file_path.substr(0, 5) == ".git/": continue - #is_visible = true var item = preload("res://scenes/item.tscn").instance() item.label = file_path item.file_browser = self - #item.connect("clicked", self, "item_clicked") - #item.connect("deleted", self, "item_deleted") - item.status = get_file_status(file_path, shell, 1) - seed(item.label.hash()) - item.position = Vector2(rand_range(0, world.rect_size.x), rand_range(0, world.rect_size.y)) - randomize() + #item.status = get_file_status(file_path, shell, 1) + item.item_type = "wd" + #seed(item.label.hash()) + #item.position = Vector2(rand_range(0, world.rect_size.x), rand_range(0, world.rect_size.y)) + #randomize() world.add_child(item) - #visible = is_visible + + # Populate index. + + if shell.run("test -d .git && echo yes || echo no") == "yes\n": + var index_files = Array(shell.run("git ls-files -s | cut -f2 | uniq").split("\n")) + #var deleted_files = Array(repository.shell.run("git status -s | grep '^D' | sed 's/^...//'").split("\n")) + # The last entries are empty strings, remove them. + index_files.pop_back() + #deleted_files.pop_back() + files = index_files# + deleted_files + for file_path in files: + var item = preload("res://scenes/item.tscn").instance() + item.label = file_path + item.item_type = "index" + item.type = "nothing" + item.file_browser = self + print(item) + #item.connect("clicked", self, "item_clicked") + #item.status = get_file_status(file_path, repository.shell, 0) + world.add_child(item) + FileBrowserMode.COMMIT: if commit: diff --git a/scenes/item.gd b/scenes/item.gd index 95a6475..9220e4d 100644 --- a/scenes/item.gd +++ b/scenes/item.gd @@ -5,6 +5,7 @@ enum IconStatus {NONE, NEW, REMOVED, CONFLICT, EDIT, UNTRACKED} export(IconStatus) var status setget _set_status export var label: String setget _set_label var type = "file" +var item_type export var editable = true var attributes @@ -26,8 +27,15 @@ func _ready(): #$PopupMenu.add_item("Delete file", 0) func read_from_file(): - print(file_browser) - attributes = helpers.parse(file_browser.shell.run("cat '%s'" % label)) + var content + match item_type: + "wd": + content = file_browser.shell.run("cat '%s'" % label) + "index": + content = file_browser.shell.run("git show :'%s'" % label) + modulate = Color(0, 0, 255.0) + + attributes = helpers.parse(content) position.x = int(attributes["x"]) position.y = int(attributes["y"]) diff --git a/scenes/text_editor.gd b/scenes/text_editor.gd index 2018eec..1b0433c 100644 --- a/scenes/text_editor.gd +++ b/scenes/text_editor.gd @@ -45,6 +45,7 @@ func save(): func close(): if _client_connection and _client_connection.is_connected_to_host(): + _client_connection.put_string(text) _client_connection.disconnect_from_host() text = "" hide()