Add dmon_watch_rm function to remove subdir
This commit is contained in:
parent
93cf01adfc
commit
794fd6b47b
|
@ -154,7 +154,14 @@ end
|
|||
function core.project_subdir_set_show(dir, filename, show)
|
||||
dir.shown_subdir[filename] = show
|
||||
if dir.files_limit then
|
||||
system.watch_dir_add(dir.watch_id, dir.name .. PATHSEP .. filename)
|
||||
local fullpath = dir.name .. PATHSEP .. filename
|
||||
if show then
|
||||
local success = system.watch_dir_add(dir.watch_id, fullpath)
|
||||
print("DEBUG: watch_dir_add", fullpath, "success:", success)
|
||||
else
|
||||
local success = system.watch_dir_rm(dir.watch_id, fullpath)
|
||||
print("DEBUG: watch_dir_rm", fullpath, "success:", success)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
## from core/init.lua
|
||||
|
||||
- scan_project_folder set the watch_id recursively or not
|
||||
* called from core.add_project_directory
|
||||
- `scan_project_folder` set the `watch_id` recursively or not
|
||||
* called from `core.add_project_directory`
|
||||
|
||||
## from treeview.lua
|
||||
|
||||
TreeView:on_mouse_pressed
|
||||
* calls core.scan_project_subdir only in files_limit mode
|
||||
* calls core.project_subdir_set_show
|
||||
`TreeView:on_mouse_pressed`
|
||||
* calls `core.scan_project_subdir` only in `files_limit` mode
|
||||
* calls `core.project_subdir_set_show`
|
||||
|
|
|
@ -660,8 +660,15 @@ 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);
|
||||
lua_pushboolean(L, dmon_watch_add(watch_id, subdir));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int f_watch_dir_rm(lua_State *L) {
|
||||
dmon_watch_id watch_id;
|
||||
watch_id.id = luaL_checkinteger(L, 1);
|
||||
const char *subdir = luaL_checkstring(L, 2);
|
||||
lua_pushboolean(L, dmon_watch_rm(watch_id, subdir));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -751,6 +758,7 @@ static const luaL_Reg lib[] = {
|
|||
{ "set_window_opacity", f_set_window_opacity },
|
||||
{ "watch_dir", f_watch_dir },
|
||||
{ "watch_dir_add", f_watch_dir_add },
|
||||
{ "watch_dir_rm", f_watch_dir_rm },
|
||||
{ "path_compare", f_path_compare },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
33
src/dmon.h
33
src/dmon.h
|
@ -116,6 +116,7 @@ DMON_API_DECL dmon_watch_id dmon_watch(const char* rootdir,
|
|||
uint32_t flags, void* user_data);
|
||||
DMON_API_DECL void dmon_unwatch(dmon_watch_id id);
|
||||
DMON_API_DECL bool dmon_watch_add(dmon_watch_id id, const char* subdir);
|
||||
DMON_API_DECL bool dmon_watch_rm(dmon_watch_id id, const char* subdir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -820,6 +821,38 @@ DMON_API_IMPL bool dmon_watch_add(dmon_watch_id id, const char* watchdir)
|
|||
return true;
|
||||
}
|
||||
|
||||
DMON_API_IMPL bool dmon_watch_rm(dmon_watch_id id, const char* watchdir)
|
||||
{
|
||||
DMON_ASSERT(id.id > 0 && id.id <= DMON_MAX_WATCHES);
|
||||
|
||||
pthread_mutex_lock(&_dmon.mutex);
|
||||
dmon__watch_state* watch = &_dmon.watches[id.id - 1];
|
||||
|
||||
int i, c = stb_sb_count(watch->subdirs);
|
||||
for (i = 0; i < c; i++) {
|
||||
const dmon__watch_subdir *subdir = &watch->subdirs[i];
|
||||
if (strcmp(subdir->rootdir, watchdir) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= c) {
|
||||
_DMON_LOG_ERRORF("Watch directory '%s' is not valid", watchdir);
|
||||
pthread_mutex_unlock(&_dmon.mutex);
|
||||
return false;
|
||||
}
|
||||
inotify_rm_watch(fd, watch->wds[i]);
|
||||
|
||||
for (int j = i; j < c - 1; j++) {
|
||||
memcpy(watch->subdir + j, watch->subdir + j + 1, sizeof(dmon__watch_subdir));
|
||||
memcpy(watch->wds + j, watch->wds + j + 1, sizeof(int));
|
||||
}
|
||||
stb__sbraw(watch->subdir)[1] = c - 1;
|
||||
stb__sbraw(watch->wds )[1] = c - 1;
|
||||
|
||||
pthread_mutex_unlock(&_dmon.mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
_DMON_PRIVATE const char* dmon__find_subdir(const dmon__watch_state* watch, int wd)
|
||||
{
|
||||
const int* wds = watch->wds;
|
||||
|
|
Loading…
Reference in New Issue