Merge pull request #765 from Guldoman/treeview_remove_deleted
Better "Remove changed files/dirs from `TreeView` cache"
This commit is contained in:
commit
416a06c566
|
@ -1158,8 +1158,8 @@ end
|
||||||
|
|
||||||
|
|
||||||
-- no-op but can be overrided by plugins
|
-- no-op but can be overrided by plugins
|
||||||
function core.on_dirmonitor_modify(dir, filepath)
|
function core.on_dirmonitor_modify(dir, filepath) end
|
||||||
end
|
function core.on_dirmonitor_delete(dir, filepath) end
|
||||||
|
|
||||||
|
|
||||||
function core.on_dir_change(watch_id, action, filepath)
|
function core.on_dir_change(watch_id, action, filepath)
|
||||||
|
@ -1168,6 +1168,7 @@ function core.on_dir_change(watch_id, action, filepath)
|
||||||
core.dir_rescan_add_job(dir, filepath)
|
core.dir_rescan_add_job(dir, filepath)
|
||||||
if action == "delete" then
|
if action == "delete" then
|
||||||
project_scan_remove_file(dir, filepath)
|
project_scan_remove_file(dir, filepath)
|
||||||
|
core.on_dirmonitor_delete(dir, filepath)
|
||||||
elseif action == "create" then
|
elseif action == "create" then
|
||||||
project_scan_add_file(dir, filepath)
|
project_scan_add_file(dir, filepath)
|
||||||
core.on_dirmonitor_modify(dir, filepath);
|
core.on_dirmonitor_modify(dir, filepath);
|
||||||
|
|
|
@ -45,13 +45,18 @@ function TreeView:new()
|
||||||
|
|
||||||
self.item_icon_width = 0
|
self.item_icon_width = 0
|
||||||
self.item_text_spacing = 0
|
self.item_text_spacing = 0
|
||||||
|
self:add_core_hooks()
|
||||||
|
end
|
||||||
|
|
||||||
local on_dirmonitor_modify = core.on_dirmonitor_modify
|
|
||||||
function core.on_dirmonitor_modify(dir, filepath)
|
function TreeView:add_core_hooks()
|
||||||
if self.cache[dir.name] then
|
-- When a file or directory is deleted we delete the corresponding cache entry
|
||||||
self.cache[dir.name][filepath] = nil
|
-- because if the entry is recreated we may use wrong information from cache.
|
||||||
end
|
local on_delete = core.on_dirmonitor_delete
|
||||||
on_dirmonitor_modify(dir, filepath)
|
core.on_dirmonitor_delete = function(dir, filepath)
|
||||||
|
local cache = self.cache[dir.name]
|
||||||
|
if cache then cache[filepath] = nil end
|
||||||
|
on_delete(dir, filepath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue