Fix directories management to always keep the project's directory

This commit is contained in:
Francesco Abbate 2021-01-03 12:02:07 +01:00
parent d7885133a0
commit e548a6adb9
3 changed files with 9 additions and 19 deletions

View File

@ -185,12 +185,12 @@ command.add(nil, {
["core:remove-directory"] = function()
local dir_list = {}
local n = #core.project_directories
for i = n, 1, -1 do
for i = n, 2, -1 do
dir_list[n - i + 1] = core.project_directories[i].name
end
core.command_view:enter("Remove Directory", function(text)
if not core.remove_project_directory(text) then
core.error("The project has no directory %q", text)
core.error("No added directory %q to be removed", text)
end
end, function(text)
text = common.home_expand(text)

View File

@ -11,8 +11,6 @@ local Doc
local core = {}
core.project_files_empty = {}
local function load_session()
local ok, t = pcall(dofile, USERDIR .. "/session.lua")
if ok then
@ -65,11 +63,7 @@ function core.set_project_dir(new_dir)
system.chdir(new_dir)
core.project_directories = {}
core.add_project_directory(new_dir)
-- core.project_files will be set during the project files scan
-- to point to the files of the project directory.
-- core.project_files will therefore not include any of the added
-- directories.
core.project_files = core.project_files_empty
core.project_files = {}
core.reschedule_project_scan()
end
@ -153,7 +147,6 @@ local function project_scan_thread()
while true do
-- get project files and replace previous table if the new table is
-- different
local include_project_dir = false
for i = 1, #core.project_directories do
local dir = core.project_directories[i]
local t, entries_count = get_files(dir.name, "")
@ -167,13 +160,9 @@ local function project_scan_thread()
core.redraw = true
end
if dir.name == core.project_dir then
include_project_dir = true
core.project_files = dir.files
end
end
if not include_project_dir then
core.project_files = core.project_files_empty
end
-- wait for next scan
coroutine.yield(config.project_scan_rate)
@ -310,7 +299,9 @@ end
function core.remove_project_directory(path)
for i, dir in ipairs(core.project_directories) do
-- skip the fist directory because it is the project's directory
for i = 2, #core.project_directories do
local dir = core.project_directories[i]
if dir.name == path then
table.remove(core.project_directories, i)
return true

View File

@ -141,8 +141,8 @@ end
local function save_directories()
local project_dir = core.project_dir
local dir_list = {}
for i, dir in ipairs(core.project_directories) do
dir_list[i] = relative_path(project_dir, dir.name)
for i = 2, #core.project_directories do
dir_list[#dir_list + 1] = relative_path(project_dir, core.project_directories[i].name)
end
return dir_list
end
@ -169,7 +169,6 @@ local function load_workspace()
if active_view then
core.set_active_view(active_view)
end
core.project_directories = {}
for i, dir_name in ipairs(t.directories) do
core.add_project_directory(system.absolute_path(dir_name))
end
@ -185,7 +184,7 @@ function core.run(...)
local on_quit_project = core.on_quit_project
function core.on_quit_project()
save_workspace()
core.try(save_workspace)
on_quit_project()
end