Remove duplicate normalize_path function
Use the function defined in the "common" module. Move the check for not-nil filename from common.normalize_path to core.open_doc. In this latter the filename can be nil if a new unnamed document is created.
This commit is contained in:
parent
1c6325b40f
commit
0ce5680ef2
|
@ -229,7 +229,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
function common.normalize_path(filename)
|
function common.normalize_path(filename)
|
||||||
if filename and PATHSEP == '\\' then
|
if PATHSEP == '\\' then
|
||||||
filename = filename:gsub('[/\\]', '\\')
|
filename = filename:gsub('[/\\]', '\\')
|
||||||
local drive, rem = filename:match('^([a-zA-Z])(:.*)')
|
local drive, rem = filename:match('^([a-zA-Z])(:.*)')
|
||||||
return drive and drive:upper() .. rem or filename
|
return drive and drive:upper() .. rem or filename
|
||||||
|
|
|
@ -34,14 +34,8 @@ local function save_session()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function normalize_path(s)
|
|
||||||
local drive, path = s:match("^([a-z]):([/\\].*)")
|
|
||||||
return drive and drive:upper() .. ":" .. path or s
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function update_recents_project(action, dir_path_abs)
|
local function update_recents_project(action, dir_path_abs)
|
||||||
local dirname = normalize_path(dir_path_abs)
|
local dirname = common.normalize_path(dir_path_abs)
|
||||||
if not dirname then return end
|
if not dirname then return end
|
||||||
local recents = core.recent_projects
|
local recents = core.recent_projects
|
||||||
local n = #recents
|
local n = #recents
|
||||||
|
@ -68,7 +62,7 @@ function core.set_project_dir(new_dir, change_project_fn)
|
||||||
local chdir_ok = pcall(system.chdir, new_dir)
|
local chdir_ok = pcall(system.chdir, new_dir)
|
||||||
if chdir_ok then
|
if chdir_ok then
|
||||||
if change_project_fn then change_project_fn() end
|
if change_project_fn then change_project_fn() end
|
||||||
core.project_dir = normalize_path(new_dir)
|
core.project_dir = common.normalize_path(new_dir)
|
||||||
core.project_directories = {}
|
core.project_directories = {}
|
||||||
core.add_project_directory(new_dir)
|
core.add_project_directory(new_dir)
|
||||||
core.project_files = {}
|
core.project_files = {}
|
||||||
|
@ -327,7 +321,7 @@ function core.add_project_directory(path)
|
||||||
-- top directories has a file-like "item" but the item.filename
|
-- top directories has a file-like "item" but the item.filename
|
||||||
-- will be simply the name of the directory, without its path.
|
-- will be simply the name of the directory, without its path.
|
||||||
-- The field item.topdir will identify it as a top level directory.
|
-- The field item.topdir will identify it as a top level directory.
|
||||||
path = normalize_path(path)
|
path = common.normalize_path(path)
|
||||||
table.insert(core.project_directories, {
|
table.insert(core.project_directories, {
|
||||||
name = path,
|
name = path,
|
||||||
item = {filename = common.basename(path), type = "dir", topdir = true},
|
item = {filename = common.basename(path), type = "dir", topdir = true},
|
||||||
|
@ -750,7 +744,7 @@ function core.open_doc(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- no existing doc for filename; create new
|
-- no existing doc for filename; create new
|
||||||
filename = core.normalize_to_project_dir(filename)
|
filename = filename and core.normalize_to_project_dir(filename)
|
||||||
local doc = Doc(filename)
|
local doc = Doc(filename)
|
||||||
table.insert(core.docs, doc)
|
table.insert(core.docs, doc)
|
||||||
core.log_quiet(filename and "Opened doc \"%s\"" or "Opened new doc", filename)
|
core.log_quiet(filename and "Opened doc \"%s\"" or "Opened new doc", filename)
|
||||||
|
|
Loading…
Reference in New Issue