VariableDialog now reports an error if attempting to name a variable to one that already exists

This commit is contained in:
2023-01-22 09:53:03 -06:00
parent 60356fc7fa
commit 570d965669
2 changed files with 15 additions and 3 deletions

View File

@@ -79,11 +79,22 @@ module TAC
def valid? def valid?
valid = true valid = true
name = @name.value.strip
if @name.value.strip.empty? if name.empty?
@name_error.value = "Error: Name cannot be blank or only whitespace." @name_error.value = "Error: Name cannot be blank or only whitespace."
@name_error.show @name_error.show
valid = false valid = false
### Don't error if renaming variable to itself
elsif @options[:variable] && @options[:variable].name == name
@name_error.value = ""
@name_error.hide
elsif @options[:list].find { |variable| variable.name == name }
@name_error.value = "Error: Name is not unique!"
@name_error.show
valid = false
end end
if not @type if not @type

View File

@@ -160,7 +160,7 @@ module TAC
label "Variables", text_size: THEME_SUBHEADING_TEXT_SIZE, fill: true, text_align: :center label "Variables", text_size: THEME_SUBHEADING_TEXT_SIZE, fill: true, text_align: :center
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add variable" do button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add variable" do
if @active_action if @active_action
push_state(TAC::Dialog::VariableDialog, title: "Create Variable", callback_method: method(:create_variable)) push_state(TAC::Dialog::VariableDialog, title: "Create Variable", list: @active_action.variables, callback_method: method(:create_variable))
else else
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create variable, no action selected.") push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create variable, no action selected.")
end end
@@ -418,7 +418,7 @@ module TAC
flow(width: 1.0, fill: true) do flow(width: 1.0, fill: true) do
button "#{variable.name}", fill: true, text_size: THEME_ICON_SIZE - 3, tip: "Edit variable" do button "#{variable.name}", fill: true, text_size: THEME_ICON_SIZE - 3, tip: "Edit variable" do
push_state(Dialog::VariableDialog, title: "Edit Variable", variable: variable, callback_method: method(:update_variable)) push_state(Dialog::VariableDialog, title: "Edit Variable", variable: variable, list: @active_action.variables, callback_method: method(:update_variable))
end end
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete variable", **THEME_DANGER_BUTTON do button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete variable", **THEME_DANGER_BUTTON do
@@ -466,6 +466,7 @@ module TAC
push_state( push_state(
TAC::Dialog::VariableDialog, TAC::Dialog::VariableDialog,
title: "Create Variable", title: "Create Variable",
list: @active_action.variables,
callback_method: method(:create_variable) callback_method: method(:create_variable)
) )
else else