From 563f6ba835d7ca9d3499b54591d85d832dd7d68b Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 10 Nov 2020 18:22:24 +0100 Subject: [PATCH] Delete Files via Popup Menue --- scenes/file_browser.gd | 14 ++++++++++---- scenes/file_browser_item.gd | 9 +++++++++ scenes/file_browser_item.tscn | 5 +++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index 4fa21fc..7502f12 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -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() diff --git a/scenes/file_browser_item.gd b/scenes/file_browser_item.gd index 4a2bea6..8f7456d 100644 --- a/scenes/file_browser_item.gd +++ b/scenes/file_browser_item.gd @@ -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) diff --git a/scenes/file_browser_item.tscn b/scenes/file_browser_item.tscn index 09193ac..6880bd5 100644 --- a/scenes/file_browser_item.tscn +++ b/scenes/file_browser_item.tscn @@ -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"]