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
+2 -2
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)
+4 -13
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