parent
857807b23a
commit
5766329313
|
@ -68,9 +68,10 @@ end
|
||||||
|
|
||||||
|
|
||||||
local function save(filename)
|
local function save(filename)
|
||||||
doc():save(filename)
|
doc():save(filename and core.normalize_to_project_dir(filename))
|
||||||
core.on_doc_save(filename)
|
local saved_filename = doc().filename
|
||||||
core.log("Saved \"%s\"", doc().filename)
|
core.on_doc_save(saved_filename)
|
||||||
|
core.log("Saved \"%s\"", saved_filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -247,6 +247,11 @@ local function split_on_slash(s, sep_pattern)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function common.path_belongs_to(filename, path)
|
||||||
|
return string.find(filename, path .. PATHSEP, 1, true) == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function common.relative_path(ref_dir, dir)
|
function common.relative_path(ref_dir, dir)
|
||||||
local ref_ls = split_on_slash(ref_dir)
|
local ref_ls = split_on_slash(ref_dir)
|
||||||
local dir_ls = split_on_slash(dir)
|
local dir_ls = split_on_slash(dir)
|
||||||
|
@ -259,9 +264,9 @@ function common.relative_path(ref_dir, dir)
|
||||||
end
|
end
|
||||||
local ups = ""
|
local ups = ""
|
||||||
for k = i, #ref_ls do
|
for k = i, #ref_ls do
|
||||||
ups = ups .. "../"
|
ups = ups .. ".." .. PATHSEP
|
||||||
end
|
end
|
||||||
local rel_path = ups .. table.concat(dir_ls, "/", i)
|
local rel_path = ups .. table.concat(dir_ls, PATHSEP, i)
|
||||||
return rel_path ~= "" and rel_path or "."
|
return rel_path ~= "" and rel_path or "."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,6 @@ end
|
||||||
|
|
||||||
|
|
||||||
function Doc:set_filename(filename)
|
function Doc:set_filename(filename)
|
||||||
filename = common.normalize_path(filename)
|
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.abs_filename = common.home_encode(system.absolute_path(filename))
|
self.abs_filename = common.home_encode(system.absolute_path(filename))
|
||||||
end
|
end
|
||||||
|
|
|
@ -732,18 +732,27 @@ function core.pop_clip_rect()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function core.normalize_to_project_dir(filename)
|
||||||
|
filename = common.normalize_path(filename)
|
||||||
|
if common.path_belongs_to(filename, core.project_dir) then
|
||||||
|
filename = common.relative_path(core.project_dir, filename)
|
||||||
|
end
|
||||||
|
return filename
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.open_doc(filename)
|
function core.open_doc(filename)
|
||||||
if filename then
|
if filename then
|
||||||
-- try to find existing doc for filename
|
-- try to find existing doc for filename
|
||||||
local abs_filename = system.absolute_path(filename)
|
local abs_filename = system.absolute_path(filename)
|
||||||
for _, doc in ipairs(core.docs) do
|
for _, doc in ipairs(core.docs) do
|
||||||
if doc.filename
|
if doc.abs_filename and abs_filename == doc.abs_filename then
|
||||||
and abs_filename == system.absolute_path(doc.filename) then
|
|
||||||
return doc
|
return doc
|
||||||
end
|
end
|
||||||
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)
|
||||||
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