diff options
| author | dam <dam@gudinoff> | 2022-01-04 22:34:48 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-01-04 22:34:48 +0000 |
| commit | 06b2f34ba64726028f494060376044531d763668 (patch) | |
| tree | 414d171e5b73c916eadfdd753a1c1b1eac38713e /menu | |
| parent | 73f2cf39d5514fab4ee994f303e250ce2b27307c (diff) | |
| download | surgery-log-06b2f34ba64726028f494060376044531d763668.tar.zst surgery-log-06b2f34ba64726028f494060376044531d763668.zip | |
Implement clear and export data actions.
Merge and reuse modal dialogs.
Diffstat (limited to 'menu')
| -rw-r--r-- | menu/menu.gd | 126 |
1 files changed, 60 insertions, 66 deletions
diff --git a/menu/menu.gd b/menu/menu.gd index 36beee8..3384436 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -4,100 +4,94 @@ const menu_items: Array = [ { label = "IMPORT FILTERS", action = "_menu_import_filters_action" }, { label = "EXPORT FILTERS", action = "_menu_export_filters_action" }, { label = "CLEAR FILTERS", action = "_menu_clear_filters_action" }, + { label = "EXPORT DATA", action = "_menu_export_data_action" }, + { label = "CLEAR DATA", action = "_menu_clear_data_action" }, { label = "ABOUT", action = "_menu_about_action" }, { label = "FAKE_DB", action = "_menu_fake_db_action" }, ] const license_font_b612: String = "res://licenses/font_b612.txt" const license_godot: String = "res://licenses/godot.txt" -onready var popup: PopupMenu = get_popup() -onready var debug: Label = get_node("/root/main/debug") as Label +onready var popup := get_popup() as PopupMenu +onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog +onready var file_picker := get_node("/root/main/file_picker") as FileDialog +onready var database := get_node("/root/main/database") as Database + func _ready(): - for idx in range(menu_items.size()): popup.add_item(menu_items[idx].label, idx) popup.connect("id_pressed", self, "id_pressed") - -# load_file(file) - + file_picker.get_cancel().connect("pressed", self, "dialog_cancelled", ["file_selected"]) + confirm_action.get_cancel().connect("pressed", self, "dialog_cancelled", ["confirmed"]) func id_pressed(id: int): - debug.text += "'%d':'%s'" % [id, menu_items[id].action] self.call_deferred(menu_items[id].action) - debug.text += "!\n" -var csv_file: Array -var has_permissions := false +func dialog_cancelled(confirmation_signal_name: String): + var confirmation_handlers = confirm_action.get_signal_connection_list(confirmation_signal_name) + for it in confirmation_handlers: + confirm_action.disconnect(it.signal, it.target, it.method) + + func _menu_import_filters_action(): - -# printerr("pressed: %s" % get_stack()[0]); - debug.text += "> import: " - - if OS.get_name() == "Android": - while not has_permissions: - var permissions := Array(OS.get_granted_permissions()) - if not permissions.has("android.permission.READ_EXTERNAL_STORAGE") \ - or not permissions.has("android.permission.WRITE_EXTERNAL_STORAGE"): - OS.request_permissions() - # await get_tree().create_timer(1).timeout - yield(get_tree().create_timer(1), "timeout") # - for Godot 3 branch - else: - has_permissions = true - - - - var file_dialog := get_node("/root/main/import_filters") as FileDialog - file_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) - file_dialog.connect("file_selected", self, "file_selected", [], CONNECT_ONESHOT) - file_dialog.show_modal(true) - file_dialog.invalidate() -# printerr("download: '%s'" % OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)) - -func file_selected(path: String): - debug.text += "'%s'\n" % path - - var file = File.new() - file.open(path, File.READ) - while file.eof_reached() == false: - var line = file.get_line() - csv_file.append(line) - printerr("%s" % line) - file.close() + return + file_picker.window_title = "IMPORT FILTERS" + file_picker.mode = FileDialog.MODE_OPEN_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) +# file_picker.connect("file_selected", filters, "TODO", [], CONNECT_ONESHOT) +# file_picker.show_modal(true) +# file_picker.invalidate() + func _menu_export_filters_action(): - debug.text += "> export: \n" -# printerr("pressed: %s" % get_stack()[0]); - var file_dialog := get_node("/root/main/export_filters") as FileDialog - file_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) - file_dialog.connect("file_selected", self, "file_selected_export", [], CONNECT_ONESHOT) - file_dialog.show_modal(true) - file_dialog.invalidate() - -func file_selected_export(path: String): - debug.text += "'%s'\n" % path - var file = File.new() - file.open(path, File.WRITE) - for ln in csv_file: - file.store_line(ln) - file.close() + return + file_picker.window_title = "EXPORT FILTERS" + file_picker.mode = FileDialog.MODE_SAVE_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) +# file_picker.connect("file_selected", filters, "TODO", [], CONNECT_ONESHOT) +# file_picker.show_modal(true) +# file_picker.invalidate() func _menu_clear_filters_action(): - debug.text += "> clear\n" -# printerr("pressed: %s" % get_stack()[0]); - (get_node("/root/main/delete_filters") as ConfirmationDialog).show_modal(true) + return + confirm_action.window_title = "CLEAR FILTERS" + confirm_action.dialog_text = "Do you want to delete all filters?" +# confirm_action.connect("confirmed", filters, "TDO", [true], CONNECT_ONESHOT) +# confirm_action.show_modal(true) + + +func _menu_export_data_action(): + file_picker.window_title = "EXPORT DATA" + file_picker.mode = FileDialog.MODE_SAVE_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) + file_picker.connect("file_selected", database, "store_database", [], CONNECT_ONESHOT) + file_picker.show_modal(true) + file_picker.invalidate() + + +func _menu_clear_data_action(): + confirm_action.window_title = "CLEAR DATA" + confirm_action.dialog_text = "Do you want to delete all entries from the database?" + confirm_action.connect("confirmed", database, "clear_database", [true], CONNECT_ONESHOT) + confirm_action.show_modal(true) func _menu_about_action(): -# printerr("pressed: %s" % get_stack()[0]); - debug.text += "> about\n" - (get_node("/root/main/about") as AcceptDialog).show_modal() + confirm_action.window_title = "FAKE DB" + confirm_action.dialog_text = "About text here!" +# confirm_action.connect("confirmed", database, "fake_database", [true], CONNECT_ONESHOT) + confirm_action.show_modal(true) + func _menu_fake_db_action(): - get_node("/root/main/database").fake_database() + confirm_action.window_title = "FAKE DB" + confirm_action.dialog_text = "Do you want to delete all entries from the database and replace by fake entries?" + confirm_action.connect("confirmed", database, "fake_database", [true], CONNECT_ONESHOT) + confirm_action.show_modal(true) |
