Show max files warning message for initial project

If the max number of files limit is achieved when the application
is starting the StatusView is not yet configured so we cannot
show the warning.

We show the warning in the function scanning the directory only if
the StatusView is up. On the other side, when the application starts
it will check if the initial project dir hit the max files limit and
show the warning if needed.
This commit is contained in:
Francesco Abbate 2021-07-19 10:47:31 +02:00
parent 019280f2ed
commit becd817ec4
2 changed files with 37 additions and 17 deletions

View File

@ -150,24 +150,25 @@ local function get_directory_files(root, path, t, recursive, begin_hook)
end
local function show_max_files_warning()
core.status_view:show_message("!", style.accent,
"Too many files in project directory: stopped reading at "..
config.max_project_files.." files. For more information see "..
"usage.md at github.com/franko/lite-xl."
)
end
-- Populate a project folder top directory by scanning the filesystem.
function core.scan_project_folder(index)
local function scan_project_folder(index)
local dir = core.project_directories[index]
local t, entries_count = get_directory_files(dir.name, "", {}, true)
if entries_count > config.max_project_files then
dir.files_limit = true
if core.status_view then -- FIXME
core.status_view:show_message("!", style.accent,
"Too many files in project directory: stopped reading at "..
config.max_project_files.." files. For more information see "..
"usage.md at github.com/franko/lite-xl."
)
if core.status_view then -- May be not yet initialized.
show_max_files_warning()
end
end
dir.files = t
if dir.name == core.project_dir then
core.project_files = dir.files
end
end
@ -177,15 +178,18 @@ function core.add_project_directory(path)
-- The field item.topdir will identify it as a top level directory.
path = common.normalize_path(path)
local watch_id = system.watch_dir(path)
print("DEBUG watch_id:", watch_id)
table.insert(core.project_directories, {
local dir = {
name = path,
item = {filename = common.basename(path), type = "dir", topdir = true},
files_limit = false,
is_dirty = true,
watch_id = watch_id,
})
core.scan_project_folder(#core.project_directories)
}
table.insert(core.project_directories, dir)
scan_project_folder(#core.project_directories)
if path == core.project_dir then
core.project_files = dir.files
end
core.redraw = true
end
@ -323,13 +327,11 @@ local function project_scan_remove_file(watch_id, filepath)
end
end
if not project_dir_entry then return end
print("LOOKING for", filepath, " in", project_dir_entry and project_dir_entry.name)
local fileinfo = { filename = filepath }
for _, filetype in ipairs {"dir", "file"} do
fileinfo.type = filetype
local index, match = file_search(project_dir_entry.files, fileinfo)
if match then
print("FOUND", filepath, " at index", index)
table.remove(project_dir_entry.files, index)
project_dir_entry.is_dirty = true
return
@ -596,6 +598,12 @@ function core.init()
end
local got_project_error = not core.load_project_module()
-- We assume we have just a single project directory here. Now that StatusView
-- is there show max files warning if needed.
if core.project_directories[1].files_limit then
show_max_files_warning()
end
for _, filename in ipairs(files) do
core.root_view:open_doc(core.open_doc(filename))
end
@ -1030,7 +1038,6 @@ function core.on_event(type, ...)
elseif type == "focuslost" then
core.root_view:on_focus_lost(...)
elseif type == "dirchange" then
print("DEBUG: dirchange", select(1, ...), select(2, ...), select(3, ...))
core.on_dir_change(...)
elseif type == "quit" then
core.quit()

View File

@ -1,3 +1,16 @@
`core.set_project_dir`:
Reset project directories and set its directory.
It chdir into the directory, empty the `core.project_directories` and add
the given directory.
`core.add_project_directory`:
Add a new top-level directory to the project.
Also called from modules and commands outside core.init.
`core.scan_project_folder`:
Scan all files for a given top-level project directory.
Can emit a warning about file limit.
Called only from within core.init module.
`core.scan_project_folder`: (renamed to `core.scan_project_subdir`)
scan a single folder, without recursion. Used when too many files.