From cc3f6e5ea29bfe006576a35b5fa24d029a07cf7c Mon Sep 17 00:00:00 2001 From: dam Date: Wed, 9 Feb 2022 00:21:59 +0000 Subject: Add confirmation dialog to entry destructive actions. --- logic/database.gd | 8 ++++++++ logic/stage.gd | 27 ++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'logic') diff --git a/logic/database.gd b/logic/database.gd index 3c2d6b7..1518490 100644 --- a/logic/database.gd +++ b/logic/database.gd @@ -7,6 +7,7 @@ var db: Array var selected_idx: int var staged_idx: int +onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog onready var stage := get_node("/root/main/stage") as Stage onready var delete_button := get_node("actions/delete") as Button onready var edit_button := get_node("actions/edit") as Button @@ -65,6 +66,13 @@ func delete_action(): if selected_idx < 0: return + confirm_action.window_title = "DELETE ENTRY" + confirm_action.dialog_text = "Do you want to delete entry with process ID '%s' from the database?" % db[selected_idx].process_id + confirm_action.connect("confirmed", self, "delete_action_confirmed", [], CONNECT_ONESHOT) + confirm_action.show_modal(true) + + +func delete_action_confirmed(): db.remove(selected_idx) self.remove_item(selected_idx) selected_idx = -1 diff --git a/logic/stage.gd b/logic/stage.gd index 1352816..6f46489 100644 --- a/logic/stage.gd +++ b/logic/stage.gd @@ -19,8 +19,10 @@ const OPTION_SETS_TREE_STRUCTURE := { } } +var staged_entry_hash: int var option_sets: Dictionary +onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog onready var process_id := get_node("controls/process_id") as LineEdit onready var surgery_id := get_node("controls/surgery_id") as LineEdit onready var date := get_node("controls/date_picker") as DatePicker @@ -65,8 +67,8 @@ func _ready(): "intervention": intervention } for key in option_sets_map: - var button := option_sets_map[key].get_node("auto") as Button - button.connect("pressed", self, "auto_populate", [key]) + var button := option_sets_map[key].get_node("option_set") as Button + button.connect("pressed", self, "show_option_sets", [key]) func get_option_sets(field: String): @@ -86,13 +88,13 @@ func get_option_sets(field: String): return options -func auto_populate(field: String): +func show_option_sets(field: String): var stage_options = get_node("/root/main/popup_list") as Popup - stage_options.connect("item_selected", self, "auto_selected", [field], CONNECT_ONESHOT) + stage_options.connect("item_selected", self, "option_set_selected", [field], CONNECT_ONESHOT) stage_options.popup_options(get_option_sets(field)) -func auto_selected(index: int, field: String): +func option_set_selected(index: int, field: String): var field_input: LineEdit = self[field] field_input.text = get_option_sets(field)[index] field_input.caret_position = field_input.text.length() @@ -107,11 +109,22 @@ func save_action(): func discard_action(): + if get_stage().hash() != staged_entry_hash: + confirm_action.window_title = "DISCARD ENTRY" + confirm_action.dialog_text = "Do you want to discard the changes made?" + confirm_action.connect("confirmed", self, "discard_action_confirmed", [], CONNECT_ONESHOT) + confirm_action.show_modal(true) + else: + discard_action_confirmed() + + +func discard_action_confirmed(): self.visible = false emit_signal("discard") func set_stage(entry: Dictionary): + staged_entry_hash = entry.hash() process_id.text = entry.process_id surgery_id.text = entry.surgery_id date.set_date(entry.date_year, entry.date_month, entry.date_day) @@ -225,8 +238,8 @@ func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData var button: Button if target is Button: button = target - elif target.get_node("auto") is Button: - button = target.get_node("auto") + elif target.get_node("option_set") is Button: + button = target.get_node("option_set") if button != null && button.get_global_rect().has_point(pointer.current_position): if button is CheckBox || button is CheckButton: -- cgit v1.2.3