From ee5f270bbe920f0c84711f057301853f241321c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sat, 27 May 2023 06:08:36 +0300 Subject: [PATCH] delete groups --- Classes/GroupsInstallsManager.gd | 13 +++++++++++-- UI/Components/GroupMenu.gd | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Classes/GroupsInstallsManager.gd b/Classes/GroupsInstallsManager.gd index 4671570..0c3911b 100644 --- a/Classes/GroupsInstallsManager.gd +++ b/Classes/GroupsInstallsManager.gd @@ -4,7 +4,7 @@ const GROUPS_BASE_FOLDER := "user://groups" const METADATA_FILENAME := "meta.tres" # key: GroupMetadata -# values: String = UUID +# value: String = UUID var groups: Dictionary = {} @@ -13,7 +13,7 @@ func _ready() -> void: func create_group_folder(gm: GroupMetadata) -> void: - if gm in groups.values(): + if gm in groups: return var folder_name := UUID.v4() @@ -24,6 +24,15 @@ func create_group_folder(gm: GroupMetadata) -> void: gm.save_request.connect(group_metadata_should_save.bind(gm)) +func delete_group_folder(gm: GroupMetadata) -> void: + if !groups.has(gm): + return + + var path := ProjectSettings.globalize_path(GROUPS_BASE_FOLDER.path_join(groups[gm])) + OS.move_to_trash(path) + groups.erase(gm) + + func group_metadata_should_save(gm: GroupMetadata) -> void: var path := GROUPS_BASE_FOLDER.path_join(groups[gm]).path_join(METADATA_FILENAME) var save_err := ResourceSaver.save(gm, path) diff --git a/UI/Components/GroupMenu.gd b/UI/Components/GroupMenu.gd index 2ff8238..6dc7080 100644 --- a/UI/Components/GroupMenu.gd +++ b/UI/Components/GroupMenu.gd @@ -25,7 +25,6 @@ var group_metadata: GroupMetadata signal add_install_button_pressed signal edit_group_button_pressed -signal delete_button_pressed func _ready() -> void: @@ -39,7 +38,7 @@ func _ready() -> void: install_edit_dialog.canceled.connect(install_edit_dialog.clear_ok_button_connections) # edit_group_button.pressed.connect(setup_rename) edit_group_button.pressed.connect(func(): edit_group_button_pressed.emit()) - delete_group_button.pressed.connect(func(): delete_button_pressed.emit()) + delete_group_button.pressed.connect(_on_delete_button_pressed) header_text_label.gui_input.connect(_on_header_text_label_gui_input) @@ -168,3 +167,7 @@ func _on_header_text_label_gui_input(event: InputEvent) -> void: get_viewport().set_input_as_handled() setup_rename() + +func _on_delete_button_pressed() -> void: + GroupsInstallsManager.delete_group_folder(group_metadata) + queue_free()