Author: bklaas
Date: Thu May 22 17:52:22 2008
New Revision: 2515
URL: http://svn.slimdevices.com?rev=2515&root=Jive&view=rev
Log:
Bug: 8123
Description: add customMenuTable to handle slightly changed item table for the
home menu (text altered for context)
Modified:
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua
7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.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=2515&root=Jive&r1=2514&r2=2515&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 22 17:52:22 2008
@@ -197,7 +197,9 @@
-- fetch item by id
local item = jiveMain:getMenuItem(id)
-- replace to original node, remove
customNode
- jiveMain:setNode(item, item.node)
+ if item then
+ jiveMain:setNode(item,
item.node)
+ end
end
self:storeSettings()
_goHome()
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=2515&root=Jive&r1=2514&r2=2515&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 22
17:52:22 2008
@@ -1,5 +1,5 @@
-local assert, pairs, type = assert, pairs, type
+local assert, pairs, type, tostring, tonumber, setmetatable = assert, pairs,
type, tostring, tonumber, setmetatable
local oo = require("loop.base")
local table = require("jive.utils.table")
@@ -16,6 +16,22 @@
-- our class
module(..., oo.class)
+-- defines a new item that inherits from an existing item
+local function _uses(parent, value)
+ local item = {}
+ setmetatable(item, { __index = parent })
+
+ for k,v in pairs(value or {}) do
+ if type(v) == "table" and type(parent[k]) == "table" then
+ -- recursively inherrit from parent item
+ item[k] = _uses(parent[k], v)
+ else
+ item[k] = v
+ end
+ end
+
+ return item
+end
-- create a new menu
function __init(self, name, style, titleStyle)
@@ -24,6 +40,7 @@
windowTitle = name,
menuTable = {},
nodeTable = {},
+ customMenuTable = {},
customNodes = {},
})
@@ -210,8 +227,6 @@
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
@@ -220,7 +235,14 @@
if self.nodeTable[node] then
self.nodeTable[node].items[item.id] = item
- self.nodeTable[node].menu:addItem(item)
+ local menuIdx = self.nodeTable[node].menu:addItem(item)
+ if node == 'home' and item.homeMenuText then
+ local labelText = item.homeMenuText
+ -- change the menu item's text by creating a new item
table with different label text
+ local myItem = _uses(item, { text = labelText })
+ self.customMenuTable[myItem.id] = myItem
+ self.nodeTable[node].menu:replaceIndex(myItem, menuIdx)
+ end
end
end
@@ -310,11 +332,19 @@
node = item.node
end
assert(node)
+ if node == 'home' and self.customMenuTable[item.id] then
+ local myIdx = self.nodeTable[node].menu:getIdIndex(item.id)
+ local myItem = self.nodeTable[node].menu:getItem(myIdx)
+ self.nodeTable[node].menu:removeItem(myItem)
+ end
+
if self.nodeTable[node] then
self.nodeTable[node].items[item.id] = nil
self.nodeTable[node].menu:removeItem(item)
self:_checkRemoveNode(node)
end
+
+
end
-- remove an item from a menu by its index
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=2515&root=Jive&r1=2514&r2=2515&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
22 17:52:22 2008
@@ -35,8 +35,6 @@
The Label includes the following style parameters in addition to the widgets
basic parameters.
-=over
-
B<itemHeight> : the height of each menu item.
=head1 METHODS
@@ -114,21 +112,6 @@
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
@@ -139,13 +122,13 @@
if widgetList[i] == nil then
widgetList[i] = Group(item.style or "item", {
- text = Label("text", labelText),
+ text = Label("text", item.text),
check = Icon("check"),
icon = icon,
})
else
widgetList[i]:setStyle(item.style or "item")
- widgetList[i]:setWidgetValue("text", labelText)
+ widgetList[i]:setWidgetValue("text", item.text)
widgetList[i]:setWidget("icon", icon)
end
end
@@ -201,6 +184,7 @@
the menu is not sorted and elements will be displayed in the order they are
added.
+=cut
--]]
function setComparator(self, comp)
self.comparator = comp
@@ -217,6 +201,7 @@
Item comparator to sort items alphabetically (i.e. using item.text).
+=cut
--]]
function itemComparatorAlpha(a, b)
return tostring(a.text) < tostring(b.text)
@@ -230,6 +215,7 @@
Item comparator to sort items using item.weight as a primary key, and
item.text as a secondary key.
+=cut
--]]
function itemComparatorWeightAlpha(a, b)
local w = a.weight - b.weight
@@ -247,6 +233,7 @@
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.
+=cut
--]]
function itemComparatorKeyWeightAlpha(a, b)
local an = tostring(a.sortKey)
@@ -271,6 +258,7 @@
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.
+=cut
--]]
function itemComparatorComplexWeightAlpha(a, b)
if not a.weights then
@@ -607,7 +595,6 @@
Menu.setItems(self, self.items, #self.items, index, index)
end
-
--[[
=head2 jive.ui.Menu:updatedItem(item)
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins