mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 21:32:35 +00:00
Allow edited action to keep its name when editing it (fixes: #1), made dialogs respond to enter and escape, Confirm dialog now shows dark red color for dangerous operations and prevents enter for accepting it
This commit is contained in:
@@ -18,32 +18,36 @@ module TAC
|
||||
end
|
||||
|
||||
button @options[:action] ? @options[:accept_label] ? @options[:accept_label] : "Update" : "Add", width: 0.475 do |b|
|
||||
if valid?
|
||||
if @options[:action]
|
||||
@options[:callback_method].call(@options[:action], @name.value.strip, @comment.value.strip)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip, @comment.value.strip)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit
|
||||
if valid?
|
||||
if @options[:action]
|
||||
@options[:callback_method].call(@options[:action], @name.value.strip, @comment.value.strip)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip, @comment.value.strip)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
valid = true
|
||||
name = @name.value.strip
|
||||
|
||||
if name.empty?
|
||||
@name_error.value = "Error: Name cannot be blank\n or only whitespace."
|
||||
@name_error.value = "Error: Name cannot be blank or only whitespace."
|
||||
@name_error.show
|
||||
valid = false
|
||||
|
||||
### TODO: Handle case when renaming a cloned Action
|
||||
# elsif @options[:action] && @options[:action].name == name
|
||||
# @name_error.value = ""
|
||||
# @name_error.hide
|
||||
elsif !@options[:cloning] && @options[:action] && @options[:action].name == name
|
||||
@name_error.value = ""
|
||||
@name_error.hide
|
||||
|
||||
elsif @options[:list].find { |action| action.name == name}
|
||||
@name_error.value = "Error: Name is not unique!"
|
||||
|
||||
@@ -6,9 +6,13 @@ module TAC
|
||||
label @options[:message]
|
||||
|
||||
button "Close", width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
||||
close
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit
|
||||
close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,8 +2,10 @@ module TAC
|
||||
class Dialog
|
||||
class ConfirmDialog < Dialog
|
||||
def build
|
||||
@dialog_root.style.border_color = [ Palette::ALERT, darken(Palette::ALERT, 50) ]
|
||||
@titlebar.style.background = [ Palette::ALERT, darken(Palette::ALERT, 50) ]
|
||||
color = @options[:dangerous] ? Palette::DANGEROUS : Palette::ALERT
|
||||
|
||||
@dialog_root.style.border_color = [ color, darken(color, 50) ]
|
||||
@titlebar.style.background = [ color, darken(color, 50) ]
|
||||
|
||||
background Gosu::Color::GRAY
|
||||
label @options[:message]
|
||||
@@ -12,7 +14,14 @@ module TAC
|
||||
button "Cancel", width: 0.475 do
|
||||
close
|
||||
end
|
||||
|
||||
button "Proceed", width: 0.475, **TAC::THEME_DANGER_BUTTON do
|
||||
try_commit(true)
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit(force = false)
|
||||
if not @options[:dangerous] || force
|
||||
close
|
||||
|
||||
@options[:callback_method].call
|
||||
|
||||
@@ -23,20 +23,23 @@ module TAC
|
||||
accept_label = @options[:accept_label] if @options[:accept_label]
|
||||
|
||||
button accept_label, width: 0.475 do
|
||||
unless valid?
|
||||
else
|
||||
if @options[:renaming]
|
||||
@options[:callback_method].call(@options[:renaming], @name.value.strip)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit
|
||||
if valid?
|
||||
if @options[:renaming]
|
||||
@options[:callback_method].call(@options[:renaming], @name.value.strip)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
name = @name.value.strip
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ module TAC
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,10 +11,14 @@ module TAC
|
||||
@sound = Gosu::Sample.new("#{TAC::ROOT_PATH}/media/error_alarm.ogg").play(1, 1, true)
|
||||
|
||||
button "Close", width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
||||
close
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit
|
||||
close
|
||||
end
|
||||
|
||||
def close
|
||||
super
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ module TAC
|
||||
@message_label = label $window.backend.tacnet.full_status
|
||||
|
||||
button "Close", width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
||||
close
|
||||
try_commit
|
||||
end
|
||||
|
||||
@timer = CyberarmEngine::Timer.new(1000.0) do
|
||||
@@ -14,6 +14,10 @@ module TAC
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit
|
||||
close
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
|
||||
@@ -48,21 +48,25 @@ module TAC
|
||||
end
|
||||
|
||||
button @options[:variable] ? "Update" : "Add", width: 0.475 do |b|
|
||||
if valid?
|
||||
value = @type == :boolean ? @value_boolean.value.to_s : @value.value.strip
|
||||
|
||||
if @options[:variable]
|
||||
@options[:callback_method].call(@options[:variable], @name.value.strip, @type, value)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip, @type, value)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def try_commit
|
||||
if valid?
|
||||
value = @type == :boolean ? @value_boolean.value.to_s : @value.value.strip
|
||||
|
||||
if @options[:variable]
|
||||
@options[:callback_method].call(@options[:variable], @name.value.strip, @type, value)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip, @type, value)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
valid = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user