oh-my-git/scenes/file_browser_item.gd

59 lines
1.8 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)
2020-11-03 16:39:55 +01:00
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"
onready var label_node = $VBoxContainer/Label
2020-11-03 16:39:55 +01:00
onready var status_icon = $VBoxContainer/Control/TextureRect/StatusIcon
func _ready():
_set_label(label)
2020-11-03 16:39:55 +01:00
_set_status(status)
2020-11-10 18:34:51 +01:00
$PopupMenu.add_item("Delete file", 0)
func _set_label(new_label):
label = new_label
if label_node:
label_node.text = helpers.abbreviate(new_label, 30)
func _gui_input(event):
if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT:
emit_signal("clicked", self)
2020-11-10 18:22:24 +01:00
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)