Display index versions of items

This commit is contained in:
blinry 2020-11-18 18:36:29 +01:00
parent e635efa796
commit 833475e80b
3 changed files with 56 additions and 28 deletions

View file

@ -33,23 +33,23 @@ func _input(event):
if event.is_action_pressed("save"): if event.is_action_pressed("save"):
if text_edit.visible: if text_edit.visible:
save() save()
if event.is_action_pressed("down", true): # if event.is_action_pressed("down", true):
player.move(Vector2(0,1)) # player.move(Vector2(0,1))
if event.is_action_pressed("up", true): # if event.is_action_pressed("up", true):
player.move(Vector2(0,-1)) # player.move(Vector2(0,-1))
if event.is_action_pressed("right", true): # if event.is_action_pressed("right", true):
player.move(Vector2(1,0)) # player.move(Vector2(1,0))
if event.is_action_pressed("left", true): # if event.is_action_pressed("left", true):
player.move(Vector2(-1,0)) # player.move(Vector2(-1,0))
if event.is_action_pressed("pickup"): # if event.is_action_pressed("pickup"):
if player.held: # if player.held:
player.held = null # player.held = null
else: # else:
for item in world.get_children(): # for item in world.get_children():
if item.label != "": # if item.label != "":
if item.position == player.position: # if item.position == player.position:
player.held = item # player.held = item
print("player picked up item " + item.label) # print("player picked up item " + item.label)
func clear(): func clear():
pass pass
@ -66,6 +66,8 @@ func update():
match mode: match mode:
FileBrowserMode.WORKING_DIRECTORY: FileBrowserMode.WORKING_DIRECTORY:
if shell: if shell:
# Populate working directory.
var wd_files = Array(shell.run("find . -type f").split("\n")) var wd_files = Array(shell.run("find . -type f").split("\n"))
# The last entry is an empty string, remove it. # The last entry is an empty string, remove it.
wd_files.pop_back() wd_files.pop_back()
@ -79,22 +81,39 @@ func update():
var files = wd_files + deleted_files var files = wd_files + deleted_files
files.sort_custom(self, "very_best_sort") files.sort_custom(self, "very_best_sort")
#var is_visible = false
for file_path in files: for file_path in files:
if file_path.substr(0, 5) == ".git/": if file_path.substr(0, 5) == ".git/":
continue continue
#is_visible = true
var item = preload("res://scenes/item.tscn").instance() var item = preload("res://scenes/item.tscn").instance()
item.label = file_path item.label = file_path
item.file_browser = self item.file_browser = self
#item.connect("clicked", self, "item_clicked") #item.status = get_file_status(file_path, shell, 1)
#item.connect("deleted", self, "item_deleted") item.item_type = "wd"
item.status = get_file_status(file_path, shell, 1) #seed(item.label.hash())
seed(item.label.hash()) #item.position = Vector2(rand_range(0, world.rect_size.x), rand_range(0, world.rect_size.y))
item.position = Vector2(rand_range(0, world.rect_size.x), rand_range(0, world.rect_size.y)) #randomize()
randomize()
world.add_child(item) 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: FileBrowserMode.COMMIT:
if commit: if commit:

View file

@ -5,6 +5,7 @@ enum IconStatus {NONE, NEW, REMOVED, CONFLICT, EDIT, UNTRACKED}
export(IconStatus) var status setget _set_status export(IconStatus) var status setget _set_status
export var label: String setget _set_label export var label: String setget _set_label
var type = "file" var type = "file"
var item_type
export var editable = true export var editable = true
var attributes var attributes
@ -26,8 +27,15 @@ func _ready():
#$PopupMenu.add_item("Delete file", 0) #$PopupMenu.add_item("Delete file", 0)
func read_from_file(): func read_from_file():
print(file_browser) var content
attributes = helpers.parse(file_browser.shell.run("cat '%s'" % label)) 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.x = int(attributes["x"])
position.y = int(attributes["y"]) position.y = int(attributes["y"])

View file

@ -45,6 +45,7 @@ func save():
func close(): func close():
if _client_connection and _client_connection.is_connected_to_host(): if _client_connection and _client_connection.is_connected_to_host():
_client_connection.put_string(text)
_client_connection.disconnect_from_host() _client_connection.disconnect_from_host()
text = "" text = ""
hide() hide()