95 lines
3.1 KiB
Plaintext
95 lines
3.1 KiB
Plaintext
import "pkg:/source/utils/Locale.bs"
|
|
import "pkg:/source/utils/Types.bs"
|
|
|
|
namespace DialogUtils
|
|
|
|
function ShowDialogEx(options as object) as object
|
|
currentDialog = m.top.getScene().dialog
|
|
alwaysOnTop = false
|
|
if options.DoesExist("alwaysOnTop")
|
|
alwaysOnTop = options.alwaysOnTop
|
|
end if
|
|
|
|
if currentDialog <> invalid and ValidBool(currentDialog.alwaysOnTop)
|
|
if not alwaysOnTop
|
|
return invalid
|
|
end if
|
|
end if
|
|
|
|
dialog = CreateObject("roSGNode", "SimpleDialog")
|
|
dialog.alwaysOnTop = alwaysOnTop
|
|
|
|
if options.DoesExist("message")
|
|
message = options.message
|
|
if GetInterface(message, "ifArray") = invalid
|
|
message = message.Tokenize(`\n`).ToArray()
|
|
end if
|
|
dialog.message = message
|
|
end if
|
|
|
|
if options.DoesExist("title")
|
|
dialog.title = options.title
|
|
end if
|
|
|
|
if options.DoesExist("buttons")
|
|
dialog.buttons = options.buttons
|
|
else
|
|
dialog.buttons = [Tr(Locale.Buttons.OK)]
|
|
end if
|
|
|
|
if options.DoesExist("large") and options.large
|
|
if m._deviceDisplayWidth = invalid
|
|
deviceInfo = CreateObject("roDeviceInfo")
|
|
displaySize = deviceInfo.GetDisplaySize()
|
|
m._deviceDisplayWidth = displaySize.w
|
|
end if
|
|
dialog.width = m._deviceDisplayWidth - 100
|
|
else if options.DoesExist("marginWidth")
|
|
if m._deviceDisplayWidth = invalid
|
|
deviceInfo = CreateObject("roDeviceInfo")
|
|
displaySize = deviceInfo.GetDisplaySize()
|
|
m._deviceDisplayWidth = displaySize.w
|
|
end if
|
|
dialog.width = m._deviceDisplayWidth - options.marginWidth
|
|
end if
|
|
|
|
m.top.getScene().dialog = dialog
|
|
return dialog
|
|
end function
|
|
|
|
function ShowTimedDialogButtons(message as dynamic, title as string, buttons as object, defaultButton as integer, timeoutSeconds as integer, large = false as boolean) as object
|
|
currentDialog = m.top.getScene().dialog
|
|
if currentDialog <> invalid and ValidBool(currentDialog.alwaysOnTop)
|
|
return invalid
|
|
end if
|
|
|
|
dialog = CreateObject("roSGNode", "TimedDialog")
|
|
if GetInterface(message, "ifArray") = invalid
|
|
message = message.Tokenize(`\n`).ToArray()
|
|
end if
|
|
dialog.message = message
|
|
dialog.title = title
|
|
dialog.actualButtons = buttons
|
|
|
|
if large
|
|
if m._deviceDisplayWidth = invalid
|
|
deviceInfo = CreateObject("roDeviceInfo")
|
|
displaySize = deviceInfo.GetDisplaySize()
|
|
m._deviceDisplayWidth = displaySize.w
|
|
end if
|
|
dialog.width = m._deviceDisplayWidth - 100
|
|
end if
|
|
|
|
dialog.defaultButtonIndex = defaultButton
|
|
dialog.defaultActionTimeoutSeconds = timeoutSeconds
|
|
dialog.startCountdown = true
|
|
|
|
m.top.getScene().dialog = dialog
|
|
|
|
dialog.focusDefaultButton = true
|
|
|
|
return dialog
|
|
end function
|
|
|
|
end namespace
|