Simplify timed dialog

This commit is contained in:
Brahim Hadriche committed 2024-03-29 12:48:03 -04:00
1 parent 305ddaa737
commit 99be2071d1
3 files changed
+18 -46

No files matched your search

@@ -49,6 +49,8 @@ namespace DialogUtils
m.top.getScene().dialog = dialog m.top.getScene().dialog = dialog
dialog.focusDefaultButton = true
return dialog return dialog
end function end function
end namespace end namespace
@@ -1,4 +1,5 @@
import "DialogPalette.bs" import "DialogPalette.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/Types.bs" import "pkg:/source/utils/Types.bs"
@@ -30,8 +31,20 @@ function OnStartCountdown()
m.currentCountDown = defaultActionTimeoutSeconds m.currentCountDown = defaultActionTimeoutSeconds
m.timer.control = "start" m.timer.control = "start"
FindContentComponent() FindButtonComponent()
WatchContentTranslation() end function
function OnFocusDefaultButton() as void
FindButtonComponent()
if m.buttonComponents = invalid
return
end if
defaultButtonIndex = m.top.defaultButtonIndex
if m.buttonComponents.Count() <= defaultButtonIndex
return
end if
button = m.buttonComponents[defaultButtonIndex]
NodeSetFocus(button, true)
end function end function
function TimerUpdateButtons() as void function TimerUpdateButtons() as void
@@ -42,7 +55,6 @@ function TimerUpdateButtons() as void
return return
end if end if
FindButtonComponent()
SetDefaultButtonText(m.currentCountDown) SetDefaultButtonText(m.currentCountDown)
end function end function
@@ -53,7 +65,6 @@ end function
function OnDialogClosed() function OnDialogClosed()
CancelTimer() CancelTimer()
UnwatchContentTranslation()
end function end function
function onKeyEvent(key as string, press as boolean) as boolean function onKeyEvent(key as string, press as boolean) as boolean
@@ -62,7 +73,6 @@ function onKeyEvent(key as string, press as boolean) as boolean
end if end if
CancelTimer() CancelTimer()
UnwatchContentTranslation()
FindButtonComponent() FindButtonComponent()
SetDefaultButtonText(0) SetDefaultButtonText(0)
@@ -105,44 +115,3 @@ function FindButtonComponent() as void
end for end for
LogWarn("No buttons found in dialog") LogWarn("No buttons found in dialog")
end function end function
function FindContentComponent() as void
if m.contentComponent <> invalid
return
end if
areas = m.top.getChildren(-1, 0)
for each area in areas
if area.subtype() = "StdDlgContentArea"
if area.getChildCount() > 0
m.contentComponent = area.getChild(0)
end if
return
end if
end for
LogWarn("No content component found in dialog")
end function
function WatchContentTranslation() as void
if m.contentComponent = invalid
return
end if
m.contentComponent.observeFieldScoped("translation", FuncName(OnContentMoved))
end function
function UnwatchContentTranslation() as void
if m.contentComponent = invalid
return
end if
m.contentComponent.unobserveFieldScoped("translation")
m.contentComponent = invalid
end function
function OnContentMoved()
CancelTimer()
UnwatchContentTranslation()
FindButtonComponent()
SetDefaultButtonText(0)
end function
@@ -6,5 +6,6 @@
<!-- Use actualButtonSelected because buttonSelected is read only and defaults to 0 --> <!-- Use actualButtonSelected because buttonSelected is read only and defaults to 0 -->
<field id="actualButtonSelected" type="integer" value="-1" /> <field id="actualButtonSelected" type="integer" value="-1" />
<field id="startCountdown" type="boolean" alwaysNotify="true" onChange="OnStartCountdown" /> <field id="startCountdown" type="boolean" alwaysNotify="true" onChange="OnStartCountdown" />
<field id="focusDefaultButton" type="boolean" alwaysNotify="true" onChange="OnFocusDefaultButton" />
</interface> </interface>
</component> </component>