2019-12-28 12:16:32 +01:00
|
|
|
local core = require "core"
|
|
|
|
local common = require "core.common"
|
2020-05-12 15:44:29 +02:00
|
|
|
local command = require "core.command"
|
2019-12-28 12:16:32 +01:00
|
|
|
local config = require "core.config"
|
|
|
|
local style = require "core.style"
|
|
|
|
local DocView = require "core.docview"
|
2020-05-12 15:44:29 +02:00
|
|
|
local LogView = require "core.logview"
|
2019-12-28 12:16:32 +01:00
|
|
|
local View = require "core.view"
|
|
|
|
|
|
|
|
|
|
|
|
local StatusView = View:extend()
|
|
|
|
|
2020-05-03 23:44:49 +02:00
|
|
|
StatusView.separator = " "
|
|
|
|
StatusView.separator2 = " | "
|
2019-12-28 12:16:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
function StatusView:new()
|
|
|
|
StatusView.super.new(self)
|
|
|
|
self.message_timeout = 0
|
|
|
|
self.message = {}
|
2021-02-21 11:09:51 +01:00
|
|
|
self.tooltip_mode = false
|
|
|
|
self.tooltip = {}
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-05-12 15:44:29 +02:00
|
|
|
function StatusView:on_mouse_pressed()
|
2020-05-19 13:58:41 +02:00
|
|
|
core.set_active_view(core.last_active_view)
|
2020-05-12 15:44:29 +02:00
|
|
|
if system.get_time() < self.message_timeout
|
|
|
|
and not core.active_view:is(LogView) then
|
|
|
|
command.perform "core:open-log"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function StatusView:show_message(icon, icon_color, text)
|
|
|
|
self.message = {
|
|
|
|
icon_color, style.icon_font, icon,
|
2020-05-03 23:44:49 +02:00
|
|
|
style.dim, style.font, StatusView.separator2, style.text, text
|
2019-12-28 12:16:32 +01:00
|
|
|
}
|
|
|
|
self.message_timeout = system.get_time() + config.message_timeout
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-02-19 11:50:20 +01:00
|
|
|
function StatusView:show_tooltip(text)
|
2021-02-21 11:09:51 +01:00
|
|
|
self.tooltip = { text }
|
|
|
|
self.tooltip_mode = true
|
2021-02-19 11:50:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function StatusView:remove_tooltip()
|
2021-02-21 11:09:51 +01:00
|
|
|
self.tooltip_mode = false
|
2021-02-19 11:50:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function StatusView:update()
|
|
|
|
self.size.y = style.font:get_height() + style.padding.y * 2
|
|
|
|
|
|
|
|
if system.get_time() < self.message_timeout then
|
|
|
|
self.scroll.to.y = self.size.y
|
|
|
|
else
|
|
|
|
self.scroll.to.y = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
StatusView.super.update(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-05-03 19:42:52 +02:00
|
|
|
local function draw_items(self, items, x, y, draw_fn)
|
2019-12-28 12:16:32 +01:00
|
|
|
local font = style.font
|
|
|
|
local color = style.text
|
|
|
|
|
2020-05-03 19:42:52 +02:00
|
|
|
for _, item in ipairs(items) do
|
2019-12-28 12:16:32 +01:00
|
|
|
if type(item) == "userdata" then
|
|
|
|
font = item
|
|
|
|
elseif type(item) == "table" then
|
|
|
|
color = item
|
|
|
|
else
|
2020-05-03 19:42:52 +02:00
|
|
|
x = draw_fn(font, color, item, nil, x, y, 0, self.size.y)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
2020-05-03 19:42:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return x
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function text_width(font, _, text, _, x)
|
|
|
|
return x + font:get_width(text)
|
|
|
|
end
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
|
2020-05-03 19:42:52 +02:00
|
|
|
function StatusView:draw_items(items, right_align, yoffset)
|
|
|
|
local x, y = self:get_content_offset()
|
|
|
|
y = y + (yoffset or 0)
|
|
|
|
if right_align then
|
|
|
|
local w = draw_items(self, items, 0, 0, text_width)
|
|
|
|
x = x + self.size.x - w - style.padding.x
|
|
|
|
draw_items(self, items, x, y, common.draw_text)
|
|
|
|
else
|
|
|
|
x = x + style.padding.x
|
|
|
|
draw_items(self, items, x, y, common.draw_text)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-05-03 19:47:55 +02:00
|
|
|
function StatusView:get_items()
|
|
|
|
if getmetatable(core.active_view) == DocView then
|
|
|
|
local dv = core.active_view
|
|
|
|
local line, col = dv.doc:get_selection()
|
|
|
|
local dirty = dv.doc:is_dirty()
|
2021-02-20 22:56:52 +01:00
|
|
|
local indent = dv.doc.indent_info
|
|
|
|
local indent_label = indent.type == "hard" and "tabs: " or "spaces: "
|
|
|
|
local indent_size = tostring(indent.size) .. (indent.confirmed and "" or "*")
|
2020-05-03 19:47:55 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
dirty and style.accent or style.text, style.icon_font, "f",
|
2020-05-03 23:44:49 +02:00
|
|
|
style.dim, style.font, self.separator2, style.text,
|
2020-05-03 19:47:55 +02:00
|
|
|
dv.doc.filename and style.text or style.dim, dv.doc:get_name(),
|
|
|
|
style.text,
|
2020-05-03 23:44:49 +02:00
|
|
|
self.separator,
|
2020-05-03 19:47:55 +02:00
|
|
|
"line: ", line,
|
2020-05-03 23:44:49 +02:00
|
|
|
self.separator,
|
2020-05-03 19:47:55 +02:00
|
|
|
col > config.line_limit and style.accent or style.text, "col: ", col,
|
|
|
|
style.text,
|
2020-05-03 23:44:49 +02:00
|
|
|
self.separator,
|
2020-05-03 19:47:55 +02:00
|
|
|
string.format("%d%%", line / #dv.doc.lines * 100),
|
|
|
|
}, {
|
2021-02-20 22:56:52 +01:00
|
|
|
style.text, indent_label, indent_size,
|
2021-02-19 11:51:49 +01:00
|
|
|
style.dim, self.separator2, style.text,
|
2020-05-03 19:47:55 +02:00
|
|
|
style.icon_font, "g",
|
2020-05-03 23:44:49 +02:00
|
|
|
style.font, style.dim, self.separator2, style.text,
|
2020-05-03 19:47:55 +02:00
|
|
|
#dv.doc.lines, " lines",
|
2020-05-03 23:44:49 +02:00
|
|
|
self.separator,
|
2020-05-03 19:47:55 +02:00
|
|
|
dv.doc.crlf and "CRLF" or "LF"
|
|
|
|
}
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
|
2020-05-03 19:47:55 +02:00
|
|
|
return {}, {
|
2020-05-03 19:42:52 +02:00
|
|
|
style.icon_font, "g",
|
2020-05-03 23:44:49 +02:00
|
|
|
style.font, style.dim, self.separator2,
|
2020-05-03 19:47:55 +02:00
|
|
|
#core.docs, style.text, " / ",
|
2020-12-28 10:26:27 +01:00
|
|
|
#core.project_files, " files"
|
2020-05-03 19:47:55 +02:00
|
|
|
}
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function StatusView:draw()
|
|
|
|
self:draw_background(style.background2)
|
|
|
|
|
|
|
|
if self.message then
|
|
|
|
self:draw_items(self.message, false, self.size.y)
|
|
|
|
end
|
|
|
|
|
2021-02-21 11:09:51 +01:00
|
|
|
if self.tooltip_mode then
|
|
|
|
self:draw_items(self.tooltip)
|
|
|
|
else
|
|
|
|
local left, right = self:get_items()
|
|
|
|
self:draw_items(left)
|
|
|
|
self:draw_items(right, true)
|
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return StatusView
|