Author: bklaas
Date: Fri Jul 23 12:35:56 2010
New Revision: 8987
URL: http://svn.slimdevices.com/jive?rev=8987&view=rev
Log:
Bug: n/a
Description: Full rework of how to customize home menu items (includes My
Music, Settings, Advanced Settings)
Adding/removing things from the home menu now done via a Context Menu (CM)
Via CM, items can be added/removed from top menu and moved up and down in the
menu
Customization including reordering is persistent across reboots
When items that are in home by default are hidden, a special "restore home menu
items" item is added to the bottom (otherwise these items would have no route
back)
Settings->Home Menu now contains help text about the CM method and a single
item to Restore Defaults
new EN strings added to support this (translations TBD)
TODO: no support for the items in My Apps yet
Modified:
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua
7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua
Modified:
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
URL:
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
---
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
(original)
+++
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
Fri Jul 23 12:35:56 2010
@@ -26,8 +26,10 @@
local Applet = require("jive.Applet")
local Checkbox = require("jive.ui.Checkbox")
local Window = require("jive.ui.Window")
+local ContextMenuWindow = require("jive.ui.ContextMenuWindow")
local Textarea = require('jive.ui.Textarea')
local Framework = require('jive.ui.Framework')
+local Timer = require('jive.ui.Timer')
local SimpleMenu = require("jive.ui.SimpleMenu")
@@ -53,131 +55,285 @@
return indent
end
+-- method to give menu of hidden items that can be restored individually back
to home menu
+-- this feature is currently disabled in the Meta file.
+function restoreHiddenItemMenu(self, menuItem)
+ local settings = self:getSettings()
+
+ local window = Window('home_menu', self:string("RESTORE_HIDDEN_ITEMS"))
+ local menu = SimpleMenu("menu")
+ local menuTable = jiveMain:getMenuTable()
+ local atLeastOneItem = false
+ for id, item in pairs(menuTable) do
+ if settings[id] == 'hidden' then
+ atLeastOneItem = true
+ menu:addItem({
+ text = item.text,
+ iconStyle = item.iconStyle,
+ callback = function()
+ appletManager:callService("goHome")
+ self:_timedExec( function()
+ self:getSettings()[item.id] =
'home'
+ jiveMain:addItemToNode(item,
'home')
+ self:_storeSettings('home')
+
+ -- immediately jump to the item
that's been restored
+ local menu =
jiveMain:getNodeMenu('home')
+ local restoredItemIdx =
menu:getIdIndex(item.id)
+
menu:setSelectedIndex(restoredItemIdx)
+
+ local somethingHidden = false
+ for id, item in
pairs(menuTable) do
+ if
self:getSettings()[id] == 'hidden' then
+ somethingHidden
= true
+ end
+ end
+ if not somethingHidden then
+ -- remove restore menu
items item
+ local restoreHomeItems
= jiveMain:getNodeItemById('appletCustomizeHomeRestoreHiddenItems', 'home')
+
jiveMain:removeItemFromNode(restoreHomeItems, 'home')
+
self:getSettings()['appletCustomizeHomeRestoreHiddenItems'] = nil
+
self:_storeSettings('home')
+ end
+ end, 500)
+ return EVENT_CONSUME
+ end,
+ })
+ end
+ end
+
+ local helpText = Textarea( 'help_text',
self:string('RESTORE_HIDDEN_ITEMS_HELP') )
+
+ if not atLeastOneItem then
+ window = Window('text_list',
self:string("RESTORE_HIDDEN_ITEMS"))
+ helpText = Textarea('help_text',
self:string('NO_HIDDEN_ITEMS') )
+ menu:addItem({
+ text = self:string('CUSTOMIZE_CANCEL'),
+ callback = function()
+ window:hide(Window.transitionPushRight)
+ return EVENT_CONSUME
+ end
+ })
+ end
+
+ menu:setHeaderWidget(helpText)
+ window:addWidget(menu)
+ window:show()
+end
+
function menu(self, menuItem)
log:info("menu")
- self.currentSettings = self:getSettings()
-
- -- get the menu table from jiveMain
- self.menuTable = jiveMain:getMenuTable()
- -- get items that have been customized
- --local customTable = jiveMain:getCustomTable()
-
- -- get the nodes. these become the choices + hidden
- self.nodeTable = jiveMain:getNodeTable()
-
- local homeMenuItems = {}
-
+
+ local menu = SimpleMenu("menu")
-- add an entry for returning everything to defaults
- table.insert(homeMenuItems,
+ menu:addItem(
{
text = self:string('CUSTOMIZE_RESTORE_DEFAULTS'),
weights = { 2000 },
callback = function()
self:restoreDefaultsMenu()
+ return EVENT_CONSUME
end
}
)
-
-
- for id, item in pairs(self.menuTable) do
- if id ~= 'hidden'
- and id ~= 'nowhere'
- -- a small hack to make sounds/effects not appear twice
- and id ~= 'opmlsounds'
- then
-
- local title, selected
-
- local complexWeight = jiveMain:getComplexWeight(id, item)
- local weights = {}
- item.weights = string.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
- selected = false
- -- elseif setting = 'home' or item.node = 'home', then select
- elseif (self.currentSettings[id] and self.currentSettings[id]
== 'home') or item.node == 'home' then
- selected = true
- -- anything else is unselect
- else
- selected = false
+ local window = Window("text_list", self:string("CUSTOMIZE_HOME"),
'settingstitle')
+ local help_text = Textarea('help_text',
self:string("CUSTOMIZE_HOME_HELP"))
+ menu:setHeaderWidget(help_text)
+ window:addWidget(menu)
+ window:show()
+end
+
+function homeMenuItemContextMenu(self, item)
+
+ local window = ContextMenuWindow(item.text)
+ local menu = SimpleMenu("menu")
+
+ menu:addItem({
+ text = self:string("CUSTOMIZE_CANCEL"),
+ sound = "WINDOWHIDE",
+ callback = function()
+ window:hide()
+ return EVENT_CONSUME
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
- title = item.text
- elseif item.homeMenuToken then
- title = indent ..
tostring(self:string(item.homeMenuToken))
- elseif item.homeMenuText then
- title = indent .. tostring(item.homeMenuText)
- else
- 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 = 'item_no_arrow'
- }
- else
- menuItem = {
- text = title,
- weights = item.weights,
- indent = indentSize,
- style = 'item_choice',
- check = 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')
+ })
+
+ local settings = self:getSettings()
+
+ if item.noCustom and item.node == 'home' then
+ menu:addItem({
+ text = self:string('ITEM_CANNOT_BE_HIDDEN'),
+ callback = function()
+ window:hide()
+ return EVENT_CONSUME
+ end
+ })
+ elseif item.node == 'home' or settings[item.id] == 'home' then
+ menu:addItem({
+ text = self:string('REMOVE_FROM_HOME'),
+ callback = function()
+ if item.node == 'home' then
+
+ -- add restore home menu items
at the bottom of the home menu
+ local restoreHomeItems =
jiveMain:getNodeItemById('appletCustomizeHomeRestoreHiddenItems',
'advancedSettings')
+ local homeItem =
jiveMain:addItemToNode(restoreHomeItems, 'home')
+ self:_timedExec(
+ function()
+
self:getSettings()[homeItem.id] = 'home'
+
jiveMain:setNode(item, 'hidden')
+
self:getSettings()[item.id] = 'hidden'
+
jiveMain:itemToBottom(homeItem, 'home')
end
- else
- if item.node == 'home'
then
-
self:getSettings()[item.id] = 'hidden'
-
jiveMain:setNode(item, 'hidden')
- else
+ )
+
+ else
+ self:_timedExec(
+ function()
self:getSettings()[item.id] = nil
jiveMain:removeItemFromNode(item, 'home')
end
- end
- self:storeSettings()
- end,
- selected
- ),
- }
- end
- if not item.synthetic then
- table.insert(homeMenuItems, menuItem)
- end
- end
- end
-
- local menu = SimpleMenu("menu", homeMenuItems )
- menu:setComparator(menu.itemComparatorComplexWeightAlpha)
-
- local window = Window("text_list", self:string("CUSTOMIZE_HOME"),
'settingstitle')
+ )
+
+ end
+ self:_storeSettings('home')
+ window:hide()
+ return EVENT_CONSUME
+ end
+ })
+ else
+ menu:addItem({
+ text = self:string('ADD_TO_HOME'),
+ callback = function()
+ self:getSettings()[item.id] = 'home'
+ local homeItem = jiveMain:addItemToNode(item,
'home')
+ jiveMain:itemToBottom(homeItem, 'home')
+ window:hide()
+ self:_storeSettings('home')
+
+ self:_timedExec(
+ function()
+
appletManager:callService("goHome")
+ local menu =
jiveMain:getNodeMenu('home')
+ local restoredItemIdx =
menu:getIdIndex(item.id)
+
menu:setSelectedIndex(restoredItemIdx)
+ end
+ )
+
+ return EVENT_CONSUME
+ end
+ })
+ end
+
+ local node = 'home'
+ if #Framework.windowStack > 1 then
+ node = item.node
+ end
+
+ -- this is for suppressing actions that don't make sense in context,
+ -- e.g. move to top when already at top
+ local nodeMenu = jiveMain:getNodeMenu(node)
+ local itemIdx = nodeMenu:getIdIndex(item.id)
+
+ if itemIdx > 1 then
+ menu:addItem({
+ text = self:string("MOVE_TO_TOP"),
+ callback = function()
+ window:hide()
+ self:_timedExec(
+ function()
+ jiveMain:itemToTop(item, node)
+ self:_storeSettings(node)
+ end
+ )
+ return EVENT_CONSUME
+ end
+ })
+ end
+
+ if itemIdx < #nodeMenu.items then
+ menu:addItem({
+ text = self:string("MOVE_TO_BOTTOM"),
+ callback = function()
+ window:hide()
+ self:_timedExec(
+ function()
+ jiveMain:itemToBottom(item,
node)
+ self:_storeSettings(node)
+ end
+ )
+ return EVENT_CONSUME
+ end
+ })
+ end
+
+ if itemIdx > 1 then
+ menu:addItem({
+ text = self:string("MOVE_UP_ONE"),
+ callback = function()
+ window:hide()
+ self:_timedExec(
+ function()
+ jiveMain:itemUpOne(item, node)
+ self:_storeSettings(node)
+ end
+ )
+ return EVENT_CONSUME
+ end
+ })
+ end
+
+ if itemIdx < #nodeMenu.items then
+ menu:addItem({
+ text = self:string("MOVE_DOWN_ONE"),
+ callback = function()
+ window:hide()
+ self:_timedExec(
+ function()
+ jiveMain:itemDownOne(item, node)
+ self:_storeSettings(node)
+ end
+ )
+ return EVENT_CONSUME
+ end
+ })
+ end
+
+
window:addWidget(menu)
- window:show()
-end
+ window:show(Window.transitionFadeIn)
+ return
+end
+
+-- many of the UI functions of repositioning items work better
+-- if there's a small delay before execution so the user sees them happening
+function _timedExec(self, func, delay)
+
+ if not delay then
+ delay = 350
+ end
+ local timer = Timer(delay, func, true)
+ timer:start()
+
+end
+
+function _storeSettings(self, node)
+ if not node then
+ return
+ end
+ local menu = jiveMain:getNodeMenu(node)
+ if not menu then
+ log:error('no menu found for ', node)
+ end
+ local menuItems = {}
+ for i, v in ipairs (menu.items) do
+ table.insert(menuItems, v.id)
+ end
+
+ local settings = self:getSettings()
+ settings._nodes[node] = menuItems
+ self:storeSettings()
+end
+
function restoreDefaultsMenu(self, id)
local window = Window("help_list",
self:string("CUSTOMIZE_RESTORE_DEFAULTS"), 'settingstitle')
@@ -187,6 +343,7 @@
sound = "WINDOWHIDE",
callback = function()
window:hide()
+ return EVENT_CONSUME
end
},
{
@@ -194,17 +351,27 @@
sound = "WINDOWSHOW",
callback = function()
local currentSettings = self:getSettings()
- for id, node in pairs(currentSettings) do
- self:getSettings()[id] = nil
- -- fetch item by id
- local item = jiveMain:getMenuItem(id)
- -- replace to original node, remove
customNode
- if item then
- jiveMain:setNode(item,
item.node)
+ for id, customNode in pairs(currentSettings) do
+ if id == '_nodes' then
+ for node, itemList in
pairs(customNode) do
+ local menu =
jiveMain:getNodeMenu(node)
+ log:info('resorting ',
node, ' by weight/alpha')
+
menu:setComparator(SimpleMenu.itemComparatorWeightAlpha)
+ end
+ self:getSettings()._nodes = {}
+ else
+ self:getSettings()[id] = nil
+ -- fetch item by id
+ local item =
jiveMain:getMenuItem(id)
+ -- replace to original node,
remove customNode
+ if item then
+ jiveMain:setNode(item,
item.node)
+ end
end
end
self:storeSettings()
- _goHome()
+ appletManager:callService("goHome")
+ return EVENT_CONSUME
end
},
})
@@ -214,8 +381,3 @@
window:show()
end
--- goHome
--- pushes the home window to the top
-function _goHome()
- jiveMain:goHome()
-end
Modified:
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
URL:
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
---
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
(original)
+++
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua
Fri Jul 23 12:35:56 2010
@@ -1,8 +1,11 @@
-local pairs = pairs
+local pairs, ipairs = pairs, ipairs
local oo = require("loop.simple")
local AppletMeta = require("jive.AppletMeta")
+local debug = require("jive.utils.debug")
+local SimpleMenu = require("jive.ui.SimpleMenu")
local appletManager = appletManager
+local jnt = jnt
local jiveMain = jiveMain
@@ -16,11 +19,14 @@
function defaultSettings(self)
return {
+ nodes = {},
}
end
function configureApplet(self)
-
+ jnt:subscribe(self)
+ self:registerService("homeMenuItemContextMenu")
+
end
@@ -32,7 +38,38 @@
end
jiveMain:addItem(self:menuItem('appletCustomizeHome', 'settings',
"CUSTOMIZE_HOME", function(applet, ...) applet:menu(...) end, 55, nil,
"hm_appletCustomizeHome"))
-
+ jiveMain:addItem(self:menuItem('appletCustomizeHomeRestoreHiddenItems',
'advancedSettings', "RESTORE_HIDDEN_ITEMS", function(applet, ...)
applet:restoreHiddenItemMenu(...) end, _, nil, _))
end
+function notify_playerLoaded(self, player)
+ log:debug('notify_playerLoaded(): ', player)
+
+ -- now that the menu is loaded, retrieve the home menu items from
jive.ui.HomeMenu
+ local homeMenuItems = jiveMain:getNodeTable()
+ for node, data in pairs (homeMenuItems) do
+ jiveMain:rankMenuItems(node)
+ local menu = jiveMain:getNodeMenu(node)
+ menu:setComparator(SimpleMenu.itemComparatorRank)
+ end
+ -- FIXME: pull in stored settings and resort as needed here?
+ local settings = self:getSettings()
+ if settings and settings._nodes then
+ for node, table in pairs(settings._nodes) do
+ for i, v in ipairs(table) do
+ local item = jiveMain:getNodeItemById(v, node)
+ if item then
+ jiveMain:setRank(item, i)
+ end
+ end
+ local menu = jiveMain:getNodeMenu(node)
+ menu:setComparator(SimpleMenu.itemComparatorRank)
+ jiveMain:rankMenuItems(node)
+ end
+ else
+ -- create the _nodes table if it isn't there
+ self:getSettings()._nodes = {}
+ self:storeSettings()
+ end
+
+end
Modified:
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
URL:
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
---
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
(original)
+++
7.6/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
Fri Jul 23 12:35:56 2010
@@ -92,3 +92,54 @@
RU ÐажмиÑе ÐºÐ½Ð¾Ð¿ÐºÑ "ÐÑодолжиÑÑ", ÑÑобÑ
ÑдалиÑÑ Ð²Ñе оÑганизаÑионнÑе наÑÑÑойки
полÑзоваÑелÑÑкого менÑ.
SV Välj Fortsätt om du vill ta bort alla anpassade
inställningar för menyordning
+RESTORE_HIDDEN_ITEMS
+ EN Restore Home Menu Items
+
+REMOVE_FROM_HOME
+ EN Hide from Home Menu
+
+ADD_TO_HOME
+ EN Add to Home Menu
+
+RESTORE_HIDDEN_ITEMS_HELP
+ EN Select an item to restore to the Home Menu. The following items
have been hidden from view:
+
+CUSTOMIZE_HOME_HELP
+ EN By pressing the + button on a selected Settings menu item and
choosing "Add to Home Menu", the item can be added to the Home Menu. Items
already in the Home Menu can be hidden from view via the same method.
+
+CUSTOMIZE_HOME_HELP_FAB4
+ EN Touch-hold on a selected Settings Menu item and choose "Add to
Home Menu" to add the item to the Home Menu. Items already in the Home Menu can
be hidden from view via the same method.
+
+NONE
+ CS Žádný
+ DA Ingen
+ DE Keine
+ EN None
+ ES Ninguno
+ FI Ei mitään
+ FR Aucun
+ IT Nessuno
+ NL Geen
+ NO Ingen
+ PL Brak
+ RU ÐеÑ
+ SV Ingen
+
+NO_HIDDEN_ITEMS
+ EN Currently no items are hidden from view on the Home Menu.
+
+ITEM_CANNOT_BE_HIDDEN
+ EN This item cannot be hidden
+
+MOVE_TO_TOP
+ EN Move to top
+
+MOVE_TO_BOTTOM
+ EN Move to bottom
+
+MOVE_UP_ONE
+ EN Move up one
+
+MOVE_DOWN_ONE
+ EN Move down one
+
Modified: 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua
URL:
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua (original)
+++ 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua Fri Jul 23
12:35:56 2010
@@ -1,5 +1,5 @@
-local assert, pairs, type, tostring, tonumber, setmetatable = assert, pairs,
type, tostring, tonumber, setmetatable
+local assert, ipairs, pairs, type, tostring, tonumber, setmetatable = assert,
ipairs, pairs, type, tostring, tonumber, setmetatable
local oo = require("loop.base")
local table = require("jive.utils.table")
@@ -13,9 +13,12 @@
local debug = require("jive.utils.debug")
local log = require("jive.utils.log").logger("squeezeplay.ui")
+local appletManager = require("jive.AppletManager")
+
local EVENT_WINDOW_ACTIVE = jive.ui.EVENT_WINDOW_ACTIVE
local EVENT_WINDOW_INACTIVE = jive.ui.EVENT_WINDOW_INACTIVE
local EVENT_UNUSED = jive.ui.EVENT_UNUSED
+
-- our class
module(..., oo.class)
@@ -158,6 +161,174 @@
end
end
+function setRank(self, item, rank)
+ log:debug('setting rank for ', item.id , ' from ', item.rank, ' to ',
rank)
+ item.rank = rank
+end
+
+
+function getWeight(self, item)
+ return item.weight
+end
+
+-- goes through an established home menu node and sets the ranks from 1..N
+-- assists in the ability for CustomizeHomeMenuApplet to move items up/down
one in the menu
+-- also needs to be run after any item is added to an already ranked menu
+function rankMenuItems(self, node)
+ if not self.nodeTable and not self.nodeTable[node] then
+ log:error('rankMenuItems not given proper args')
+ return
+ end
+ local menu = self:getNodeMenu(node)
+
+ local rank = 1
+ for i, v in ipairs (menu.items) do
+ self:setRank(v, rank)
+ rank = rank + 1
+ log:debug('v.id: ', v.id, ' rank: ', rank, '--->', v)
+ end
+
+ menu:setComparator(SimpleMenu.itemComparatorRank)
+end
+
+
+function getNodeMenu(self, node)
+ local menu = self.nodeTable and self.nodeTable[node] and
self.nodeTable[node].menu
+ if not menu or not menu.items then
+ log:error('no menu object found for ', node)
+ return false
+ end
+ return menu
+end
+
+
+function itemUpOne(self, item, node)
+ if not node then
+ node = 'home'
+ end
+ local menu = self:getNodeMenu(node)
+ if not menu then
+ return
+ end
+
+ -- first make sure we have a ranked weight menu
+ self:rankMenuItems(node)
+
+ local rank = 1
+ for i, v in ipairs(menu.items) do
+ if v == item then
+ if rank == 1 then
+ log:info('Item is already at the top')
+ else
+ local itemAbove = menu.items[i - 1]
+ self:setRank(itemAbove, rank)
+ self:setRank(v, rank - 1)
+ menu:setSelectedIndex(rank - 1)
+
menu:setComparator(SimpleMenu.itemComparatorRank)
+ break
+ end
+ end
+ rank = rank + 1
+ end
+end
+
+function itemDownOne(self, item, node)
+ if not node then
+ node = 'home'
+ end
+ local menu = self:getNodeMenu(node)
+ if not menu then
+ return
+ end
+
+ -- first make sure the items are ranked in order
+ self:rankMenuItems(node)
+
+ local rank = 1
+ for i, v in ipairs(menu.items) do
+ if v == item then
+ if rank == #menu.items then
+ log:info('Item is already at the bottom')
+ else
+ local itemBelow = menu.items[i + 1]
+ self:setRank(itemBelow, rank)
+ self:setRank(v, rank + 1)
+
menu:setComparator(SimpleMenu.itemComparatorRank)
+ menu:setSelectedIndex(rank + 1)
+ break
+ end
+ end
+ rank = rank + 1
+ end
+end
+
+function itemToBottom(self, item, node)
+ if not node then
+ node = 'home'
+ end
+ local menu = self:getNodeMenu(node)
+ if not menu then
+ return
+ end
+
+ -- first make sure the items are ranked in order
+ self:rankMenuItems(node)
+
+ local rank = 1
+ for i, v in ipairs(menu.items) do
+ if v == item then
+ if rank == #menu.items then
+ log:info('Item is already at the bottom')
+ else
+ local bottomIndex = #menu.items
+ -- note: order matters here, you don't want to
rankMenuItems until the menu has been resorted
+ self:setRank(v, bottomIndex + 1)
+ menu:setSelectedIndex(bottomIndex)
+
menu:setComparator(SimpleMenu.itemComparatorRank)
+ self:rankMenuItems('home')
+ break
+ end
+ end
+ rank = rank + 1
+ end
+end
+
+
+function itemToTop(self, item, node)
+ if not node then
+ node = 'home'
+ end
+ local menu = self:getNodeMenu(node)
+ if not menu then
+ return
+ end
+
+ -- first make sure the items are ranked in order
+ self:rankMenuItems(node)
+
+ local rank = 1
+ for i, v in ipairs(menu.items) do
+ if v == item then
+ if rank == 1 then
+ log:info('Item is already at the top')
+ else
+ self:setRank(v, 1)
+ end
+ else
+ self:setRank(v, rank + 1)
+
+ end
+ rank = rank + 1
+ end
+ menu:setSelectedIndex(1)
+
+ -- sort menu before ranking it
+ menu:setComparator(SimpleMenu.itemComparatorRank)
+ self:rankMenuItems(node)
+
+end
+
+
function setTitle(self, title)
if title then
self.window:setTitle(title)
@@ -240,9 +411,12 @@
return
end
- log:debug("JiveMain.addNode: Adding a non-root node, ", item.id)
-
item.isANode = 1
+
+ item.cmCallback = function()
+ appletManager:callService("homeMenuItemContextMenu", item)
+ return EVENT_CONSUME
+ end
if not item.weight then
item.weight = 100
@@ -266,18 +440,6 @@
end
local window
- -- FIXME: this if clause is mostly for mini icon support, which is
either going obsolete
- -- or will need to be implemented differently after the skin reorg
effort
- --[[
- if item.window and item.window.titleStyle then
- window = Window("text_list", item.text, item.window.titleStyle
.. "title")
- elseif item.titleStyle then
- window = Window("text_list", item.text, item.titleStyle ..
"title")
- else
- window = Window("text_list", item.text)
- end
- --]]
-
if item.windowStyle then
window = Window(item.windowStyle, item.text)
else
@@ -329,12 +491,34 @@
if self.nodeTable[node] then
self.nodeTable[node].items[item.id] = item
local menuIdx = self.nodeTable[node].menu:addItem(item)
- if node == 'home' and item.homeMenuText then
+ -- items in the home menu get special handling and a new table
created for them
+ if node == 'home' then
local labelText = item.homeMenuText
+ if not labelText then
+ if item.text.str then
+ -- FIXME: by grabbing the home menu
text directly from item.text.str here, this creates
+ -- a bug where if the user changes
languages these items do not change their language
+ labelText = item.text.str
+ else
+ labelText = item.text
+ end
+ end
-- change the menu item's text by creating a new item
table with different label text
- local myItem = _uses(item, { text = labelText })
+ local myItem = _uses(item, {
+ text = labelText,
+ })
+ -- rewrite the callback for CM to use myItem instead of
item
+ myItem.cmCallback = function()
+
appletManager:callService("homeMenuItemContextMenu", myItem)
+ return EVENT_CONSUME
+ end
self.customMenuTable[myItem.id] = myItem
- self.nodeTable[node].menu:replaceIndex(myItem, menuIdx)
+ self.nodeTable[node].menu:addItem(myItem)
+ self.nodeTable[node].items[myItem.id] = myItem
+ return myItem
+
+ else
+ return item
end
end
@@ -345,6 +529,10 @@
assert(item.id)
assert(item.node)
+ item.cmCallback = function()
+ appletManager:callService("homeMenuItemContextMenu", item)
+ return EVENT_CONSUME
+ end
if item.iconStyle then
item.icon = Icon(item.iconStyle)
end
@@ -518,6 +706,11 @@
end
+function getNodeItemById(self, id, node)
+ return self.nodeTable and self.nodeTable[node] and
self.nodeTable[node].items and self.nodeTable[node].items[id]
+
+end
+
-- lock an item in the menu
function lockItem(self, item, ...)
if self.customNodes[item.id] then
Modified: 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua
URL:
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua?rev=8987&r1=8986&r2=8987&view=diff
==============================================================================
--- 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua
(original)
+++ 7.6/trunk/squeezeplay/src/squeezeplay/share/jive/ui/SimpleMenu.lua Fri Jul
23 12:35:56 2010
@@ -351,6 +351,27 @@
end
+--[[
+
+=head2 jive.ui.Menu.itemComparatorRank
+
+Item comparator to sort items by rank (i.e. using item.rank).
+
+=cut
+--]]
+function itemComparatorRank(a, b)
+ local w
+ if a.rank and b.rank then
+ w = a.rank - b.rank
+ else
+ w = a.weight - b.weight
+ end
+
+ return (w < 0)
+end
+
+
+
--[[
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins