WIP: using new dmon_watch_add function

This commit is contained in:
Francesco Abbate 2021-09-20 17:51:46 +02:00
parent 3fa8866532
commit 31eed0c61a
2 changed files with 22 additions and 3 deletions

View File

@ -153,6 +153,9 @@ end
function core.project_subdir_set_show(dir, filename, show) function core.project_subdir_set_show(dir, filename, show)
dir.shown_subdir[filename] = show dir.shown_subdir[filename] = show
if dir.files_limit then
system.watch_dir_add(dir.watch_id, dir.name .. PATHSEP .. filename)
end
end end
@ -176,9 +179,13 @@ local function scan_project_folder(index)
if entries_count > config.max_project_files then if entries_count > config.max_project_files then
print("DEBUG setting files limit FLAG for", dir.name) print("DEBUG setting files limit FLAG for", dir.name)
dir.files_limit = true dir.files_limit = true
-- Watch non-recursively
dir.watch_id = system.watch_dir(path, false)
if core.status_view then -- May be not yet initialized. if core.status_view then -- May be not yet initialized.
show_max_files_warning() show_max_files_warning()
end end
else
dir.watch_id = system.watch_dir(path, true)
end end
dir.files = t dir.files = t
core.dir_rescan_add_job(dir, ".") core.dir_rescan_add_job(dir, ".")
@ -190,13 +197,13 @@ function core.add_project_directory(path)
-- will be simply the name of the directory, without its path. -- will be simply the name of the directory, without its path.
-- The field item.topdir will identify it as a top level directory. -- The field item.topdir will identify it as a top level directory.
path = normalize_path(path) path = normalize_path(path)
local watch_id = system.watch_dir(path); -- local watch_id = system.watch_dir(path)
local dir = { local dir = {
name = path, name = path,
item = {filename = common.basename(path), type = "dir", topdir = true}, item = {filename = common.basename(path), type = "dir", topdir = true},
files_limit = false, files_limit = false,
is_dirty = true, is_dirty = true,
watch_id = watch_id, -- watch_id = watch_id,
shown_subdir = {}, shown_subdir = {},
} }
table.insert(core.project_directories, dir) table.insert(core.project_directories, dir)

View File

@ -648,12 +648,23 @@ static int f_set_window_opacity(lua_State *L) {
static int f_watch_dir(lua_State *L) { static int f_watch_dir(lua_State *L) {
const char *path = luaL_checkstring(L, 1); const char *path = luaL_checkstring(L, 1);
dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, DMON_WATCHFLAGS_RECURSIVE, NULL); const int recursive = lua_toboolean(L, 2);
uint32_t dmon_flags = (recursive ? DMON_WATCHFLAGS_RECURSIVE : 0);
dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, dmon_flags, NULL);
if (watch_id.id == 0) { luaL_error(L, "directory monitoring watch failed"); } if (watch_id.id == 0) { luaL_error(L, "directory monitoring watch failed"); }
lua_pushnumber(L, watch_id.id); lua_pushnumber(L, watch_id.id);
return 1; return 1;
} }
static int f_watch_dir_add(lua_State *L) {
dmon_watch_id watch_id;
watch_id.id = luaL_checkinteger(L, 1);
const char *subdir = luaL_checkstring(L, 2);
bool success = dmon_watch_add(watch_id, subdir);
lua_pushboolean(L, success);
return 1;
}
#ifdef _WIN32 #ifdef _WIN32
#define PATHSEP '\\' #define PATHSEP '\\'
#else #else
@ -739,6 +750,7 @@ static const luaL_Reg lib[] = {
{ "fuzzy_match", f_fuzzy_match }, { "fuzzy_match", f_fuzzy_match },
{ "set_window_opacity", f_set_window_opacity }, { "set_window_opacity", f_set_window_opacity },
{ "watch_dir", f_watch_dir }, { "watch_dir", f_watch_dir },
{ "watch_dir_add", f_watch_dir_add },
{ "path_compare", f_path_compare }, { "path_compare", f_path_compare },
{ NULL, NULL } { NULL, NULL }
}; };