Commit dde11735 authored by alex@thinkpad's avatar alex@thinkpad
Browse files

menu: allow submenu selection by name

(updated api_test.lua)

--HG--
branch : lua_fix
parent c4bcf87f07f6
......@@ -294,9 +294,8 @@ function test_menu()
msleep(1000)
-- enter the submenu
-- TODO: menu.select should handle submenus as well
-- fixme: return value
assert(menu.select("Intervalometer", "Take a pic every") == false)
key.press(KEY.Q)
msleep(1000)
-- note: setting menu by string works by brute force
......@@ -328,9 +327,23 @@ function test_menu()
msleep(1000)
-- exit submenu
key.press(KEY.Q)
assert(menu.select("Shoot", "Intervalometer"))
msleep(1000)
-- let's try some more submenus
-- fixme: return value
-- todo: more multi-level submenus
assert(menu.select("Advanced Bracket", "Frames") == false); msleep(1000)
assert(menu.select("Advanced Bracket", "Sequence") == false); msleep(1000)
assert(menu.select("Advanced Bracket", "ISO shifting") == false); msleep(1000)
assert(menu.select("Bulb Timer", "Exposure duration") == false); msleep(1000)
assert(menu.select("Shoot Preferences", "Snap Simulation") == false); msleep(1000)
assert(menu.select("Misc key settings", "Sticky HalfShutter") == false); msleep(1000)
assert(menu.select("Play mode actions", "Trigger key(s)") == false); msleep(1000)
assert(menu.select("LiveView zoom tweaks", "Zoom on HalfShutter") == false); msleep(1000)
assert(menu.select("Lens info", "Lens ID") == false); msleep(1000)
assert(menu.select("Shoot", "Intervalometer")); msleep(1000)
-- non-existent menus; should fail
assert(menu.select("Dinosaur") == false)
assert(menu.select("Shoot", "Crocodile") == false)
......@@ -1119,8 +1132,8 @@ function api_tests()
printf("Module tests...\n")
test_io()
test_camera_take_pics()
test_menu()
test_camera_take_pics()
msleep(1000)
test_multitasking()
test_keys()
......
......@@ -5536,62 +5536,81 @@ void select_menu(char* name, int entry_index)
//~ menu_damage = 1;
}
void select_menu_by_name(char* name, const char* entry_name)
static void select_menu_recursive(struct menu * selected_menu, const char * entry_name)
{
take_semaphore(menu_sem, 0);
printf("select_menu %s -> %s\n", selected_menu->name, entry_name);
/* select the first menu that matches the name, if any given */
/* otherwise, keep the selection unchanged */
struct menu * selected_menu = 0;
/* update selection flag for all entries from this menu */
for (struct menu * menu = menus; menu; menu = menu->next)
{
if (streq(menu->name, name))
{
selected_menu = menu;
break;
}
}
int menu_selected = (menu == selected_menu);
if (selected_menu)
{
if (IS_SUBMENU(selected_menu))
if (!IS_SUBMENU(selected_menu))
{
/* submenus are hard; you need to select all parents along the way */
give_semaphore(menu_sem);
return;
/* only select the menu if it's at the top level */
menu->selected = menu_selected;
if (menu_selected)
{
/* update last selected menu (only at the top level); see menu_move */
menu_first_by_icon = selected_menu->icon;
}
}
/* update selection flag for all entries from this menu */
for (struct menu * menu = menus; menu; menu = menu->next)
if ((menu == selected_menu) && entry_name)
{
menu->selected = (menu == selected_menu);
if (menu->selected && entry_name)
/* select the requested menu entry from this menu */
struct menu_entry * selected_entry = 0;
for (struct menu_entry * entry = menu->children; entry; entry = entry->next)
{
if (streq(entry->name, entry_name))
{
selected_entry = entry;
break;
}
}
if (selected_entry)
{
/* process menu entries from the selected menu in a similar way */
struct menu_entry * selected_entry = 0;
/* update selection flag for all entries from this menu */
for (struct menu_entry * entry = menu->children; entry; entry = entry->next)
{
if (streq(entry->name, entry_name))
{
selected_entry = entry;
break;
}
entry->selected = (entry == selected_entry);
}
if (selected_entry)
/* select parent menu entry, if any */
if (selected_entry->parent)
{
/* update selection flag for all entries from this menu */
for (struct menu_entry * entry = menu->children; entry; entry = entry->next)
{
entry->selected = (entry == selected_entry);
}
selected_entry = selected_entry->parent;
select_menu_recursive(selected_entry->parent_menu, selected_entry->name);
submenu_level++;
}
}
}
}
}
void select_menu_by_name(char* name, const char* entry_name)
{
take_semaphore(menu_sem, 0);
/* select the first menu that matches the name, if any given */
/* otherwise, keep the selection unchanged */
struct menu * selected_menu = 0;
for (struct menu * menu = menus; menu; menu = menu->next)
{
if (streq(menu->name, name))
{
selected_menu = menu;
break;
}
}
/* update other internal state (see menu_move) */
menu_first_by_icon = selected_menu->icon;
if (selected_menu)
{
submenu_level = 0;
select_menu_recursive(selected_menu, entry_name);
beta_set_warned();
}
give_semaphore(menu_sem);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment