View Full Version : Lua-specified context menus for MediaBridge

April 1st, 2006, 06:43 AM
Hi Ben,

I don't really want to distract you from finishing NR 2.0 - and especially finding and fixing the full-screen bug(s) on Pocket PC.

But I wonder if I could persuade you to add a new option to the MB playing-now-list, media-library-tree and search-results-list buttons? As I attach the code, it should not take more than an hour or so.

The idea is to allow the context menu for the three list/tree button actions to be optionally specified as a Lua table. For my PlayPick driver, I use the "MENU:<LuaMenuTable>" encoding in the button text, but any similar encoding would work.

What would be needed is in each of your notification handlers to add a couple of lines of code:

if &#40; &#40; hdr->hdr.code == NM_RCLICK || hdr->hdr.code == NM_RETURN
#ifdef _WIN32_WCE
|| hdr->hdr.code == LVN_KEYDOWN
|| hdr->hdr.code == GN_CONTEXTMENU
&#41; &#41;
// Get the information about the selected item,
// setting "selected" variables etc for use in Lua,
// which I hope is being done already!

if &#40; !m_menuLuaVariable.IsEmpty&#40;&#41; &#41;
DoLuaPopupMenu&#40; netremote, CWnd&#58;&#58;FromHandle&#40;m_listCtrl&#41;, m_menuLuaVariable &#41;;
// Do the default &#40;built-in&#41; context menu

Thereafter anyone could specify the context menu in the Lua as a table array with one or more items, each with mandatory fields "label" and "func", plus optional other fields. The menu popped-up would be constructed from the set of labels. When one is selected, its associated func() would be called, passing the complete selected item from the table as its only parameter (from where the func can get any other parameters it needs).


function OnCCFLoad&#40;&#41;

DemoListMenu = &#123;
&#123; label="One", func=DoMenu &#125;,
&#123; label="Two", func=DoMenu &#125;,
&#123; label="Three", func=DoMenu &#125;

function DoMenu&#40;selected&#41;
NetRemote.SetVariable&#40; 'Demo.Display', 'Menu Selected&#58; '..selected.label &#41;;
What do you think?

I attached the source of DoLuaPopupMenu(), which I believe should just drop in to your MB code. Note that this uses the "proper" Lua object and is not faked using LuaExecute() as a previous implementation did.

And can anyone else see the benefit in this?


Ben S
April 1st, 2006, 08:39 AM
I'll see what I can do, Brian. This is something I wanted to add sooner or later, as different players support different actions, and it's a little confusing.

April 1st, 2006, 08:47 AM
Thanks Ben,

It would also help with use in non-English countries (menus in Norwegian, Tor?)