WIP: implement adding of files in project's tree
When a dir monitor create event is received the file is added in the project's files tree.
This commit is contained in:
parent
79b65014a5
commit
2bc068d0b7
|
@ -293,21 +293,24 @@ function core.project_files_number()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function file_search(files, fileinfo)
|
local function file_search(files, info)
|
||||||
|
local filename, type = info.filename, info.type
|
||||||
local inf, sup = 1, #files
|
local inf, sup = 1, #files
|
||||||
while sup - inf > 8 do
|
while sup - inf > 8 do
|
||||||
local curr = math.floor((inf + sup) / 2)
|
local curr = math.floor((inf + sup) / 2)
|
||||||
if system.path_compare(fileinfo.filename, fileinfo.type, files[curr].filename, files[curr].type) then
|
if system.path_compare(filename, type, files[curr].filename, files[curr].type) then
|
||||||
sup = curr - 1
|
sup = curr - 1
|
||||||
else
|
else
|
||||||
inf = curr
|
inf = curr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i = inf, sup do
|
repeat
|
||||||
if files[i].filename == fileinfo.filename then
|
if files[inf].filename == filename then
|
||||||
return i
|
return inf, true
|
||||||
end
|
end
|
||||||
end
|
inf = inf + 1
|
||||||
|
until inf > sup or system.path_compare(filename, type, files[inf].filename, files[inf].type)
|
||||||
|
return inf, false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,8 +326,8 @@ local function project_scan_remove_file(watch_id, filepath)
|
||||||
local fileinfo = { filename = filepath }
|
local fileinfo = { filename = filepath }
|
||||||
for _, filetype in ipairs {"dir", "file"} do
|
for _, filetype in ipairs {"dir", "file"} do
|
||||||
fileinfo.type = filetype
|
fileinfo.type = filetype
|
||||||
local index = file_search(project_dir_entry.files, fileinfo)
|
local index, match = file_search(project_dir_entry.files, fileinfo)
|
||||||
if index then
|
if match then
|
||||||
print("FOUND", filepath, " at index", index)
|
print("FOUND", filepath, " at index", index)
|
||||||
table.remove(project_dir_entry.files, index)
|
table.remove(project_dir_entry.files, index)
|
||||||
project_dir_entry.is_dirty = true
|
project_dir_entry.is_dirty = true
|
||||||
|
@ -334,6 +337,25 @@ local function project_scan_remove_file(watch_id, filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function project_scan_add_file(watch_id, filepath)
|
||||||
|
local project_dir_entry
|
||||||
|
for i = 1, #core.project_directories do
|
||||||
|
if core.project_directories[i].watch_id == watch_id then
|
||||||
|
project_dir_entry = core.project_directories[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not project_dir_entry then return end
|
||||||
|
local size_limit = config.file_size_limit * 10e5
|
||||||
|
local fileinfo = get_project_file_info(project_dir_entry.name, PATHSEP .. filepath, size_limit)
|
||||||
|
local index, match = file_search(project_dir_entry.files, fileinfo)
|
||||||
|
if not match then
|
||||||
|
table.insert(project_dir_entry.files, index, fileinfo)
|
||||||
|
project_dir_entry.is_dirty = true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- create a directory using mkdir but may need to create the parent
|
-- create a directory using mkdir but may need to create the parent
|
||||||
-- directories as well.
|
-- directories as well.
|
||||||
local function create_user_directory()
|
local function create_user_directory()
|
||||||
|
@ -947,6 +969,8 @@ end
|
||||||
function core.on_dir_change(watch_id, action, filepath)
|
function core.on_dir_change(watch_id, action, filepath)
|
||||||
if action == "delete" then
|
if action == "delete" then
|
||||||
project_scan_remove_file(watch_id, filepath)
|
project_scan_remove_file(watch_id, filepath)
|
||||||
|
elseif action == "create" then
|
||||||
|
project_scan_add_file(watch_id, filepath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue