From c0f0325bbb2943a15fc588cfd71622974976e5a5 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 8 Dec 2020 09:42:11 +0100 Subject: [PATCH] Fix behavior of project manager to store directories --- data/core/rootview.lua | 1 + data/plugins/projectmanager.lua | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 690fdeec..de66a01f 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -19,6 +19,7 @@ local function draw_text(x, y, color) local lines = { { fmt = "%s to run a command", cmd = "core:find-command" }, { fmt = "%s to open a file from the project", cmd = "core:find-file" }, + { fmt = "%s to open a folder", cmd = "project-manager:open-folder" }, } th = style.font:get_height() y = y + (dh - th * 2 - style.padding.y) / 2 diff --git a/data/plugins/projectmanager.lua b/data/plugins/projectmanager.lua index 5ba7a4a2..073fcbee 100644 --- a/data/plugins/projectmanager.lua +++ b/data/plugins/projectmanager.lua @@ -17,16 +17,12 @@ end load_projects() local function serialize(val) - if type(val) == "string" then - return string.format("%q", val) - elseif type(val) == "table" then - local t = {} - for k, v in pairs(val) do - table.insert(t, "[" .. serialize(k) .. "]=" .. serialize(v)) - end - return "{" .. table.concat(t, ",") .. "}" + local ls = {"{"} + for i = 1, #val do + ls[#ls + 1] = " " .. string.format("%q", val[i]) .. "," end - return tostring(val) + ls[#ls + 1] = "}" + return table.concat(ls, "\n") end local function save_projects() @@ -44,17 +40,26 @@ end function project_manager.open_folder() core.command_view:enter("Open Folder", function(text) + local path_stat = system.get_file_info(text) + if not path_stat or path_stat.type ~= 'dir' then + core.error("Cannot open folder %q", text) + return + end if core.confirm_close_all() then core.root_view:close_all_docviews() table.insert(project_manager.recents, text) save_projects() core.switch_project = text end - end, common.dir_path_suggest) + end, function(text) + return text == "" and project_manager.recents or common.dir_path_suggest(text) + end) end command.add(nil, { ["project-manager:open-folder"] = project_manager.open_folder, }) +keymap.add { ["ctrl+shift+o"] = "project-manager:open-folder" } + return project_manager