oh-my-git/scenes/file_browser_item.gd

91 lines
3.1 KiB
GDScript3
Raw Permalink Normal View History

2020-11-03 16:39:55 +01:00
class_name FileBrowserItem
extends Control
signal clicked(what)
2020-11-10 18:22:24 +01:00
signal deleted(what)
2023-09-06 16:04:23 +02:00
@export var label: String: set = _set_label
var type = "file"
var repository
2023-09-06 16:04:23 +02:00
@onready var label_node = $VBoxContainer/Label
func _ready():
_set_label(label)
#$PopupMenu.add_item("Delete file", 0)
2023-09-07 14:45:52 +02:00
var exists_in_wd = (await repository.shell.run("test -f '%s' && echo yes || echo no" % label)) == "yes\n"
var exists_in_index = (await repository.shell.run("git ls-files --error-unmatch '%s' &>/dev/null && echo yes || echo no" % label)) == "yes\n"
var exists_in_head = (await repository.shell.run("git cat-file -e HEAD:'%s' &>/dev/null && echo yes || echo no" % label)) == "yes\n"
2023-09-07 14:45:52 +02:00
var wd_hash = await repository.shell.run("git hash-object '%s' 2>/dev/null || true" % label)
var index_hash = await repository.shell.run("git ls-files -s '%s' | cut -f2 -d' '" % label)
var head_hash = await repository.shell.run("git ls-tree HEAD '%s' | cut -f1 | cut -f3 -d' '" % label)
var conflict = Array(index_hash.split("\n")).size() > 2
var offset_index = 0
var offset_wd = 0
var offset = 10
if exists_in_index and exists_in_head and index_hash != head_hash:
offset_index += 1
if exists_in_wd and exists_in_head and wd_hash != head_hash:
offset_wd += 1
if exists_in_wd and exists_in_index and wd_hash != index_hash and offset_index == offset_wd:
offset_wd += 1
2023-09-06 16:04:23 +02:00
$VBoxContainer/Control/Index.position.x += offset_index*offset
$VBoxContainer/Control/Index.position.y -= offset_index*offset
2023-09-06 16:04:23 +02:00
$VBoxContainer/Control/WD.position.x += offset_wd*offset
$VBoxContainer/Control/WD.position.y -= offset_wd*offset
if conflict:
$VBoxContainer/Control/Index.self_modulate = Color(1, 0.2, 0.2, 0.5)
$VBoxContainer/Control/HEAD.visible = exists_in_head
$VBoxContainer/Control/Index.visible = exists_in_index
$VBoxContainer/Control/WD.visible = exists_in_wd
func _set_label(new_label):
label = new_label
if label_node:
label_node.text = helpers.abbreviate(new_label, 30)
func _gui_input(event):
2023-09-06 16:04:23 +02:00
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
emit_signal("clicked", self)
# if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_RIGHT and status != IconStatus.REMOVED:
# $PopupMenu.set_position(get_global_mouse_position())
# $PopupMenu.popup()
2020-11-03 16:39:55 +01:00
#func _set_status(new_status):
# if status_icon:
# match new_status:
# IconStatus.NEW:
# status_icon.texture = preload("res://images/new.svg")
# status_icon.modulate = Color("33BB33")
# IconStatus.REMOVED:
# status_icon.texture = preload("res://images/removed.svg")
# status_icon.modulate = Color("D10F0F")
# IconStatus.CONFLICT:
# status_icon.texture = preload("res://images/conflict.svg")
# status_icon.modulate = Color("DE5E09")
# IconStatus.EDIT:
# status_icon.texture = preload("res://images/modified.svg")
# status_icon.modulate = Color("344DED")
# IconStatus.UNTRACKED:
# status_icon.texture = preload("res://images/untracked.svg")
# status_icon.modulate = Color("9209B8")
# IconStatus.NONE:
# status_icon.texture = null
#
# status = new_status
#
2020-11-10 18:22:24 +01:00
2020-11-10 22:37:10 +01:00
func _popup_menu_pressed(_id):
2020-11-10 18:22:24 +01:00
emit_signal("deleted", self)