Fix checks when opening new project directory
This commit is contained in:
parent
827f3f876d
commit
656a89c494
|
@ -15,6 +15,15 @@ local function suggest_directory(text)
|
||||||
core.recent_projects or common.dir_path_suggest(text))
|
core.recent_projects or common.dir_path_suggest(text))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function check_directory_path(path)
|
||||||
|
local abs_path = system.absolute_path(path)
|
||||||
|
local info = abs_path and system.get_file_info(abs_path)
|
||||||
|
if not info or info.type ~= 'dir' then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return abs_path
|
||||||
|
end
|
||||||
|
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
["core:quit"] = function()
|
["core:quit"] = function()
|
||||||
core.quit()
|
core.quit()
|
||||||
|
@ -156,17 +165,17 @@ command.add(nil, {
|
||||||
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
||||||
end
|
end
|
||||||
core.command_view:enter("Change Project Folder", function(text)
|
core.command_view:enter("Change Project Folder", function(text)
|
||||||
text = system.absolute_path(common.home_expand(text))
|
local path = common.home_expand(text)
|
||||||
if text == core.project_dir then return end
|
local abs_path = check_directory_path(path)
|
||||||
local path_stat = system.get_file_info(text)
|
if not abs_path then
|
||||||
if not path_stat or path_stat.type ~= 'dir' then
|
core.error("Cannot open directory %q", path)
|
||||||
core.error("Cannot open folder %q", text)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if abs_path == core.project_dir then return end
|
||||||
core.confirm_close_docs(core.docs, function(dirpath)
|
core.confirm_close_docs(core.docs, function(dirpath)
|
||||||
core.close_current_project()
|
core.close_current_project()
|
||||||
core.open_folder_project(dirpath)
|
core.open_folder_project(dirpath)
|
||||||
end, text)
|
end, abs_path)
|
||||||
end, suggest_directory)
|
end, suggest_directory)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -176,13 +185,17 @@ command.add(nil, {
|
||||||
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
||||||
end
|
end
|
||||||
core.command_view:enter("Open Project", function(text)
|
core.command_view:enter("Open Project", function(text)
|
||||||
text = common.home_expand(text)
|
local path = common.home_expand(text)
|
||||||
local path_stat = system.get_file_info(text)
|
local abs_path = check_directory_path(path)
|
||||||
if not path_stat or path_stat.type ~= 'dir' then
|
if not abs_path then
|
||||||
core.error("Cannot open folder %q", text)
|
core.error("Cannot open directory %q", path)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
system.exec(string.format("%q %q", EXEFILE, text))
|
if abs_path == core.project_dir then
|
||||||
|
core.error("Directory %q is currently opened", abs_path)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
system.exec(string.format("%q %q", EXEFILE, abs_path))
|
||||||
end, suggest_directory)
|
end, suggest_directory)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue