mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 21:32:35 +00:00
Changes
This commit is contained in:
@@ -3,7 +3,7 @@ module TAC
|
||||
attr_reader :config, :settings, :tacnet
|
||||
def initialize
|
||||
load_settings
|
||||
load_config(@settings.config) if @settings.config
|
||||
load_config(@settings.config) if @settings.config && File.exist?("#{TAC::CONFIGS_PATH}/#{@settings.config}.json")
|
||||
@tacnet = TACNET.new
|
||||
|
||||
@config_changed = false
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
module TAC
|
||||
class Dialog
|
||||
class NamePromptDialog < Dialog
|
||||
NameStub = Struct.new(:name)
|
||||
|
||||
def build
|
||||
background Gosu::Color::GRAY
|
||||
flow width: 1.0 do
|
||||
@@ -10,6 +12,10 @@ module TAC
|
||||
@name_error = label "", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
||||
@name_error.hide
|
||||
|
||||
@name.subscribe(:changed) do |sender, value|
|
||||
valid?
|
||||
end
|
||||
|
||||
flow width: 1.0 do
|
||||
button "Cancel", width: 0.475 do
|
||||
close
|
||||
@@ -19,12 +25,7 @@ module TAC
|
||||
accept_label = @options[:accept_label] if @options[:accept_label]
|
||||
|
||||
button accept_label, width: 0.475 do
|
||||
if @name.value.strip.empty?
|
||||
@name_error.value = "Name cannot be blank.\nName cannot only be whitespace."
|
||||
@name_error.show
|
||||
elsif @options[:list] && @options[:list].find { |i| i.name == @name.value.strip }
|
||||
@name_error.value = "Name is not unique!"
|
||||
@name_error.show
|
||||
unless valid?
|
||||
else
|
||||
if @options[:renaming]
|
||||
@options[:callback_method].call(@options[:renaming], @name.value.strip)
|
||||
@@ -38,8 +39,27 @@ module TAC
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
if @name.value.strip.empty?
|
||||
@name_error.value = "Name cannot be blank.\nName cannot only be whitespace."
|
||||
@name_error.show
|
||||
|
||||
return false
|
||||
elsif @options[:list] && @options[:list].find { |i| i.name == @name.value.strip }
|
||||
@name_error.value = "Name is not unique!"
|
||||
@name_error.show
|
||||
|
||||
return false
|
||||
else
|
||||
@name_error.value = ""
|
||||
@name_error.hide
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
def filter(text)
|
||||
text.match(/[A-Za-z0-9,._\-]/) ? text : ""
|
||||
text.match(/[A-Za-z0-9._\- ]/) ? text : ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -171,7 +171,7 @@ module TAC
|
||||
end
|
||||
end
|
||||
|
||||
unless window.backend.settings.config
|
||||
if window.backend.settings.config == nil || window.backend.config == nil
|
||||
push_state(ManageConfigurations)
|
||||
else
|
||||
populate_groups_list
|
||||
|
||||
@@ -46,8 +46,11 @@ module TAC
|
||||
end
|
||||
|
||||
def populate_configs
|
||||
@config_files = Dir.glob("#{TAC::CONFIGS_PATH}/*.json")
|
||||
@config_files_list = @config_files.map { |file| Dialog::NamePromptDialog::NameStub.new(File.basename(file, ".json")) }
|
||||
|
||||
@configs_list.clear do
|
||||
Dir.glob("#{TAC::CONFIGS_PATH}/*.json").each_with_index do |config_file, i|
|
||||
@config_files.each_with_index do |config_file, i|
|
||||
flow width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
||||
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
||||
|
||||
@@ -58,17 +61,21 @@ module TAC
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Rename configuration" do
|
||||
push_state(Dialog::NamePromptDialog, title: "Rename Config", callback_method: proc { |new_name|
|
||||
FileUtils.mv(
|
||||
"#{TAC::CONFIGS_PATH}/#{name}.json",
|
||||
"#{TAC::CONFIGS_PATH}/#{new_name}.json"
|
||||
)
|
||||
push_state(Dialog::NamePromptDialog, title: "Rename Config", renaming: @config_files_list.find { |c| c.name == name }, list: @config_files_list, accept_label: "Update", callback_method: proc { |old_name, new_name|
|
||||
if not File.exist?("#{TAC::CONFIGS_PATH}/#{new_name}.json")
|
||||
FileUtils.mv(
|
||||
"#{TAC::CONFIGS_PATH}/#{name}.json",
|
||||
"#{TAC::CONFIGS_PATH}/#{new_name}.json"
|
||||
)
|
||||
|
||||
if window.backend.settings.config == name
|
||||
change_config(new_name)
|
||||
if window.backend.settings.config == name
|
||||
change_config(new_name)
|
||||
end
|
||||
|
||||
populate_configs
|
||||
else
|
||||
push_state(Dialog::AlertDialog, title: "Config Rename Failed", message: "File already exists at\n#{TAC::CONFIGS_PATH}/#{new_name}.json}")
|
||||
end
|
||||
|
||||
populate_configs
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user