Author: bklaas
Date: Thu May 15 08:28:28 2008
New Revision: 2454
URL: http://svn.slimdevices.com?rev=2454&root=Jive&view=rev
Log:
Bug: 8123
Description:
- add itemComparatorKeyWeightAlpha method to SimpleMenu (not in use anywhere at
the moment, but works for a three level alpha-num-alpha sort)
- add itemComparatorComplexWeightAlpha method to SimpleMenu (now used by
CustomizeHomeMenu and HomeMenu)
- add getComplexWeight method to HomeMenu to walk an item's placement to the
top menu
- add split() method to jive.utils.strings
- send style attribute to HomeMenu from SlimBrowser._menuSink()
- add progressive indents to submenu items in CustomizeHomeMenuApplet
- add complexWeight sort to menu in CustomizeHomeMenuApplet checkbox list. Menu
should now be rendered in a visual facsimile of the home menu item hierarchy
-- don't allow settings and advanced settings to be removed from home menu, but
don't remove them from the applet menu (styled now as 'itemNoAction' with no
checkbox)
- change sort style in HomeMenu items to complex weights (if no complex weights
exist for a given SimpleMenu, this comparator works identically to the
WeightAlpha sort comparator)
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/strings.lua
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
---
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
(original)
+++
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
Thu May 15 08:28:28 2008
@@ -17,9 +17,10 @@
-- stuff we use
-local tostring, pairs, table = tostring, pairs, table
+local tostring, tonumber, pairs, ipairs, table = tostring, tonumber, pairs,
ipairs, table
local oo = require("loop.simple")
local string = require("string")
+local strings = require("jive.utils.strings")
local table = require("jive.utils.table")
local Applet = require("jive.Applet")
@@ -39,6 +40,19 @@
module(...)
oo.class(_M, Applet)
+-- FIXME: this method should be farmed out to SimpleMenu as a function called
from _itemRenderer()
+-- _indent
+-- returns a string of <size> spaces
+local function _indent(indentSize)
+ local indent = ''
+ if not indentSize then
+ return indent
+ end
+ for i = 1, tonumber(indentSize) do
+ indent = tostring(indent) .. ' '
+ end
+ return indent
+end
function menu(self, menuItem)
@@ -59,28 +73,26 @@
table.insert(homeMenuItems,
{
text = self:string('CUSTOMIZE_RESTORE_DEFAULTS'),
- weight = 100,
+ weights = { 1001 },
callback = function()
self:restoreDefaultsMenu()
end
}
)
+
for id, item in pairs(self.menuTable) do
- if id ~= 'hidden' and
- id ~= 'nowhere' and
- id ~= 'settings' and
- not item.noCustom
+ if id ~= 'hidden'
+ and id ~= 'nowhere'
+ -- a small hack to make sounds/effects not appear twice
+ and id ~= 'opmlsounds'
then
- local title, selected, weight
-
- local defaultNode = jiveMain:getNodeText(item.node)
- if defaultNode then
- title = tostring(item.text) .. ' (' ..
tostring(defaultNode) .. ')'
- else
- title = item.text
- end
+ local title, selected
+
+ local complexWeight = jiveMain:getComplexWeight(id, item)
+ local weights = {}
+ item.weights = strings:split('%.', complexWeight, weights)
-- if this is a home item and setting = 'hidden', then unselect
if self.currentSettings[id] and self.currentSettings[id] ==
'hidden' and item.node == 'home' then
@@ -93,51 +105,72 @@
selected = false
end
+ local indentSize = 0
+ for i,v in ipairs(item.weights) do
+ if i > 1 then
+ indentSize = indentSize + 2
+ end
+ end
+ local indent = _indent(indentSize)
+
if item.node == 'home' then
- weight = 2
+ title = item.text
+ elseif item.homeMenuToken then
+ title = indent ..
tostring(self:string(item.homeMenuToken))
+ elseif item.homeMenuText then
+ title = indent .. tostring(item.homeMenuText)
else
- weight = 5
- end
-
- local menuItem = {
- text = title,
- weight = weight,
- icon = Checkbox(
- "checkbox",
- function(object, isSelected)
- if isSelected then
- if item.node == 'home' then
-
self:getSettings()[item.id] = nil
- jiveMain:setNode(item,
'home')
+ title = indent .. tostring(item.text)
+ end
+
+ if not item.weights[1] then
+ item.weights = { 2 }
+ end
+ local menuItem
+ if item.noCustom then
+ menuItem = {
+ text = title,
+ weights = item.weights,
+ indent = indentSize,
+ style = 'itemNoAction'
+ }
+ else
+ menuItem = {
+ text = title,
+ weights = item.weights,
+ indent = indentSize,
+ icon = Checkbox(
+ "checkbox",
+ function(object, isSelected)
+ if isSelected then
+ if item.node == 'home'
then
+
self:getSettings()[item.id] = nil
+
jiveMain:setNode(item, 'home')
+ else
+
self:getSettings()[item.id] = 'home'
+
jiveMain:addItemToNode(item, 'home')
+ end
else
-
self:getSettings()[item.id] = 'home'
- if item.homeMenuToken
then
- item.text =
self:string(item.homeMenuToken)
- elseif
item.homeMenuText then
- item.text =
item.homeMenuText
+ if item.node == 'home'
then
+
self:getSettings()[item.id] = 'hidden'
+
jiveMain:setNode(item, 'hidden')
+ else
+
self:getSettings()[item.id] = nil
+
jiveMain:removeItemFromNode(item, 'home')
end
-
jiveMain:addItemToNode(item, 'home')
end
- else
- if item.node == 'home' then
-
self:getSettings()[item.id] = 'hidden'
- jiveMain:setNode(item,
'hidden')
- else
-
self:getSettings()[item.id] = nil
-
jiveMain:removeItemFromNode(item, 'home')
- end
- end
- self:storeSettings()
- end,
- selected
- ),
- }
+ self:storeSettings()
+ end,
+ selected
+ ),
+ }
+ end
table.insert(homeMenuItems, menuItem)
end
end
local menu = SimpleMenu("menu", homeMenuItems )
- menu:setComparator(menu.itemComparatorWeightAlpha)
+ menu:setComparator(menu.itemComparatorComplexWeightAlpha)
local window = Window("window", self:string("CUSTOMIZE_HOME"),
'settingstitle')
window:addWidget(menu)
@@ -186,3 +219,4 @@
windowStack[#windowStack - 1]:hide()
end
end
+
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
---
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
(original)
+++
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
Thu May 15 08:28:28 2008
@@ -28,6 +28,6 @@
jiveMain:setCustomNode(id, node)
end
- jiveMain:addItem(self:menuItem('appletCustomizeHome', 'settings',
"CUSTOMIZE_HOME", function(applet, ...) applet:menu(...) end, _, {
homeMenuToken = 'CUSTOMIZE_HOME_HOMESTRING' }))
+ jiveMain:addItem(self:menuItem('appletCustomizeHome', 'settings',
"CUSTOMIZE_HOME", function(applet, ...) applet:menu(...) end))
end
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
---
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
(original)
+++
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
Thu May 15 08:28:28 2008
@@ -4,9 +4,6 @@
CUSTOMIZE_HOME
EN Home Menu
-
-CUSTOMIZE_HOME_HOMESTRING
- EN Customize This Menu
CUSTOMIZE_HIDDEN
EN Hidden
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
---
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
(original)
+++
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
Thu May 15 08:28:28 2008
@@ -865,6 +865,7 @@
local item = {
id = v.id,
node = v.node,
+ style = v.style,
text = v.text,
homeMenuText = v.homeMenuText,
weight = v.weight,
Modified: 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
--- 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua (original)
+++ 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua Thu May 15
08:28:28 2008
@@ -230,7 +230,7 @@
jiveMain:addNode( { id = 'hidden', node = 'nowhere' } )
jiveMain:addNode( { id = 'extras', node = 'home', text =
_globalStrings:str("EXTRAS"), weight = 70 } )
jiveMain:addNode( { id = 'games', node = 'extras', text =
_globalStrings:str("GAMES"), weight = 70 } )
- jiveMain:addNode( { id = 'settings', node = 'home', text =
_globalStrings:str("SETTINGS"), weight = 50, titleStyle = 'settings' })
+ jiveMain:addNode( { id = 'settings', node = 'home', noCustom = 1, text
= _globalStrings:str("SETTINGS"), weight = 50, titleStyle = 'settings' })
jiveMain:addNode( { id = 'advancedSettings', node = 'settings',
noCustom = 1, text = _globalStrings:str("ADVANCED_SETTINGS"), weight = 110,
titleStyle = 'settings' })
jiveMain:addNode( { id = 'screenSettings', node = 'settings', text =
_globalStrings:str("SCREEN_SETTINGS"), weight = 50, titleStyle = 'settings' })
jiveMain:addNode( { id = 'factoryTest', node = 'advancedSettings',
noCustom = 1, text = _globalStrings:str("FACTORY_TEST"), weight = 100,
titleStyle = 'settings' })
Modified: 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
--- 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua (original)
+++ 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua Thu May 15
08:28:28 2008
@@ -3,6 +3,7 @@
local oo = require("loop.base")
local table = require("jive.utils.table")
+local strings = require("jive.utils.strings")
local Framework = require("jive.ui.Framework")
local SimpleMenu = require("jive.ui.SimpleMenu")
@@ -27,7 +28,7 @@
})
local menu = SimpleMenu("menu")
- menu:setComparator(SimpleMenu.itemComparatorWeightAlpha)
+ menu:setComparator(SimpleMenu.itemComparatorComplexWeightAlpha)
-- home menu is not closeable
menu:setCloseable(false)
@@ -59,6 +60,22 @@
return self.nodeTable[node]['item']['text']
else
return nil
+ end
+end
+
+function getComplexWeight(self, id, item)
+ if self.menuTable[id]['node'] == 'home' then
+ return item.weight
+ elseif self.menuTable[id]['node'] == 'hidden' then
+ return 100
+ else
+ local nodeItem = self.menuTable[id]['node']
+ if not self.menuTable[nodeItem] then
+ log:warn('when trying to analyze ', item.text, ', its
node, ', nodeItem, ', is not currently in the menuTable thus no way to
establish a complex weight for sorting')
+ return item.weight
+ else
+ return
self:getComplexWeight(self.menuTable[id]['node'], self.menuTable[nodeItem]) ..
'.' .. item.weight
+ end
end
end
@@ -187,8 +204,15 @@
-- add an item to a node
function addItemToNode(self, item, node)
assert(item.id)
+ self.node = node
if node then
self.customNodes[item.id] = node
+ if item.node ~= 'home' and node == 'home' then
+ local complexWeight = self:getComplexWeight(item.id,
item)
+ item.weights = strings:split('%.', complexWeight)
+ -- non-home items on home get an indent
+ item.indent = #item.weights * 2
+ end
else
node = item.node
end
Modified: 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
--- 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua
(original)
+++ 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua Thu May
15 08:28:28 2008
@@ -46,7 +46,7 @@
-- stuff we use
-local _assert, ipairs, string, tostring, type = _assert, ipairs, string,
tostring, type
+local _assert, ipairs, string, tostring, type, tonumber = _assert, ipairs,
string, tostring, type, tonumber
local oo = require("loop.simple")
@@ -95,6 +95,18 @@
return nil
end
+-- _indent
+-- returns a string of <size> spaces
+local function _indent(indentSize)
+ local indent = ''
+ if not indentSize then
+ return indent
+ end
+ for i = 1, tonumber(indentSize) do
+ indent = tostring(indent) .. ' '
+ end
+ return indent
+end
-- _itemRenderer
-- updates the widgetList ready for the menu to be rendered
@@ -102,6 +114,21 @@
for i = 1,size do
if indexList[i] ~= nil then
local item = list[indexList[i]]
+ local labelText = item.text
+ -- FIXME
+ -- changing labelText for the item for the home menu
+ -- also changes it for its default location
+ -- label text needs to be changed on a contextual basis
+ -- question is how to determine context in
_itemRenderer since self is not available
+ --[[
+ if item.homeMenuText then
+ labelText = item.homeMenuText
+ end
+ if item.indent then
+ local indent = _indent(item.indent)
+ labelText = indent .. tostring(labelText)
+ end
+ --]]
local icon = item.icon or menu.icons[i]
if icon == nil then
@@ -112,13 +139,13 @@
if widgetList[i] == nil then
widgetList[i] = Group(item.style or "item", {
- text = Label("text", item.text),
+ text = Label("text", labelText),
check = Icon("check"),
icon = icon,
})
else
widgetList[i]:setStyle(item.style or "item")
- widgetList[i]:setWidgetValue("text", item.text)
+ widgetList[i]:setWidgetValue("text", labelText)
widgetList[i]:setWidget("icon", icon)
end
end
@@ -211,6 +238,87 @@
return tostring(a.text) < tostring(b.text)
end
return (w < 0)
+end
+
+--[[
+
+=head2 jive.ui.Menu.itemComparatorNodeWeightAlpha
+
+Item comparator to sort items using item.sortKey as a primary key, item.weight
as a secondary key, and
+item.text as a tertiary key.
+
+--]]
+function itemComparatorKeyWeightAlpha(a, b)
+ local an = tostring(a.sortKey)
+ local bn = tostring(b.sortKey)
+
+ if an == bn then
+ local w = a.weight - b.weight
+
+ if w == 0 then
+ return tostring(a.text) < tostring(b.text)
+ end
+ return (w < 0)
+ else
+ return an < bn
+ end
+end
+
+--[[
+
+=head2 jive.ui.Menu.itemComparatorComplexWeightAlpha
+
+Item comparator to sort items using a complex a.b.c...n-style item.weights
(table) as a primary key, and
+item.text as a secondary key.
+
+--]]
+function itemComparatorComplexWeightAlpha(a, b)
+ if not a.weights then
+ a.weights = { a.weight }
+ end
+ if not b.weights then
+ b.weights = { b.weight }
+ end
+
+ local aSize = #a.weights
+ local bSize = #b.weights
+ local x
+ if aSize > bSize then
+ x = aSize
+ else
+ x = bSize
+ end
+
+ for i=1,x do
+ if not a.weights[i] then
+ a.weights[i] = 0
+ end
+ if not b.weights[i] then
+ b.weights[i] = 0
+ end
+ local w = a.weights[i] - b.weights[i]
+ -- nodes above subitems (e.g., 11 ranks above 11.10)
+ if (not a.weights[i+1] or not b.weights[i+1]) and w == 0 then
+ -- end of the road, weights are the same
+ if not a.weights[i+1] and not b.weights[i+1] then
+ return tostring(a.text) < tostring(b.text)
+ -- a is the node
+ elseif not a.weights[i+1] then
+ return true
+ -- b is the node
+ elseif not b.weights[i+1] then
+ return false
+ end
+ -- weights differ
+ elseif w ~= 0 then
+ return (w < 0)
+ -- end of the road, weight is the same
+ elseif i==x then
+ return tostring(a.text) < tostring(b.text)
+ end
+ -- if we get here, it's time to examine the next i in the
weights table
+ end
+
end
Modified: 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/strings.lua
URL:
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/strings.lua?rev=2454&root=Jive&r1=2453&r2=2454&view=diff
==============================================================================
--- 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/strings.lua
(original)
+++ 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/utils/strings.lua Thu May
15 08:28:28 2008
@@ -60,6 +60,33 @@
return s
end
end
+
+--[[
+
+=head2 split(self, inSplitPattern, myString, returnTable)
+
+Takes a string pattern and string as arguments, and an optional third argument
of a returnTable
+
+Splits myString on inSplitPattern and returns elements in returnTable
(appending to returnTable if returnTable is given)
+
+=cut
+--]]
+
+function split(self, inSplitPattern, myString, returnTable)
+ if not returnTable then
+ returnTable = {}
+ end
+ local theStart = 1
+ local theSplitStart, theSplitEnd = string.find(myString,
inSplitPattern, theStart)
+ while theSplitStart do
+ table.insert(returnTable, string.sub(myString, theStart,
theSplitStart-1))
+ theStart = theSplitEnd + 1
+ theSplitStart, theSplitEnd = string.find(myString,
inSplitPattern, theStart)
+ end
+ table.insert(returnTable, string.sub(myString, theStart))
+ return returnTable
+end
+
--[[
=head1 LICENSE
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins