mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-16 13:52:34 +00:00
Added PickPresetDialog for importing from preset, enable importing presets for groups and actions
This commit is contained in:
23
lib/dialogs/pick_preset_dialog.rb
Normal file
23
lib/dialogs/pick_preset_dialog.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
module TAC
|
||||||
|
class Dialog
|
||||||
|
class PickPresetDialog < Dialog
|
||||||
|
def build
|
||||||
|
@limit = @options[:limit]
|
||||||
|
|
||||||
|
list = window.backend.config.presets.groups if @limit == :groups
|
||||||
|
list = window.backend.config.presets.actions if @limit == :actions
|
||||||
|
|
||||||
|
background Gosu::Color::GRAY
|
||||||
|
|
||||||
|
stack(width: 1.0, height: 512, scroll: true) do
|
||||||
|
list.each do |item|
|
||||||
|
button item.name, width: 1.0 do
|
||||||
|
close
|
||||||
|
@options[:callback_method].call(item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -68,6 +68,20 @@ module TAC
|
|||||||
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create group preset, no group selected.")
|
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create group preset, no group selected.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
button get_image("#{TAC::ROOT_PATH}/media/icons/import.png"), image_width: THEME_ICON_SIZE, tip: "Import group from preset" do
|
||||||
|
push_state(Dialog::PickPresetDialog, title: "Pick Group Preset", limit: :groups, callback_method: proc { |preset|
|
||||||
|
push_state(Dialog::NamePromptDialog, title: "Name Group", renaming: preset, accept_label: "Add", list: window.backend.config.groups, callback_method: proc { |group, name|
|
||||||
|
clone = TAC::Config::Group.from_json( JSON.parse( group.to_json, symbolize_names: true ))
|
||||||
|
clone.name = "#{name}"
|
||||||
|
window.backend.config.groups << clone
|
||||||
|
window.backend.config.groups.sort_by! { |g| g.name.downcase }
|
||||||
|
window.backend.config_changed!
|
||||||
|
|
||||||
|
populate_groups_list
|
||||||
|
})
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@groups_list = stack width: 1.0, scroll: true do
|
@groups_list = stack width: 1.0, scroll: true do
|
||||||
@@ -117,6 +131,24 @@ module TAC
|
|||||||
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create action preset, no action selected.")
|
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create action preset, no action selected.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
button get_image("#{TAC::ROOT_PATH}/media/icons/import.png"), image_width: THEME_ICON_SIZE, tip: "Import action from preset" do
|
||||||
|
if @active_group
|
||||||
|
push_state(Dialog::PickPresetDialog, title: "Pick Action Preset", limit: :actions, callback_method: proc { |preset|
|
||||||
|
push_state(Dialog::NamePromptDialog, title: "Name Action", renaming: preset, accept_label: "Add", list: @active_group.actions, callback_method: proc { |action, name|
|
||||||
|
clone = TAC::Config::Action.from_json( JSON.parse( action.to_json, symbolize_names: true ))
|
||||||
|
clone.name = "#{name}"
|
||||||
|
@active_group.actions << clone
|
||||||
|
@active_group.actions.sort_by! { |a| a.name.downcase }
|
||||||
|
window.backend.config_changed!
|
||||||
|
|
||||||
|
populate_actions_list(@active_group)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
else
|
||||||
|
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to import action preset, no group selected.")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@actions_list = stack width: 1.0, scroll: true do
|
@actions_list = stack width: 1.0, scroll: true do
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ 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"
|
||||||
|
require_relative "lib/dialogs/pick_preset_dialog"
|
||||||
require_relative "lib/tacnet"
|
require_relative "lib/tacnet"
|
||||||
require_relative "lib/tacnet/packet"
|
require_relative "lib/tacnet/packet"
|
||||||
require_relative "lib/tacnet/packet_handler"
|
require_relative "lib/tacnet/packet_handler"
|
||||||
|
|||||||
Reference in New Issue
Block a user