Add full filename path in window's title
Optimal implementation to limite computations in core.step.
This commit is contained in:
parent
59fbf9cfc0
commit
de1afb3391
|
@ -65,11 +65,17 @@ function Doc:reset_syntax()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Doc:set_filename(filename)
|
||||||
|
filename = common.normalize_path(filename)
|
||||||
|
self.filename = filename
|
||||||
|
self.abs_filename = common.home_encode(system.absolute_path(filename))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Doc:load(filename)
|
function Doc:load(filename)
|
||||||
local fp = assert( io.open(filename, "rb") )
|
local fp = assert( io.open(filename, "rb") )
|
||||||
filename = common.normalize_path(filename)
|
|
||||||
self:reset()
|
self:reset()
|
||||||
self.filename = filename
|
self:set_filename(filename)
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
for line in fp:lines() do
|
for line in fp:lines() do
|
||||||
if line:byte(-1) == 13 then
|
if line:byte(-1) == 13 then
|
||||||
|
@ -94,7 +100,9 @@ function Doc:save(filename)
|
||||||
fp:write(line)
|
fp:write(line)
|
||||||
end
|
end
|
||||||
fp:close()
|
fp:close()
|
||||||
self.filename = common.normalize_path(filename or self.filename)
|
if filename then
|
||||||
|
self:set_filename(filename)
|
||||||
|
end
|
||||||
self:reset_syntax()
|
self:reset_syntax()
|
||||||
self:clean()
|
self:clean()
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,6 +90,12 @@ function DocView:get_name()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function DocView:get_filename()
|
||||||
|
local post = self.doc:is_dirty() and "*" or ""
|
||||||
|
return (self.doc.abs_filename and self.doc.abs_filename or "unsaved") .. post
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function DocView:get_scrollable_size()
|
function DocView:get_scrollable_size()
|
||||||
return self:get_line_height() * (#self.doc.lines - 1) + self.size.y
|
return self:get_line_height() * (#self.doc.lines - 1) + self.size.y
|
||||||
end
|
end
|
||||||
|
|
|
@ -719,6 +719,17 @@ function core.on_event(type, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function get_title_filename(view)
|
||||||
|
local doc_filename = view.get_filename and view:get_filename() or view:get_name()
|
||||||
|
return (doc_filename ~= "---") and doc_filename or ""
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function compose_window_title(title)
|
||||||
|
return title == "" and "lite" or title .. " - lite"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.step()
|
function core.step()
|
||||||
-- handle events
|
-- handle events
|
||||||
local did_keymap = false
|
local did_keymap = false
|
||||||
|
@ -761,11 +772,10 @@ function core.step()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update window title
|
-- update window title
|
||||||
local name = core.active_view:get_name()
|
local current_title = get_title_filename(core.active_view)
|
||||||
local title = (name ~= "---") and ( (core.active_view:is(DocView) and core.active_view.doc.filename or name) .. " - lite") or "lite"
|
if current_title ~= core.window_title then
|
||||||
if title ~= core.window_title then
|
system.set_window_title(compose_window_title(current_title))
|
||||||
system.set_window_title(title)
|
core.window_title = current_title
|
||||||
core.window_title = title
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- draw
|
-- draw
|
||||||
|
|
Loading…
Reference in New Issue