2023-12-26 14:48:33 +03:00
|
|
|
Current = {
|
2024-07-12 13:32:01 +03:00
|
|
|
_id = "current",
|
2023-12-26 14:48:33 +03:00
|
|
|
}
|
|
|
|
|
2024-07-12 13:32:01 +03:00
|
|
|
function Current:new(area, tab)
|
|
|
|
return setmetatable({
|
|
|
|
_area = area,
|
|
|
|
_tab = tab,
|
|
|
|
_folder = tab.current,
|
|
|
|
}, { __index = self })
|
|
|
|
end
|
2024-04-12 05:09:29 +03:00
|
|
|
|
2024-07-12 13:32:01 +03:00
|
|
|
function Current:empty()
|
2024-04-12 05:09:29 +03:00
|
|
|
local line
|
2024-07-12 13:32:01 +03:00
|
|
|
if self._folder.files.filter then
|
2024-04-12 05:09:29 +03:00
|
|
|
line = ui.Line("No filter results")
|
|
|
|
else
|
2024-08-09 06:38:47 +03:00
|
|
|
line = ui.Line(self._folder.stage.is_loading and "Loading..." or "No items")
|
2024-04-12 05:09:29 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2024-07-12 13:32:01 +03:00
|
|
|
ui.Paragraph(self._area, { line }):align(ui.Paragraph.CENTER),
|
2024-04-12 05:09:29 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-07-12 13:32:01 +03:00
|
|
|
function Current:render()
|
|
|
|
local files = self._folder.window
|
2024-02-15 15:20:28 +03:00
|
|
|
if #files == 0 then
|
2024-07-12 13:32:01 +03:00
|
|
|
return self:empty()
|
2024-02-15 15:20:28 +03:00
|
|
|
end
|
|
|
|
|
2024-07-15 09:59:24 +03:00
|
|
|
local entities, linemodes = {}, {}
|
2024-07-12 13:32:01 +03:00
|
|
|
for _, f in ipairs(files) do
|
2024-07-15 09:59:24 +03:00
|
|
|
linemodes[#linemodes + 1] = Linemode:new(f):render()
|
|
|
|
|
|
|
|
local entity = Entity:new(f)
|
|
|
|
entities[#entities + 1] = ui.ListItem(entity:render()):style(entity:style())
|
2023-12-26 14:48:33 +03:00
|
|
|
end
|
2024-02-15 15:20:28 +03:00
|
|
|
|
2024-07-12 13:32:01 +03:00
|
|
|
return {
|
2024-07-15 09:59:24 +03:00
|
|
|
ui.List(self._area, entities),
|
|
|
|
ui.Paragraph(self._area, linemodes):align(ui.Paragraph.RIGHT),
|
2024-02-15 15:20:28 +03:00
|
|
|
}
|
2023-12-26 14:48:33 +03:00
|
|
|
end
|
2024-06-03 09:31:55 +03:00
|
|
|
|
2024-07-12 13:32:01 +03:00
|
|
|
-- Mouse events
|
2024-06-03 09:31:55 +03:00
|
|
|
function Current:click(event, up)
|
2024-06-29 06:25:45 +03:00
|
|
|
if up or event.is_middle then
|
2024-06-03 09:31:55 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-07-12 13:32:01 +03:00
|
|
|
local f = self._folder
|
|
|
|
local y = event.y - self._area.y + 1
|
|
|
|
if y > #f.window or not f.hovered then
|
2024-06-29 06:25:45 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-07-12 13:32:01 +03:00
|
|
|
ya.manager_emit("arrow", { y + f.offset - f.hovered.idx })
|
2024-06-29 06:25:45 +03:00
|
|
|
if event.is_right then
|
2024-07-01 18:58:03 +03:00
|
|
|
ya.manager_emit("open", {})
|
2024-06-03 09:31:55 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Current:scroll(event, step) ya.manager_emit("arrow", { step }) end
|
|
|
|
|
|
|
|
function Current:touch(event, step) end
|