Finalize add project directory feature
This commit is contained in:
@@ -73,14 +73,14 @@ command.add(nil, {
|
|||||||
|
|
||||||
["core:find-file"] = function()
|
["core:find-file"] = function()
|
||||||
local files = {}
|
local files = {}
|
||||||
for _, item in pairs(core.project_files) do
|
for dir, item in core.project_files() do
|
||||||
if item.type == "file" then
|
if item.type == "file" then
|
||||||
table.insert(files, item.filename)
|
local filename = dir == core.project_dir and item.filename:match('^[/\\](.+)') or dir .. item.filename
|
||||||
|
table.insert(files, common.home_encode(filename))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
core.command_view:enter("Open File From Project", function(text, item)
|
core.command_view:enter("Open File From Project", function(text, item)
|
||||||
text = item and item.text or text
|
core.root_view:open_doc(core.open_doc(common.home_expand(text)))
|
||||||
core.root_view:open_doc(core.open_doc(text))
|
|
||||||
end, function(text)
|
end, function(text)
|
||||||
if text == "" then
|
if text == "" then
|
||||||
local recent_files = {}
|
local recent_files = {}
|
||||||
@@ -164,4 +164,21 @@ command.add(nil, {
|
|||||||
system.exec(string.format("%q %q", EXEFILE, text))
|
system.exec(string.format("%q %q", EXEFILE, text))
|
||||||
end, suggest_directory)
|
end, suggest_directory)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
["core:add-directory"] = function()
|
||||||
|
core.command_view:enter("Open Project", function(text)
|
||||||
|
text = common.home_expand(text)
|
||||||
|
local path_stat, err = system.get_file_info(text)
|
||||||
|
if not path_stat then
|
||||||
|
core.error("cannot open %q: %s", text, err)
|
||||||
|
return
|
||||||
|
elseif path_stat.type ~= 'dir' then
|
||||||
|
core.error("%q is not a directory", text)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
core.add_project_directory(system.absolute_path(text))
|
||||||
|
core.request_project_scan()
|
||||||
|
end, suggest_directory)
|
||||||
|
end,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
+35
-10
@@ -47,12 +47,18 @@ local function save_projects()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function core.request_project_scan()
|
||||||
|
core.threads[core.project_scan_thread_id].wake = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.open_folder_project(dirname)
|
function core.open_folder_project(dirname)
|
||||||
core.root_view:close_all_docviews()
|
core.root_view:close_all_docviews()
|
||||||
add_project_to_recents(dirname)
|
add_project_to_recents(dirname)
|
||||||
save_projects()
|
save_projects()
|
||||||
core.switch_project = dirname
|
core.switch_project = dirname
|
||||||
core.threads[core.project_scan_thread_id].wake = 0
|
core.request_project_scan()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function project_scan_thread()
|
local function project_scan_thread()
|
||||||
@@ -137,6 +143,24 @@ local function project_scan_thread()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function project_files_iter(state)
|
||||||
|
local dir = core.project_directories[state.dir_index]
|
||||||
|
state.file_index = state.file_index + 1
|
||||||
|
while dir and state.file_index > #dir.files do
|
||||||
|
state.dir_index = state.dir_index + 1
|
||||||
|
state.file_index = 1
|
||||||
|
dir = core.project_directories[state.dir_index]
|
||||||
|
end
|
||||||
|
if not dir then return end
|
||||||
|
return dir.name, dir.files[state.file_index]
|
||||||
|
end
|
||||||
|
|
||||||
|
function core.project_files()
|
||||||
|
local state = { dir_index = 1, file_index = 0 }
|
||||||
|
return project_files_iter, state
|
||||||
|
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()
|
||||||
@@ -223,6 +247,13 @@ function core.load_user_directory()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function core.add_project_directory(path)
|
||||||
|
table.insert(core.project_directories, {
|
||||||
|
name = path,
|
||||||
|
item = {filename = path:match("[^\\/]+$"), type = "dir"},
|
||||||
|
files = {}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
function core.init()
|
function core.init()
|
||||||
command = require "core.command"
|
command = require "core.command"
|
||||||
@@ -254,15 +285,9 @@ function core.init()
|
|||||||
core.log_items = {}
|
core.log_items = {}
|
||||||
core.docs = {}
|
core.docs = {}
|
||||||
core.threads = setmetatable({}, { __mode = "k" })
|
core.threads = setmetatable({}, { __mode = "k" })
|
||||||
local dir_path = system.absolute_path(".")
|
core.project_dir = system.absolute_path(".")
|
||||||
local dir_name = dir_path:match("[^\\/]+$")
|
core.project_directories = {}
|
||||||
core.project_directories = {
|
core.add_project_directory(core.project_dir)
|
||||||
{
|
|
||||||
name = dir_path,
|
|
||||||
item = {filename = dir_name, type = "dir"},
|
|
||||||
files = {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
core.visited_files = {}
|
core.visited_files = {}
|
||||||
core.restart_request = false
|
core.restart_request = false
|
||||||
|
|||||||
@@ -43,7 +43,12 @@ function TreeView:get_cached(item, dirname)
|
|||||||
if not t then
|
if not t then
|
||||||
t = {}
|
t = {}
|
||||||
local basename = item.filename:match("[^\\/]+$")
|
local basename = item.filename:match("[^\\/]+$")
|
||||||
t.filename = item.filename:match('^[/\\]') and strip_leading_path(item.filename) or basename
|
if item.filename:match('^[/\\]') then
|
||||||
|
t.filename = strip_leading_path(item.filename)
|
||||||
|
else
|
||||||
|
t.filename = basename
|
||||||
|
t.expanded = true
|
||||||
|
end
|
||||||
t.depth = get_depth(item.filename)
|
t.depth = get_depth(item.filename)
|
||||||
t.abs_filename = dirname .. item.filename
|
t.abs_filename = dirname .. item.filename
|
||||||
t.name = basename
|
t.name = basename
|
||||||
@@ -97,7 +102,7 @@ function TreeView:each_item()
|
|||||||
coroutine.yield(dir_cached, ox, y, w, h)
|
coroutine.yield(dir_cached, ox, y, w, h)
|
||||||
y = y + h
|
y = y + h
|
||||||
local i = 1
|
local i = 1
|
||||||
while i <= #dir.files do
|
while i <= #dir.files and dir_cached.expanded do
|
||||||
local item = dir.files[i]
|
local item = dir.files[i]
|
||||||
local cached = self:get_cached(item, dir.name)
|
local cached = self:get_cached(item, dir.name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user