Use relative path for filenames in project directories
This commit is contained in:
parent
5449781353
commit
39181a56fd
|
@ -70,11 +70,11 @@ local function project_scan_thread()
|
||||||
return a.filename < b.filename
|
return a.filename < b.filename
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_files(path, t)
|
local function get_files(root, path, t)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
t = t or {}
|
t = t or {}
|
||||||
local size_limit = config.file_size_limit * 10e5
|
local size_limit = config.file_size_limit * 10e5
|
||||||
local all = system.list_dir(path) or {}
|
local all = system.list_dir(root .. path) or {}
|
||||||
local dirs, files = {}, {}
|
local dirs, files = {}, {}
|
||||||
|
|
||||||
local entries_count = 0
|
local entries_count = 0
|
||||||
|
@ -82,7 +82,7 @@ local function project_scan_thread()
|
||||||
for _, file in ipairs(all) do
|
for _, file in ipairs(all) do
|
||||||
if not common.match_pattern(file, config.ignore_files) then
|
if not common.match_pattern(file, config.ignore_files) then
|
||||||
local file = path .. PATHSEP .. file
|
local file = path .. PATHSEP .. file
|
||||||
local info = system.get_file_info(file)
|
local info = system.get_file_info(root .. file)
|
||||||
if info and info.size < size_limit then
|
if info and info.size < size_limit then
|
||||||
info.filename = file
|
info.filename = file
|
||||||
table.insert(info.type == "dir" and dirs or files, info)
|
table.insert(info.type == "dir" and dirs or files, info)
|
||||||
|
@ -96,7 +96,7 @@ local function project_scan_thread()
|
||||||
for _, f in ipairs(dirs) do
|
for _, f in ipairs(dirs) do
|
||||||
table.insert(t, f)
|
table.insert(t, f)
|
||||||
if entries_count <= max_entries then
|
if entries_count <= max_entries then
|
||||||
local subdir_t, subdir_count = get_files(f.filename, t)
|
local subdir_t, subdir_count = get_files(root, f.filename, t)
|
||||||
entries_count = entries_count + subdir_count
|
entries_count = entries_count + subdir_count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -114,7 +114,7 @@ local function project_scan_thread()
|
||||||
-- different
|
-- different
|
||||||
for i = 1, #core.project_directories do
|
for i = 1, #core.project_directories do
|
||||||
local dir = core.project_directories[i]
|
local dir = core.project_directories[i]
|
||||||
local t, entries_count = get_files(dir.name)
|
local t, entries_count = get_files(dir.name, "")
|
||||||
if diff_files(dir.files, t) then
|
if diff_files(dir.files, t) then
|
||||||
if entries_count > config.max_project_files then
|
if entries_count > config.max_project_files then
|
||||||
core.status_view:show_message("!", style.accent,
|
core.status_view:show_message("!", style.accent,
|
||||||
|
@ -255,10 +255,11 @@ function core.init()
|
||||||
core.docs = {}
|
core.docs = {}
|
||||||
core.threads = setmetatable({}, { __mode = "k" })
|
core.threads = setmetatable({}, { __mode = "k" })
|
||||||
local dir_path = system.absolute_path(".")
|
local dir_path = system.absolute_path(".")
|
||||||
|
local dir_name = dir_path:match("[^\\/]+$")
|
||||||
core.project_directories = {
|
core.project_directories = {
|
||||||
{
|
{
|
||||||
name = dir_path,
|
name = dir_path,
|
||||||
item = {filename = dir_path, type = "dir", top_dir = true},
|
item = {filename = dir_name, type = "dir"},
|
||||||
files = {},
|
files = {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ local View = require "core.view"
|
||||||
config.treeview_size = 200 * SCALE
|
config.treeview_size = 200 * SCALE
|
||||||
|
|
||||||
local function get_depth(filename)
|
local function get_depth(filename)
|
||||||
local n = 1
|
local n = 0
|
||||||
for sep in filename:gmatch("[\\/]") do
|
for sep in filename:gmatch("[\\/]") do
|
||||||
n = n + 1
|
n = n + 1
|
||||||
end
|
end
|
||||||
|
@ -28,16 +28,11 @@ function TreeView:new()
|
||||||
self.last = {}
|
self.last = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function strip_leading_path(filename)
|
||||||
local function relative_filename(filename, dirname)
|
return filename:sub(2)
|
||||||
local n = #dirname
|
|
||||||
if filename:sub(1, n) == dirname then
|
|
||||||
return filename:sub(n + 1):match('[/\\](.*)')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function TreeView:get_cached(item, dirname)
|
function TreeView:get_cached(item, dirname)
|
||||||
local dir_cache = self.cache[dirname]
|
local dir_cache = self.cache[dirname]
|
||||||
if not dir_cache then
|
if not dir_cache then
|
||||||
|
@ -47,17 +42,11 @@ function TreeView:get_cached(item, dirname)
|
||||||
local t = dir_cache[item.filename]
|
local t = dir_cache[item.filename]
|
||||||
if not t then
|
if not t then
|
||||||
t = {}
|
t = {}
|
||||||
local rel = relative_filename(item.filename, dirname)
|
local basename = item.filename:match("[^\\/]+$")
|
||||||
-- FIXME: rel should never be nil here. to be verified.
|
t.filename = item.filename:match('^[/\\]') and strip_leading_path(item.filename) or basename
|
||||||
if item.top_dir then
|
t.depth = get_depth(item.filename)
|
||||||
t.filename = item.filename:match("[^\\/]+$")
|
t.abs_filename = dirname .. item.filename
|
||||||
t.depth = 0
|
t.name = basename
|
||||||
else
|
|
||||||
t.filename = rel or item.filename
|
|
||||||
t.depth = get_depth(t.filename)
|
|
||||||
end
|
|
||||||
t.abs_filename = item.filename
|
|
||||||
t.name = t.filename:match("[^\\/]+$")
|
|
||||||
t.type = item.type
|
t.type = item.type
|
||||||
dir_cache[item.filename] = t
|
dir_cache[item.filename] = t
|
||||||
end
|
end
|
||||||
|
@ -122,8 +111,7 @@ function TreeView:each_item()
|
||||||
else
|
else
|
||||||
local depth = cached.depth
|
local depth = cached.depth
|
||||||
while i <= #dir.files do
|
while i <= #dir.files do
|
||||||
local filename = relative_filename(dir.files[i].filename, dir.name)
|
if get_depth(dir.files[i].filename) <= depth then break end
|
||||||
if get_depth(filename) <= depth then break end
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
cached.skip = i
|
cached.skip = i
|
||||||
|
@ -153,7 +141,7 @@ function TreeView:on_mouse_pressed(button, x, y)
|
||||||
self.hovered_item.expanded = not self.hovered_item.expanded
|
self.hovered_item.expanded = not self.hovered_item.expanded
|
||||||
else
|
else
|
||||||
core.try(function()
|
core.try(function()
|
||||||
core.root_view:open_doc(core.open_doc(self.hovered_item.filename))
|
core.root_view:open_doc(core.open_doc(self.hovered_item.abs_filename))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue