diff options
| author | dam <dam@gudinoff> | 2022-04-06 22:52:14 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-04-06 22:52:14 +0000 |
| commit | 1fe674aec4bd6ce3fc666c8545dadb4f0614067d (patch) | |
| tree | 949a5ff1380bf82edaf387a5b4e04d0a4bf9d46a /menu/menu.gd | |
| parent | 0f1adc3bb1f41b5dd3490f176a5eee2c17007923 (diff) | |
| download | surgery-log-1fe674aec4bd6ce3fc666c8545dadb4f0614067d.tar.zst surgery-log-1fe674aec4bd6ce3fc666c8545dadb4f0614067d.zip | |
Improved file operations for database and option sets.
Added confirmation dialogs when importing database and option sets files.
Standardized the error print calls.
Fixed capitalization on menu entries.
Diffstat (limited to 'menu/menu.gd')
| -rw-r--r-- | menu/menu.gd | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/menu/menu.gd b/menu/menu.gd index 5f13949..735f86a 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -1,12 +1,13 @@ extends MenuButton const menu_items: Array = [ - { label = "IMPORT OPTION SETS", action = "import_option_sets_action" }, - { label = "EXPORT OPTION SETS", action = "export_option_sets_action" }, - { label = "CLEAR OPTION SETS", action = "clear_option_sets_action" }, - { label = "EXPORT DATA", action = "export_data_action" }, - { label = "CLEAR DATA", action = "clear_data_action" }, - { label = "ABOUT", action = "about_action" }, + { label = "Import Option Sets", action = "import_option_sets_action" }, + { label = "Export Option Sets", action = "export_option_sets_action" }, + { label = "Clear Option Sets", action = "clear_option_sets_action" }, + { label = "Import Database", action = "import_database_action" }, + { label = "Export Database", action = "export_database_action" }, + { label = "Clear Database", action = "clear_database_action" }, + { label = "About", action = "about_action" }, { label = "TEST_FAKE_DB", action = "test_fake_db_action" }, ] const license_font_b612: String = "res://licenses/font_b612.txt" @@ -31,39 +32,27 @@ func id_pressed(id: int): func import_option_sets_action(): + dialog.setup("All option sets from the dropdown menus will be replaced.", "Continue", "No") + dialog.connect("accepted", self, "import_option_sets_action_accepted") + popup.open_popup("Replace option sets?", dialog) + + +func import_option_sets_action_accepted(): file_picker.mode = FileDialog.MODE_OPEN_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.json", "*.csv"] file_picker.current_file = "" - file_picker.connect("file_selected", self, "import_option_sets_action_confirmed") + file_picker.connect("file_selected", stage, "load_option_sets") file_picker.show_modal(true) file_picker.invalidate() -func import_option_sets_action_confirmed(file_path: String): - match file_path.get_extension(): - "json": - stage.load_option_sets(file_path) - stage.sanitize_option_sets(stage.option_sets) - stage.save_option_sets() - - "csv": - var database := Database.import_database(file_path) - for it in database: - stage.gather_option_sets(it) - stage.save_option_sets() - - _: - push_error("Invalid file extension selected to be parsed for option sets: '%s'." % file_path.get_file()) - return - - func export_option_sets_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.json"] file_picker.current_file = "" - file_picker.connect("file_selected", stage, "save_option_sets", [], CONNECT_ONESHOT) + file_picker.connect("file_selected", stage, "save_option_sets") file_picker.show_modal(true) file_picker.invalidate() @@ -74,17 +63,33 @@ func clear_option_sets_action(): popup.open_popup("Clear option sets?", dialog) -func export_data_action(): +func import_database_action(): + dialog.setup("All entries from the database will be replaced.", "Continue", "No") + dialog.connect("accepted", self, "import_database_action_accepted") + popup.open_popup("Replace database?", dialog) + + +func import_database_action_accepted(): + file_picker.mode = FileDialog.MODE_OPEN_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) + file_picker.filters = ["*.json", "*.csv"] + file_picker.current_file = "" + file_picker.connect("file_selected", database, "load_database") + file_picker.show_modal(true) + file_picker.invalidate() + + +func export_database_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters = ["*.csv"] file_picker.current_file = "" - file_picker.connect("file_selected", database, "save_database", [], CONNECT_ONESHOT) + file_picker.connect("file_selected", database, "save_database") file_picker.show_modal(true) file_picker.invalidate() -func clear_data_action(): +func clear_database_action(): dialog.setup("All entries from the database will be deleted.", "Delete all", "No") dialog.connect("accepted", database, "clear_database") popup.open_popup("Clear database?", dialog) |
