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 = { local lines = {
{ fmt = "%s to run a command", cmd = "core:find-command" }, { 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 file from the project", cmd = "core:find-file" },
{ fmt = "%s to open a folder", cmd = "project-manager:open-folder" },
} }
th = style.font:get_height() th = style.font:get_height()
y = y + (dh - th * 2 - style.padding.y) / 2 y = y + (dh - th * 2 - style.padding.y) / 2

View File

@ -17,16 +17,12 @@ end
load_projects() load_projects()
local function serialize(val) local function serialize(val)
if type(val) == "string" then local ls = {"{"}
return string.format("%q", val) for i = 1, #val do
elseif type(val) == "table" then ls[#ls + 1] = " " .. string.format("%q", val[i]) .. ","
local t = {}
for k, v in pairs(val) do
table.insert(t, "[" .. serialize(k) .. "]=" .. serialize(v))
end
return "{" .. table.concat(t, ",") .. "}"
end end
return tostring(val) ls[#ls + 1] = "}"
return table.concat(ls, "\n")
end end
local function save_projects() local function save_projects()
@ -44,17 +40,26 @@ end
function project_manager.open_folder() function project_manager.open_folder()
core.command_view:enter("Open Folder", function(text) 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 if core.confirm_close_all() then
core.root_view:close_all_docviews() core.root_view:close_all_docviews()
table.insert(project_manager.recents, text) table.insert(project_manager.recents, text)
save_projects() save_projects()
core.switch_project = text core.switch_project = text
end end
end, common.dir_path_suggest) end, function(text)
return text == "" and project_manager.recents or common.dir_path_suggest(text)
end)
end end
command.add(nil, { command.add(nil, {
["project-manager:open-folder"] = project_manager.open_folder, ["project-manager:open-folder"] = project_manager.open_folder,
}) })
keymap.add { ["ctrl+shift+o"] = "project-manager:open-folder" }
return project_manager return project_manager