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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user