TimedDialog bug fix

This commit is contained in:
Brahim Hadriche committed 2024-03-28 17:06:25 -04:00
1 parent e5062c34d7
commit b67587df2b
2 files changed
+68 -16

No files matched your search

+3 -1
View File
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
- Nothing worth mentioning yet. ### Fixed
- Dialog with timer now stops as expected if any button is pressed
## [0.22.0] - 2024-03-24 ## [0.22.0] - 2024-03-24
@@ -29,6 +29,9 @@ function OnStartCountdown()
m.timer.observeFieldScoped("fire", FuncName(TimerUpdateButtons)) m.timer.observeFieldScoped("fire", FuncName(TimerUpdateButtons))
m.currentCountDown = defaultActionTimeoutSeconds m.currentCountDown = defaultActionTimeoutSeconds
m.timer.control = "start" m.timer.control = "start"
FindContentComponent()
WatchContentTranslation()
end function end function
function TimerUpdateButtons() as void function TimerUpdateButtons() as void
@@ -39,13 +42,8 @@ function TimerUpdateButtons() as void
return return
end if end if
FindButtonComponents() FindButtonComponent()
if m.buttonComponents = invalid SetDefaultButtonText(m.currentCountDown)
return
end if
defaultButtonIndex = m.top.defaultButtonIndex
m.buttonComponents[defaultButtonIndex].text = `${m.top.actualButtons[defaultButtonIndex]} (${m.currentCountDown})`
end function end function
function OnButtonSelected() function OnButtonSelected()
@@ -55,6 +53,7 @@ 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
@@ -63,14 +62,10 @@ function onKeyEvent(key as string, press as boolean) as boolean
end if end if
CancelTimer() CancelTimer()
UnwatchContentTranslation()
FindButtonComponents() FindButtonComponent()
if m.buttonComponents = invalid SetDefaultButtonText(0)
return false
end if
defaultButtonIndex = m.top.defaultButtonIndex
m.buttonComponents[defaultButtonIndex].text = m.top.actualButtons[defaultButtonIndex]
return false return false
end function end function
@@ -82,7 +77,21 @@ function CancelTimer()
end if end if
end function end function
function FindButtonComponents() as void function SetDefaultButtonText(timeLeft as integer) as void
if m.buttonComponents = invalid
return
end if
defaultButtonIndex = m.top.defaultButtonIndex
if timeLeft > 0
m.buttonComponents[defaultButtonIndex].text = `${m.top.actualButtons[defaultButtonIndex]} (${timeLeft})`
else
m.buttonComponents[defaultButtonIndex].text = m.top.actualButtons[defaultButtonIndex]
end if
end function
function FindButtonComponent() as void
if m.buttonComponents <> invalid if m.buttonComponents <> invalid
return return
end if end if
@@ -96,3 +105,44 @@ function FindButtonComponents() 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