From e27f1d1dca6641e7292135928b19cf28c4e1074c Mon Sep 17 00:00:00 2001 From: cyberarm Date: Tue, 9 Feb 2021 23:38:01 -0600 Subject: [PATCH] Initial presets editing support --- lib/pages/editor.rb | 52 +++++++++++++++++++++++------- lib/pages/presets.rb | 8 +++-- timecrafters_configuration_tool.rb | 8 ++--- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/lib/pages/editor.rb b/lib/pages/editor.rb index 5938b39..65eb2f8 100644 --- a/lib/pages/editor.rb +++ b/lib/pages/editor.rb @@ -48,6 +48,8 @@ module TAC populate_groups_list }) + else + push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to clone group, no group selected.") end end @@ -61,6 +63,8 @@ module TAC window.toast("Saved Group Preset", "Saved preset: #{name}") }) + else + push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create group preset, no group selected.") end end end @@ -77,7 +81,7 @@ module TAC if @active_group push_state(TAC::Dialog::ActionDialog, title: "Create Action", list: @active_group.actions, callback_method: method(:create_action)) 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, no group selected.") end end @@ -92,6 +96,8 @@ module TAC populate_actions_list(@active_group) }) + else + push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to clone action, no action selected.") end end @@ -105,6 +111,8 @@ module TAC window.toast("Saved Action Preset", "Saved preset: #{name}") }) + else + push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create action preset, no action selected.") end end end @@ -133,20 +141,38 @@ module TAC populate_groups_list - if @options[:group] + if @options[:group_is_preset] @active_group = @options[:group] @active_group_label.value = @active_group.name - populate_actions_list(@active_group) - if @options[:action] - @active_action = @options[:action] - @active_action_label.value = @active_action.name + @groups_menu.hide - populate_variables_list(@active_action) + elsif @options[:action_is_preset] + @active_action = @options[:action] + @active_action_label.value = @active_action.name - if @options[:variable] - # Scroll into view? + populate_variables_list(@options[:action]) + + @groups_menu.hide + @actions_menu.hide + + else + if @options[:group] + @active_group = @options[:group] + @active_group_label.value = @active_group.name + + populate_actions_list(@active_group) + + if @options[:action] + @active_action = @options[:action] + @active_action_label.value = @active_action.name + + populate_variables_list(@active_action) + + if @options[:variable] + # Scroll into view? + end end end end @@ -241,7 +267,11 @@ module TAC end def populate_groups_list - groups = window.backend.config.groups + groups = [] + + unless @options[:group_is_preset] || @options[:action_is_preset] + groups = window.backend.config.groups + end @groups_list.clear do groups.each_with_index do |group, i| @@ -262,7 +292,7 @@ module TAC push_state(Dialog::NamePromptDialog, title: "Rename Group", renaming: group, list: window.backend.config.groups, callback_method: method(:update_group)) end button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete group", **THEME_DANGER_BUTTON do - push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete group and all\nof its actions and variables?", callback_method: proc { delete_group(group) }) + push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete group and all of its actions and variables?", callback_method: proc { delete_group(group) }) end end end diff --git a/lib/pages/presets.rb b/lib/pages/presets.rb index bd1a13e..7f2a023 100644 --- a/lib/pages/presets.rb +++ b/lib/pages/presets.rb @@ -29,7 +29,9 @@ module TAC flow(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button group.name, width: 0.895 + button group.name, width: 0.895 do + page(TAC::Pages::Editor,{ group: group, group_is_preset: true }) + end button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit group preset" do push_state( @@ -60,7 +62,9 @@ module TAC flow(width: 1.0, **THEME_ITEM_CONTAINER_PADDING) do background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR - button action.name, width: 0.895 + button action.name, width: 0.895 do + page(TAC::Pages::Editor,{ action: action, action_is_preset: true }) + end button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit action preset" do push_state( diff --git a/timecrafters_configuration_tool.rb b/timecrafters_configuration_tool.rb index dbf5bb1..08beaad 100644 --- a/timecrafters_configuration_tool.rb +++ b/timecrafters_configuration_tool.rb @@ -13,11 +13,11 @@ require_relative "lib/backend" require_relative "lib/config" require_relative "lib/settings" require_relative "lib/states/boot" -require_relative "lib/states/editor" require_relative "lib/states/new_editor" -require_relative "lib/states/simulator" -require_relative "lib/states/manage_presets" -require_relative "lib/states/manage_configurations" +# require_relative "lib/states/editor" +# require_relative "lib/states/simulator" +# require_relative "lib/states/manage_presets" +# require_relative "lib/states/manage_configurations" require_relative "lib/page" require_relative "lib/pages/home" require_relative "lib/pages/editor"