Preliminary version of projects with multiple directories
This commit is contained in:
parent
4416f219e4
commit
2f50f21f57
|
@ -84,7 +84,7 @@ local function project_scan_thread()
|
||||||
local file = (path ~= "." and path .. PATHSEP or "") .. file
|
local file = (path ~= "." and path .. PATHSEP or "") .. file
|
||||||
local info = system.get_file_info(file)
|
local info = system.get_file_info(file)
|
||||||
if info and info.size < size_limit then
|
if info and info.size < size_limit then
|
||||||
info.filename = file
|
info.filename = system.absolute_path(file)
|
||||||
table.insert(info.type == "dir" and dirs or files, info)
|
table.insert(info.type == "dir" and dirs or files, info)
|
||||||
entries_count = entries_count + 1
|
entries_count = entries_count + 1
|
||||||
if entries_count > max_entries then break end
|
if entries_count > max_entries then break end
|
||||||
|
@ -120,6 +120,7 @@ local function project_scan_thread()
|
||||||
config.max_project_files.." files according to config.max_project_files.")
|
config.max_project_files.." files according to config.max_project_files.")
|
||||||
end
|
end
|
||||||
core.project_files = t
|
core.project_files = t
|
||||||
|
core.project_directories[1] = {filename = system.absolute_path("."), type = "dir"}
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -252,6 +253,7 @@ function core.init()
|
||||||
core.docs = {}
|
core.docs = {}
|
||||||
core.threads = setmetatable({}, { __mode = "k" })
|
core.threads = setmetatable({}, { __mode = "k" })
|
||||||
core.project_files = {}
|
core.project_files = {}
|
||||||
|
core.project_directories = {}
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
core.visited_files = {}
|
core.visited_files = {}
|
||||||
core.restart_request = false
|
core.restart_request = false
|
||||||
|
|
|
@ -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 = 0
|
local n = 1
|
||||||
for sep in filename:gmatch("[\\/]") do
|
for sep in filename:gmatch("[\\/]") do
|
||||||
n = n + 1
|
n = n + 1
|
||||||
end
|
end
|
||||||
|
@ -28,16 +28,36 @@ function TreeView:new()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function TreeView:get_cached(item)
|
local function relative_filename(filename, dirname)
|
||||||
|
local n = #dirname
|
||||||
|
if filename:sub(1, n) == dirname then
|
||||||
|
return filename:sub(n + 1):match('[/\\](.*)')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function belongs_to_directory(item, dirname)
|
||||||
|
return relative_filename(item.filename, dirname)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function TreeView:get_cached(item, dirname)
|
||||||
local t = self.cache[item.filename]
|
local t = self.cache[item.filename]
|
||||||
if not t then
|
if not t then
|
||||||
t = {}
|
t = {}
|
||||||
t.filename = item.filename
|
if dirname then
|
||||||
t.abs_filename = system.absolute_path(item.filename)
|
local rel = relative_filename(item.filename, dirname)
|
||||||
|
-- FIXME: rel should never be nil here. to be verified.
|
||||||
|
t.filename = rel or item.filename
|
||||||
|
t.depth = get_depth(t.filename)
|
||||||
|
else
|
||||||
|
t.filename = item.filename:match("[^\\/]+$")
|
||||||
|
t.depth = 0
|
||||||
|
end
|
||||||
|
t.abs_filename = item.filename
|
||||||
t.name = t.filename:match("[^\\/]+$")
|
t.name = t.filename:match("[^\\/]+$")
|
||||||
t.depth = get_depth(t.filename)
|
|
||||||
t.type = item.type
|
t.type = item.type
|
||||||
self.cache[t.filename] = t
|
self.cache[item.filename] = t
|
||||||
end
|
end
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
@ -73,28 +93,41 @@ function TreeView:each_item()
|
||||||
local h = self:get_item_height()
|
local h = self:get_item_height()
|
||||||
|
|
||||||
local i = 1
|
local i = 1
|
||||||
while i <= #core.project_files do
|
-- FIXME: make this loop more efficient. Currently it takes O(M * N)
|
||||||
local item = core.project_files[i]
|
-- where M = (directories number) and N = (files number)
|
||||||
local cached = self:get_cached(item)
|
-- It should take O(N).
|
||||||
|
for idir, dir_item in ipairs(core.project_directories) do
|
||||||
coroutine.yield(cached, ox, y, w, h)
|
local dir_entry = self:get_cached(dir_item)
|
||||||
|
local dir_name = dir_item.filename
|
||||||
|
coroutine.yield(dir_entry, ox, y, w, h)
|
||||||
y = y + h
|
y = y + h
|
||||||
i = i + 1
|
while i <= #core.project_files do
|
||||||
|
local item = core.project_files[i]
|
||||||
|
if belongs_to_directory(item, dir_name) then
|
||||||
|
local cached = self:get_cached(item, dir_name)
|
||||||
|
|
||||||
if not cached.expanded then
|
coroutine.yield(cached, ox, y, w, h)
|
||||||
if cached.skip then
|
y = y + h
|
||||||
i = cached.skip
|
i = i + 1
|
||||||
else
|
|
||||||
local depth = cached.depth
|
if not cached.expanded then
|
||||||
while i <= #core.project_files do
|
if cached.skip then
|
||||||
local filename = core.project_files[i].filename
|
i = cached.skip
|
||||||
if get_depth(filename) <= depth then break end
|
else
|
||||||
i = i + 1
|
local depth = cached.depth
|
||||||
|
while i <= #core.project_files do
|
||||||
|
local filename = relative_filename(core.project_files[i].filename, dir_name)
|
||||||
|
if get_depth(filename) <= depth then break end
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
cached.skip = i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
cached.skip = i
|
else
|
||||||
|
i = i + 1
|
||||||
end
|
end
|
||||||
end
|
end -- while files
|
||||||
end
|
end -- for directories
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue