summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/scripts/lua/require/UI/popup.lua77
-rw-r--r--indra/newview/scripts/lua/test_group_chat.lua7
-rw-r--r--indra/newview/scripts/lua/test_luafloater_speedometer.lua5
-rw-r--r--indra/newview/scripts/lua/test_popup.lua9
-rw-r--r--indra/newview/scripts/lua/test_toolbars.lua6
5 files changed, 67 insertions, 37 deletions
diff --git a/indra/newview/scripts/lua/require/UI/popup.lua b/indra/newview/scripts/lua/require/UI/popup.lua
index 3aaadf85ba..8ccf3b87f3 100644
--- a/indra/newview/scripts/lua/require/UI/popup.lua
+++ b/indra/newview/scripts/lua/require/UI/popup.lua
@@ -1,53 +1,82 @@
local leap = require 'leap'
local mapargs = require 'mapargs'
+local util = require 'util'
-- notification is any name defined in notifications.xml as
-- <notification name=>
-- vars is a table providing values for [VAR] substitution keys in the
-- notification body
-- payload prepopulates the response table
--- wait=false means fire and forget, otherwise wait for user response
-local popup_meta = {
- -- setting this function as getmetatable(popup).__call() means this gets
- -- called when a consumer calls popup(notification, vars, payload)
+-- wait=false means fire and forget, returning nil
+-- wait=true waits for user response:
+-- * If the viewer returns a table containing exactly one key=true pair,
+-- popup() returns just that key. If the key is a string containing an
+-- underscore, e.g. 'OK_okcancelbuttons', it's truncated at the first
+-- underscore, e.g. 'OK'.
+-- * Otherwise the viewer's response is returned unchanged. To suppress the
+-- above transformations, pass a non-empty payload table; this will cause
+-- the viewer to return a table with at least two keys.
+local popup = util.setmetamethods{
+ -- this gets called when a consumer calls popup(notification, vars, payload)
__call = function(self, ...)
local args = mapargs('notification,vars,payload,wait', ...)
-- we use convenience argument names different from 'LLNotifications'
-- listener
- args.name = args.notification
- args.notification = nil
- args.substitutions = args.vars
- args.vars = nil
- local wait = args.wait
- args.wait = nil
- args.op = 'requestAdd'
+ newargs = {op='requestAdd',
+ name=args.notification,
+ substitutions=args.vars,
+ payload=args.payload}
-- Specifically test (wait == false), NOT (not wait), because we treat
-- nil (omitted, default true) differently than false (explicitly
-- DON'T wait).
- if wait == false then
- leap.send('LLNotifications', args)
+ if args.wait == false then
+ leap.send('LLNotifications', newargs)
else
- return leap.request('LLNotifications', args).response
+ local response = leap.request('LLNotifications', newargs).response
+ -- response is typically a table. It might have multiple keys,
+ -- e.g. if caller passed non-empty payload. In that case, just
+ -- return the whole thing.
+ if type(response) ~= 'table' then
+ return response
+ end
+ -- get first key=value pair, if any
+ local key, value = next(response)
+ if (not key) or next(response, key) then
+ -- key == nil means response is empty
+ -- next(response, non-nil first key) ~= nil means at least two keys
+ return response
+ end
+ -- Here response is a table containing exactly one key. The
+ -- notifications system typically returns a table of the form
+ -- {OK_okcancelbuttons=true}, which is tricky to test for because it
+ -- varies with each set of buttons.
+ if value == true then
+ -- change {key=true} to plain key
+ response = key
+ if type(response) == 'string' then
+ -- change 'OK_okcancelbuttons' to plain 'OK'
+ response = string.split(response, '_')[1]
+ end
+ end
+ return response
end
end
}
-local popup = setmetatable({}, popup_meta)
-
-function popup:alert(message)
- return self('GenericAlert', {MESSAGE=message})
+function popup:alert(message, payload)
+ return self('GenericAlert', {MESSAGE=message, payload=payload})
end
-function popup:alertOK(message)
- return self('GenericAlertOK', {MESSAGE=message})
+function popup:alertOK(message, payload)
+ return self('GenericAlertOK', {MESSAGE=message, payload=payload})
end
-function popup:alertYesCancel(message)
- return self('GenericAlertYesCancel', {MESSAGE=message})
+function popup:alertYesCancel(message, payload)
+ return self('GenericAlertYesCancel', {MESSAGE=message, payload=payload})
end
-function popup:tip(message)
- self{'SystemMessageTip', {MESSAGE=message}, wait=false}
+function popup:tip(message, payload)
+ self{'SystemMessageTip', {MESSAGE=message, payload=payload}, wait=false}
end
return popup
diff --git a/indra/newview/scripts/lua/test_group_chat.lua b/indra/newview/scripts/lua/test_group_chat.lua
index eaff07ed14..373411c26c 100644
--- a/indra/newview/scripts/lua/test_group_chat.lua
+++ b/indra/newview/scripts/lua/test_group_chat.lua
@@ -1,15 +1,14 @@
LLChat = require 'LLChat'
LLAgent = require 'LLAgent'
-popup = require 'popup'
+UI = require 'UI'
-local OK = 'OK_okcancelbuttons'
local GROUPS = LLAgent.getGroups()
-- Choose one of the groups randomly and send group message
math.randomseed(os.time())
group_info = GROUPS[math.random(#GROUPS)]
LLChat.startGroupChat(group_info.id)
-response = popup:alertYesCancel('Started group chat with ' .. group_info.name .. ' group. Send greetings?')
-if next(response) == OK then
+response = UI.popup:alertYesCancel('Started group chat with ' .. group_info.name .. ' group. Send greetings?')
+if response == 'OK' then
LLChat.sendGroupIM('Greetings', group_info.id)
end
diff --git a/indra/newview/scripts/lua/test_luafloater_speedometer.lua b/indra/newview/scripts/lua/test_luafloater_speedometer.lua
index af7189a2cb..8bc18ad286 100644
--- a/indra/newview/scripts/lua/test_luafloater_speedometer.lua
+++ b/indra/newview/scripts/lua/test_luafloater_speedometer.lua
@@ -1,8 +1,9 @@
local Floater = require 'Floater'
local leap = require 'leap'
-local popup = require 'popup'
local startup = require 'startup'
local Timer = (require 'timers').Timer
+local UI = require 'UI'
+local popup = UI.popup
local max_speed = 0
local flt = Floater("luafloater_speedometer.xml")
startup.wait('STATE_STARTED')
@@ -25,7 +26,7 @@ end
msg = 'Are you sure you want to run this "speedometer" script?'
response = popup:alertYesCancel(msg)
-if response.OK_okcancelbuttons then
+if response == 'OK' then
flt:show()
timer = Timer(1, idle, true) -- iterate
end
diff --git a/indra/newview/scripts/lua/test_popup.lua b/indra/newview/scripts/lua/test_popup.lua
index 156c09c78f..7a11895669 100644
--- a/indra/newview/scripts/lua/test_popup.lua
+++ b/indra/newview/scripts/lua/test_popup.lua
@@ -1,7 +1,10 @@
UI = require 'UI'
popup = UI.popup
+startup = require 'startup'
+
+startup.wait('STATE_STARTED')
response = popup:alert('This just has a Close button')
-response = popup:alertOK(string.format('You said "%s", is that OK?', next(response)))
-response = popup:alertYesCancel(string.format('You said "%s"', next(response)))
-popup:tip(string.format('You said "%s"', next(response)))
+response = popup:alertOK(string.format('You said "%s", is that OK?', response))
+response = popup:alertYesCancel(string.format('You said "%s"', response))
+popup:tip(string.format('You said "%s"', response))
diff --git a/indra/newview/scripts/lua/test_toolbars.lua b/indra/newview/scripts/lua/test_toolbars.lua
index 9a832c5644..7683fca8a3 100644
--- a/indra/newview/scripts/lua/test_toolbars.lua
+++ b/indra/newview/scripts/lua/test_toolbars.lua
@@ -1,13 +1,11 @@
-popup = require 'popup'
UI = require 'UI'
-local OK = 'OK_okcancelbuttons'
local BUTTONS = UI.getToolbarBtnNames()
local TOOLBARS = {'left','right','bottom'}
-- Clear the toolbars and then add the toolbar buttons to the random toolbar
-response = popup:alertYesCancel('Toolbars will be randomly reshuffled. Proceed?')
-if next(response) == OK then
+response = UI.popup:alertYesCancel('Toolbars will be randomly reshuffled. Proceed?')
+if response == 'OK' then
UI.clearAllToolbars()
math.randomseed(os.time())