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
|
||||
|
||||
|
||||
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)
|
||||
local fp = assert( io.open(filename, "rb") )
|
||||
filename = common.normalize_path(filename)
|
||||
self:reset()
|
||||
self.filename = filename
|
||||
self:set_filename(filename)
|
||||
self.lines = {}
|
||||
for line in fp:lines() do
|
||||
if line:byte(-1) == 13 then
|
||||
|
@ -94,7 +100,9 @@ function Doc:save(filename)
|
|||
fp:write(line)
|
||||
end
|
||||
fp:close()
|
||||
self.filename = common.normalize_path(filename or self.filename)
|
||||
if filename then
|
||||
self:set_filename(filename)
|
||||
end
|
||||
self:reset_syntax()
|
||||
self:clean()
|
||||
end
|
||||
|
|
|
@ -90,6 +90,12 @@ function DocView:get_name()
|
|||
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()
|
||||
return self:get_line_height() * (#self.doc.lines - 1) + self.size.y
|
||||
end
|
||||
|
|
|
@ -719,6 +719,17 @@ function core.on_event(type, ...)
|
|||
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()
|
||||
-- handle events
|
||||
local did_keymap = false
|
||||
|
@ -761,11 +772,10 @@ function core.step()
|
|||
end
|
||||
|
||||
-- update window title
|
||||
local name = core.active_view:get_name()
|
||||
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
|
||||
local current_title = get_title_filename(core.active_view)
|
||||
if current_title ~= core.window_title then
|
||||
system.set_window_title(compose_window_title(current_title))
|
||||
core.window_title = current_title
|
||||
end
|
||||
|
||||
-- draw
|
||||
|
|
Loading…
Reference in New Issue