Merge branch 'master' into dev

This commit is contained in:
Francesco Abbate 2021-02-17 23:57:02 +01:00
commit 59fbf9cfc0
6 changed files with 56 additions and 22 deletions

View File

@ -7,17 +7,9 @@ local LogView = require "core.logview"
local fullscreen = false
local function home_encode_list(paths)
local t = {}
for i = 1, #paths do
t[i] = common.home_encode(paths[i])
end
return t
end
local function suggest_directory(text)
text = common.home_expand(text)
return home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text))
return common.home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text))
end
command.add(nil, {
@ -95,7 +87,7 @@ command.add(nil, {
core.command_view:enter("Open File", function(text)
core.root_view:open_doc(core.open_doc(common.home_expand(text)))
end, function (text)
return home_encode_list(common.path_suggest(common.home_expand(text)))
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
end)
end,
@ -107,12 +99,6 @@ command.add(nil, {
["core:open-user-module"] = function()
local user_module_doc = core.open_doc(USERDIR .. "/init.lua")
if not user_module_doc then return end
local doc_save = user_module_doc.save
user_module_doc.save = function(self)
doc_save(self)
core.reload_module("core.style")
core.load_user_directory()
end
core.root_view:open_doc(user_module_doc)
end,
@ -184,7 +170,7 @@ command.add(nil, {
end
end, function(text)
text = common.home_expand(text)
return home_encode_list(common.dir_list_suggest(text, dir_list))
return common.home_encode_list(common.dir_list_suggest(text, dir_list))
end)
end,
})

View File

@ -67,6 +67,7 @@ end
local function save(filename)
doc():save(filename)
core.on_doc_save(filename)
core.log("Saved \"%s\"", doc().filename)
end
@ -297,8 +298,10 @@ local commands = {
core.command_view:set_text(doc().filename)
end
core.command_view:enter("Save As", function(filename)
save(filename)
end, common.path_suggest)
save(common.home_expand(filename))
end, function (text)
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
end)
end,
["doc:save"] = function()

View File

@ -214,9 +214,28 @@ function common.home_encode(text)
end
function common.home_encode_list(paths)
local t = {}
for i = 1, #paths do
t[i] = common.home_encode(paths[i])
end
return t
end
function common.home_expand(text)
return HOME and text:gsub("^~", HOME) or text
end
function common.normalize_path(filename)
if PATHSEP == '\\' then
filename = filename:gsub('[/\\]', '\\')
local drive, rem = filename:match('^([a-zA-Z])(:.*)')
return drive and drive:upper() .. rem or filename
end
return filename
end
return common

View File

@ -67,6 +67,7 @@ end
function Doc:load(filename)
local fp = assert( io.open(filename, "rb") )
filename = common.normalize_path(filename)
self:reset()
self.filename = filename
self.lines = {}
@ -93,7 +94,7 @@ function Doc:save(filename)
fp:write(line)
end
fp:close()
self.filename = filename or self.filename
self.filename = common.normalize_path(filename or self.filename)
self:reset_syntax()
self:clean()
end

View File

@ -7,6 +7,7 @@ local keymap
local RootView
local StatusView
local CommandView
local DocView
local Doc
local core = {}
@ -346,6 +347,7 @@ function core.init()
RootView = require "core.rootview"
StatusView = require "core.statusview"
CommandView = require "core.commandview"
DocView = require "core.docview"
Doc = require "core.doc"
do
@ -473,6 +475,19 @@ do
core.on_enter_project = do_nothing
end
core.doc_save_hooks = {}
function core.add_save_hook(fn)
core.doc_save_hooks[#core.doc_save_hooks + 1] = fn
end
function core.on_doc_save(filename)
for _, hook in ipairs(core.doc_save_hooks) do
hook(filename)
end
end
local function quit_with_function(quit_fn, force)
if force then
delete_temp_files()
@ -710,6 +725,7 @@ function core.step()
local mouse_moved = false
local mouse = { x = 0, y = 0, dx = 0, dy = 0 }
for type, a,b,c,d in system.poll_event do
if type == "mousemoved" then
mouse_moved = true
@ -746,7 +762,7 @@ function core.step()
-- update window title
local name = core.active_view:get_name()
local title = (name ~= "---") and (name .. " - lite") or "lite"
local title = (name ~= "---") and ( (core.active_view:is(DocView) and core.active_view.doc.filename or name) .. " - lite") or "lite"
if title ~= core.window_title then
system.set_window_title(title)
core.window_title = title
@ -839,4 +855,13 @@ function core.on_error(err)
end
core.add_save_hook(function(filename)
local doc = core.active_view.doc
if doc and doc:is(Doc) and doc.filename == common.normalize_path(USERDIR .. PATHSEP .. "init.lua") then
core.reload_module("core.style")
core.load_user_directory()
end
end)
return core

View File

@ -28,7 +28,7 @@ foreach data_module : ['core', 'fonts', 'plugins', 'colors']
endforeach
lite_link_args = []
if get_option('buildtype') == 'release'
if cc.get_id() == 'gcc' and get_option('buildtype') == 'release'
lite_link_args += ['-static-libgcc', '-static-libstdc++']
endif