mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-16 05:42:35 +00:00
Fixed issues with Action dialog
This commit is contained in:
@@ -4,8 +4,6 @@ module TAC
|
|||||||
def build
|
def build
|
||||||
background Gosu::Color::GRAY
|
background Gosu::Color::GRAY
|
||||||
|
|
||||||
@type = @options[:action].type if @options[:action]
|
|
||||||
|
|
||||||
label "Name"
|
label "Name"
|
||||||
@name_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
@name_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
||||||
@name_error.hide
|
@name_error.hide
|
||||||
@@ -19,7 +17,7 @@ module TAC
|
|||||||
close
|
close
|
||||||
end
|
end
|
||||||
|
|
||||||
button @options[:action] ? "Update" : "Add", width: 0.475 do |b|
|
button @options[:action] ? @options[:accept_label] ? @options[:accept_label] : "Update" : "Add", width: 0.475 do |b|
|
||||||
if valid?
|
if valid?
|
||||||
if @options[:action]
|
if @options[:action]
|
||||||
@options[:callback_method].call(@options[:action], @name.value.strip, @comment.value.strip)
|
@options[:callback_method].call(@options[:action], @name.value.strip, @comment.value.strip)
|
||||||
@@ -35,11 +33,23 @@ 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\n or only whitespace."
|
@name_error.value = "Error: Name cannot be blank\n or only whitespace."
|
||||||
@name_error.show
|
@name_error.show
|
||||||
valid = false
|
valid = false
|
||||||
|
|
||||||
|
### TODO: Handle case when renaming a cloned Action
|
||||||
|
# elsif @options[:action] && @options[:action].name == name
|
||||||
|
# @name_error.value = ""
|
||||||
|
# @name_error.hide
|
||||||
|
|
||||||
|
elsif @options[:list].find { |action| action.name == name}
|
||||||
|
@name_error.value = "Error: Name is not unique!"
|
||||||
|
@name_error.show
|
||||||
|
valid = false
|
||||||
|
|
||||||
else
|
else
|
||||||
@name_error.value = ""
|
@name_error.value = ""
|
||||||
@name_error.hide
|
@name_error.hide
|
||||||
|
|||||||
@@ -40,12 +40,22 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
|
name = @name.value.strip
|
||||||
|
|
||||||
if @name.value.strip.empty?
|
if @name.value.strip.empty?
|
||||||
@name_error.value = "Name cannot be blank.\nName cannot only be whitespace."
|
@name_error.value = "Name cannot be blank.\nName cannot only be whitespace."
|
||||||
@name_error.show
|
@name_error.show
|
||||||
|
|
||||||
return false
|
return false
|
||||||
elsif @options[:list] && @options[:list].find { |i| i.name == @name.value.strip }
|
|
||||||
|
### TODO: Handle case when renaming a cloned Group
|
||||||
|
# elsif @options[:renaming] && @options[:renaming].name == name
|
||||||
|
# @name_error.value = ""
|
||||||
|
# @name_error.hide
|
||||||
|
|
||||||
|
# return true
|
||||||
|
|
||||||
|
elsif @options[:list] && @options[:list].find { |i| i.name == name }
|
||||||
@name_error.value = "Name is not unique!"
|
@name_error.value = "Name is not unique!"
|
||||||
@name_error.show
|
@name_error.show
|
||||||
|
|
||||||
|
|||||||
@@ -125,20 +125,21 @@ module TAC
|
|||||||
label "Actions", text_size: THEME_SUBHEADING_TEXT_SIZE
|
label "Actions", text_size: THEME_SUBHEADING_TEXT_SIZE
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add action" do
|
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add action" do
|
||||||
if @active_group
|
if @active_group
|
||||||
push_state(TAC::Dialog::NamePromptDialog, title: "Create Action", list: @active_group.actions, callback_method: method(:create_action))
|
push_state(TAC::Dialog::ActionDialog, title: "Create Action", list: @active_group.actions, callback_method: method(:create_action))
|
||||||
else
|
else
|
||||||
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create action,\nno group selected.")
|
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create action,\nno group selected.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/button2.png"), image_width: THEME_ICON_SIZE, tip: "Clone currently selected action" do
|
button get_image("#{TAC::ROOT_PATH}/media/icons/button2.png"), image_width: THEME_ICON_SIZE, tip: "Clone currently selected action" do
|
||||||
if @active_group && @active_action
|
if @active_group && @active_action
|
||||||
push_state(Dialog::NamePromptDialog, title: "Clone Action", renaming: @active_action, accept_label: "Clone", list: @active_group.actions, callback_method: proc { |action, name|
|
push_state(Dialog::ActionDialog, title: "Clone Action", action: @active_action, accept_label: "Clone", list: @active_group.actions, callback_method: proc { |action, name, comment|
|
||||||
clone = TAC::Config::Action.from_json( JSON.parse( @active_action.to_json, symbolize_names: true ))
|
clone = TAC::Config::Action.from_json( JSON.parse( @active_action.to_json, symbolize_names: true ))
|
||||||
clone.name = name
|
clone.name = name
|
||||||
@active_group.actions << clone
|
clone.comment = comment
|
||||||
window.backend.config_changed!
|
@active_group.actions << clone
|
||||||
|
window.backend.config_changed!
|
||||||
|
|
||||||
populate_actions_list(@active_group)
|
populate_actions_list(@active_group)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -241,15 +242,16 @@ module TAC
|
|||||||
populate_groups_list
|
populate_groups_list
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_action(name)
|
def create_action(name, comment)
|
||||||
@active_group.actions << TAC::Config::Action.new(name: name, enabled: true, variables: [])
|
@active_group.actions << TAC::Config::Action.new(name: name, comment: comment, enabled: true, variables: [])
|
||||||
window.backend.config_changed!
|
window.backend.config_changed!
|
||||||
|
|
||||||
populate_actions_list(@active_group)
|
populate_actions_list(@active_group)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_action(action, name)
|
def update_action(action, name, comment)
|
||||||
action.name = name
|
action.name = name
|
||||||
|
action.comment = comment
|
||||||
window.backend.config_changed!
|
window.backend.config_changed!
|
||||||
|
|
||||||
populate_actions_list(@active_group)
|
populate_actions_list(@active_group)
|
||||||
@@ -324,28 +326,33 @@ module TAC
|
|||||||
|
|
||||||
@actions_list.clear do
|
@actions_list.clear do
|
||||||
actions.each_with_index do |action, i|
|
actions.each_with_index do |action, i|
|
||||||
flow width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
stack width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
||||||
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
||||||
|
|
||||||
button action.name, width: 0.8 do
|
flow width: 1.0 do
|
||||||
@active_action = action
|
button action.name, width: 0.8 do
|
||||||
@active_action_label.value = action.name
|
@active_action = action
|
||||||
|
@active_action_label.value = action.name
|
||||||
|
|
||||||
populate_variables_list(action)
|
populate_variables_list(action)
|
||||||
|
end
|
||||||
|
|
||||||
|
action_enabled_toggle = toggle_button tip: "Enable action", checked: action.enabled
|
||||||
|
action_enabled_toggle.subscribe(:changed) do |sender, value|
|
||||||
|
action.enabled = value
|
||||||
|
window.backend.config_changed!
|
||||||
|
end
|
||||||
|
|
||||||
|
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit action" do
|
||||||
|
push_state(Dialog::ActionDialog, title: "Rename Action", action: action, list: @active_group.actions, callback_method: method(:update_action))
|
||||||
|
end
|
||||||
|
|
||||||
|
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete action", **THEME_DANGER_BUTTON do
|
||||||
|
push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete action and all\nof its variables?", callback_method: proc { delete_action(action) })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
action_enabled_toggle = toggle_button tip: "Enable action", checked: action.enabled
|
label "#{action.comment}" unless action.comment.empty?
|
||||||
action_enabled_toggle.subscribe(:changed) do |sender, value|
|
|
||||||
action.enabled = value
|
|
||||||
window.backend.config_changed!
|
|
||||||
end
|
|
||||||
|
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit action" do
|
|
||||||
push_state(Dialog::NamePromptDialog, title: "Rename Action", renaming: action, list: @active_group.actions, callback_method: method(:update_action))
|
|
||||||
end
|
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete action", **THEME_DANGER_BUTTON do
|
|
||||||
push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete action and all\nof its variables?", callback_method: proc { delete_action(action) })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ module TAC
|
|||||||
|
|
||||||
def close
|
def close
|
||||||
if @backend.config_changed?
|
if @backend.config_changed?
|
||||||
push_state(Dialog::ConfirmDialog, title: "Unsaved Config", message: "Config has unsaved changes\nthat will be lost if\nyou continue!", callback_method: proc { cleanup_and_close })
|
push_state(Dialog::ConfirmDialog, title: "Unsaved Config", message: "Config has unsaved changes\nthat will be lost if you continue!", callback_method: proc { cleanup_and_close })
|
||||||
elsif @backend.settings_changed?
|
elsif @backend.settings_changed?
|
||||||
push_state(Dialog::ConfirmDialog, title: "Unsaved Settings", message: "Settings has unsaved changes\nthat will be lost if\nyou continue!", callback_method: proc { cleanup_and_close })
|
push_state(Dialog::ConfirmDialog, title: "Unsaved Settings", message: "Settings has unsaved changes\nthat will be lost if you continue!", callback_method: proc { cleanup_and_close })
|
||||||
else
|
else
|
||||||
cleanup_and_close
|
cleanup_and_close
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ require_relative "lib/dialog"
|
|||||||
require_relative "lib/dialogs/alert_dialog"
|
require_relative "lib/dialogs/alert_dialog"
|
||||||
require_relative "lib/dialogs/confirm_dialog"
|
require_relative "lib/dialogs/confirm_dialog"
|
||||||
require_relative "lib/dialogs/name_prompt_dialog"
|
require_relative "lib/dialogs/name_prompt_dialog"
|
||||||
|
require_relative "lib/dialogs/action_dialog"
|
||||||
require_relative "lib/dialogs/variable_dialog"
|
require_relative "lib/dialogs/variable_dialog"
|
||||||
require_relative "lib/dialogs/tacnet_dialog"
|
require_relative "lib/dialogs/tacnet_dialog"
|
||||||
require_relative "lib/dialogs/tacnet_status_dialog"
|
require_relative "lib/dialogs/tacnet_status_dialog"
|
||||||
|
|||||||
Reference in New Issue
Block a user