Fix project change and quit versus workspace plugin
This commit is contained in:
parent
0e263af3c6
commit
b91a84eb56
|
@ -178,7 +178,7 @@ command.add(nil, {
|
||||||
end
|
end
|
||||||
core.add_project_directory(system.absolute_path(text))
|
core.add_project_directory(system.absolute_path(text))
|
||||||
-- TODO: add the name of directory to prioritize
|
-- TODO: add the name of directory to prioritize
|
||||||
core.request_project_scan()
|
core.reschedule_project_scan()
|
||||||
end, suggest_directory)
|
end, suggest_directory)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
@ -39,17 +39,37 @@ local function save_projects()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.request_project_scan()
|
function core.reschedule_project_scan()
|
||||||
|
if core.project_scan_thread_id then
|
||||||
core.threads[core.project_scan_thread_id].wake = 0
|
core.threads[core.project_scan_thread_id].wake = 0
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
core.project_files_empty = {}
|
||||||
|
|
||||||
|
|
||||||
|
function core.set_project_dir(new_dir)
|
||||||
|
core.project_dir = new_dir
|
||||||
|
system.chdir(new_dir)
|
||||||
|
core.project_directories = {}
|
||||||
|
core.add_project_directory(new_dir)
|
||||||
|
-- core.project_files will be set during the project files scan
|
||||||
|
-- to point to the files of the project directory.
|
||||||
|
-- core.project_files will therefore not include any of the added
|
||||||
|
-- directories.
|
||||||
|
core.project_files = core.project_files_empty
|
||||||
|
core.reschedule_project_scan()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.open_folder_project(dirname)
|
function core.open_folder_project(dirname)
|
||||||
|
core.on_quit_project()
|
||||||
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.set_project_dir(dirname)
|
||||||
core.request_project_scan()
|
core.on_enter_project(dirname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,6 +143,7 @@ local function project_scan_thread()
|
||||||
while true do
|
while true do
|
||||||
-- get project files and replace previous table if the new table is
|
-- get project files and replace previous table if the new table is
|
||||||
-- different
|
-- different
|
||||||
|
local include_project_dir = false
|
||||||
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, "")
|
||||||
|
@ -133,22 +154,21 @@ 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
|
||||||
dir.files = t
|
dir.files = t
|
||||||
if i == 1 then
|
if dir.name == core.project_dir then
|
||||||
|
include_project_dir = true
|
||||||
core.project_files = t
|
core.project_files = t
|
||||||
end
|
end
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not include_project_dir then
|
||||||
|
core.project_files = core.project_files_empty
|
||||||
|
end
|
||||||
|
|
||||||
-- wait for next scan
|
-- wait for next scan
|
||||||
if core.switch_project then
|
|
||||||
system.chdir(core.switch_project)
|
|
||||||
core.switch_project = nil
|
|
||||||
else
|
|
||||||
coroutine.yield(config.project_scan_rate)
|
coroutine.yield(config.project_scan_rate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function project_files_iter(state)
|
local function project_files_iter(state)
|
||||||
|
@ -312,23 +332,13 @@ function core.init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
system.chdir(project_dir)
|
|
||||||
|
|
||||||
core.frame_start = 0
|
core.frame_start = 0
|
||||||
core.clip_rect_stack = {{ 0,0,0,0 }}
|
core.clip_rect_stack = {{ 0,0,0,0 }}
|
||||||
core.log_items = {}
|
core.log_items = {}
|
||||||
core.docs = {}
|
core.docs = {}
|
||||||
core.threads = setmetatable({}, { __mode = "k" })
|
core.threads = setmetatable({}, { __mode = "k" })
|
||||||
|
|
||||||
-- core.project_files will always point to the files of
|
core.set_project_dir(system.absolute_path(project_dir))
|
||||||
-- core.project_directories[1]. We assume the first entry of
|
|
||||||
-- project_directories will always be the project's directory.
|
|
||||||
-- core.project_files will therefore not include any of the added
|
|
||||||
-- directories.
|
|
||||||
core.project_dir = system.absolute_path(".")
|
|
||||||
core.project_directories = {}
|
|
||||||
core.add_project_directory(core.project_dir)
|
|
||||||
core.project_files = core.project_directories[1].files
|
|
||||||
|
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
core.visited_files = {}
|
core.visited_files = {}
|
||||||
|
@ -403,14 +413,18 @@ function core.temp_filename(ext)
|
||||||
.. string.format("%06x", temp_file_counter) .. (ext or "")
|
.. string.format("%06x", temp_file_counter) .. (ext or "")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- override to perform an operation before quit
|
-- override to perform an operation before quitting or entering the
|
||||||
function core.on_quit()
|
-- current project
|
||||||
|
do
|
||||||
|
local do_nothing = function() end
|
||||||
|
core.on_quit_project = do_nothing
|
||||||
|
core.on_enter_project = do_nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
local function quit_with_function(quit_fn, force)
|
local function quit_with_function(quit_fn, force)
|
||||||
if force then
|
if force then
|
||||||
delete_temp_files()
|
delete_temp_files()
|
||||||
core.on_quit()
|
core.on_quit_project()
|
||||||
quit_fn()
|
quit_fn()
|
||||||
else
|
else
|
||||||
if core.confirm_close_all() then
|
if core.confirm_close_all() then
|
||||||
|
|
|
@ -147,7 +147,7 @@ local function create_directory_in(item)
|
||||||
core.error("cannot create directory %q: %s", dirname, err)
|
core.error("cannot create directory %q: %s", dirname, err)
|
||||||
end
|
end
|
||||||
item.expanded = true
|
item.expanded = true
|
||||||
core.request_project_scan()
|
core.reschedule_project_scan()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -183,10 +183,16 @@ function core.run(...)
|
||||||
if #core.docs == 0 then
|
if #core.docs == 0 then
|
||||||
core.try(load_workspace)
|
core.try(load_workspace)
|
||||||
|
|
||||||
local original_on_quit = core.on_quit
|
local on_quit_project = core.on_quit_project
|
||||||
function core.on_quit()
|
function core.on_quit_project()
|
||||||
save_workspace()
|
save_workspace()
|
||||||
original_on_quit()
|
on_quit_project()
|
||||||
|
end
|
||||||
|
|
||||||
|
local on_enter_project = core.on_enter_project
|
||||||
|
function core.on_enter_project(new_dir)
|
||||||
|
on_enter_project(new_dir)
|
||||||
|
core.try(load_workspace)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue