delete groups

This commit is contained in:
Lera Elvoé 2023-05-27 06:08:36 +03:00
parent 97b1aad886
commit ee5f270bbe
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
2 changed files with 16 additions and 4 deletions

View File

@ -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)

View File

@ -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()