summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.lua79
1 files changed, 62 insertions, 17 deletions
diff --git a/main.lua b/main.lua
index 17a5007..0ed84b5 100644
--- a/main.lua
+++ b/main.lua
@@ -449,6 +449,57 @@ local function push_group_menu(group)
update_osd()
end
+local update_search_matches
+
+local function set_menu_sort(menu, bool)
+ if not menu.sorted == not bool then
+ return
+ end
+
+ local key = menu.type == 'search' and 'search_options' or 'options'
+ if bool then
+ menu['orig_' .. key] = menu[key]
+ menu[key] = util.copy_table(menu[key])
+ sort_options(menu[key])
+ else
+ menu[key] = menu['orig_' .. key]
+ menu['orig_' .. key] = nil
+ end
+
+ if menu.type == 'search' then
+ update_search_matches()
+ end
+ menu.sorted = bool
+end
+
+local function refresh_favourites_menu()
+ local menu = menus[depth]
+ local opt = menu.options[menu.cursor]
+ local sorted = menu.sorted
+ if sorted then
+ set_menu_sort(menu, false)
+ end
+
+ local options = group_menu_options(catalogue:get(menu.group_id))
+ local seen = {}
+ for _, v in ipairs(options) do
+ seen[v.id] = true
+ end
+ for _, v in ipairs(menu.options) do
+ if not seen[v.id] then
+ options[#options+1] = v
+ end
+ end
+ menu.options = options
+
+ if sorted then
+ set_menu_sort(menu, true)
+ end
+ if opt then
+ cursor_to_object(opt.id)
+ end
+end
+
local function prev_menu()
depth = depth - 1
@@ -456,6 +507,9 @@ local function prev_menu()
-- reset main menu
push_group_menu(catalogue:get(menus[1].group_id))
else
+ if menus[depth].group_id == 'favourites' then
+ refresh_favourites_menu()
+ end
update_osd()
end
end
@@ -514,8 +568,13 @@ local function goto_option()
return
end
- if menu.type == 'search' or menu.group_id == 'favourites' then
+ if menu.group_id == 'favourites' then
+ depth = 1
+ elseif menu.type == 'search' then
depth = depth - 1
+ if menus[depth].group_id == 'favourites' then
+ refresh_favourites_menu()
+ end
end
if opt.path then
@@ -810,7 +869,7 @@ local function search_menu_options(options)
return ret
end
-local function update_search_matches()
+function update_search_matches()
local menu = menus[depth]
if #menu.search_text == 0 then
@@ -990,21 +1049,7 @@ local function toggle_menu_sort()
return
end
- local key = menu.type == 'search' and 'search_options' or 'options'
-
- menu.sorted = not menu.sorted
- if menu.sorted then
- menu['orig_' .. key] = menu[key]
- menu[key] = util.copy_table(menu[key])
- sort_options(menu[key])
- else
- menu[key] = menu['orig_' .. key]
- menu['orig_' .. key] = nil
- end
-
- if menu.type == 'search' then
- update_search_matches()
- end
+ set_menu_sort(menu, not menu.sorted)
update_osd()
end