Fix behavior of project manager to store directories

This commit is contained in:
Francesco Abbate 2020-12-08 09:42:11 +01:00
parent a3adfeb8f6
commit c0f0325bbb
2 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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