Delete Files via Popup Menue

This commit is contained in:
bleeptrack 2020-11-10 18:22:24 +01:00
parent 107d6f8fb1
commit 563f6ba835
3 changed files with 24 additions and 4 deletions

View file

@ -48,9 +48,11 @@ func update():
wd_files.pop_back()
wd_files = helpers.map(wd_files, self, "substr2")
var deleted_files = Array(shell.run("git status -s | grep '^.D' | sed -r 's/^...//'").split("\n"))
deleted_files.pop_back()
var deleted_files = []
if shell.run("test -d .git && echo yes || echo no") == "yes\n":
deleted_files = Array(shell.run("git status -s | grep '^.D' | sed -r 's/^...//'").split("\n"))
deleted_files.pop_back()
var files = wd_files + deleted_files
files.sort_custom(self, "very_best_sort")
@ -62,7 +64,7 @@ func update():
var item = preload("res://scenes/file_browser_item.tscn").instance()
item.label = file_path
item.connect("clicked", self, "item_clicked")
item.connect("deleted", self, "item_deleted")
item.status = get_file_status(file_path, shell, 1)
grid.add_child(item)
@ -133,6 +135,10 @@ func item_clicked(item):
open_file = item.label
text_edit.show()
text_edit.grab_focus()
func item_deleted(item):
helpers.careful_delete(shell._cwd + item.label)
update()
func close():
text_edit.hide()

View file

@ -2,6 +2,7 @@ class_name FileBrowserItem
extends Control
signal clicked(what)
signal deleted(what)
enum IconStatus {NONE, NEW, REMOVED, CONFLICT, EDIT, UNTRACKED}
export(IconStatus) var status setget _set_status
@ -14,6 +15,7 @@ onready var status_icon = $VBoxContainer/Control/TextureRect/StatusIcon
func _ready():
_set_label(label)
_set_status(status)
$PopupMenu.add_item("Delete File", 0)
func _set_label(new_label):
label = new_label
@ -23,6 +25,9 @@ func _set_label(new_label):
func _gui_input(event):
if event is InputEventMouseButton and event.is_pressed() and event.button_index == 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()
func _set_status(new_status):
if status_icon:
@ -47,3 +52,7 @@ func _set_status(new_status):
status = new_status
func _popup_menu_pressed(id):
emit_signal("deleted", self)

View file

@ -92,3 +92,8 @@ custom_fonts/font = ExtResource( 2 )
text = "filename"
align = 1
autowrap = true
[node name="PopupMenu" type="PopupMenu" parent="."]
margin_right = 20.0
margin_bottom = 20.0
[connection signal="id_pressed" from="PopupMenu" to="." method="_popup_menu_pressed"]