Skip to content

Commit

Permalink
Added filter for NamePromptDialog, configurations can now be renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberarm committed Jun 23, 2020
1 parent 17e4290 commit ffd8146
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/dialogs/name_prompt_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def build
background Gosu::Color::GRAY
flow width: 1.0 do
label "Name", width: 0.25
@name = edit_line @options[:renaming] ? @options[:renaming].name : "", width: 0.70
@name = edit_line @options[:renaming] ? @options[:renaming].name : "", filter: method(:filter), width: 0.70
end
@name_error = label "", color: TAC::Palette::TACNET_CONNECTION_ERROR
@name_error.hide
Expand Down Expand Up @@ -37,6 +37,10 @@ def build
end
end
end

def filter(text)
text.match(/[A-Za-z0-9,._\-]/) ? text : ""
end
end
end
end
17 changes: 16 additions & 1 deletion lib/states/manage_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,25 @@ def populate_configs

name = File.basename(config_file, ".json")

button "#{name}", width: 0.965 do
button "#{name}", width: 0.94 do
change_config(name)
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"
)

if window.backend.settings.config == name
change_config(new_name)
end

populate_configs
})
end

button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, **THEME_DANGER_BUTTON, tip: "Delete configuration" do
push_state(Dialog::ConfirmDialog, title: "Delete Config?", callback_method: proc {
File.delete("#{TAC::CONFIGS_PATH}/#{name}.json")
Expand Down
1 change: 1 addition & 0 deletions timecrafters_configuration_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "socket"
require "securerandom"
require "json"
require "fileutils"

require_relative "lib/tac"
require_relative "lib/palette"
Expand Down

0 comments on commit ffd8146

Please sign in to comment.