feat: **back** in file menus now navigates up the directory tree

closes #367
This commit is contained in:
tomasklaen
2022-11-14 09:22:32 +01:00
parent 107e758144
commit 682fd81a85
2 changed files with 32 additions and 17 deletions

View File

@@ -178,6 +178,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
items[#items + 1] = {title = '..', hint = 'parent dir', value = directory.dirname, separator = true}
end
local back_path = items[#items] and items[#items].value
local selected_index = #items + 1
for _, dir in ipairs(directories) do
@@ -197,13 +198,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
if opts.selected_path == item.value then selected_index = index end
end
local menu_data = {
type = opts.type, title = opts.title or directory.basename .. path_separator, items = items,
selected_index = selected_index,
}
local menu_options = {on_open = opts.on_open, on_close = opts.on_close}
return Menu:open(menu_data, function(path)
local function open_path(path)
local is_drives = path == '{drives}'
local is_to_parent = is_drives or #path < #directory_path
local inheritable_options = {
@@ -237,7 +232,19 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
else
handle_select(path)
end
end, menu_options)
end
local function handle_back()
if back_path then open_path(back_path) end
end
local menu_data = {
type = opts.type, title = opts.title or directory.basename .. path_separator, items = items,
selected_index = selected_index,
}
local menu_options = {on_open = opts.on_open, on_close = opts.on_close, on_back = handle_back}
return Menu:open(menu_data, open_path, menu_options)
end
-- Opens a file navigation menu with Windows drives as items.