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-10-14 14:39:59 +03:00
|
|
|
local text
|
2024-07-12 13:32:01 +03:00
|
|
|
if self._folder.files.filter then
|
2024-10-14 14:39:59 +03:00
|
|
|
text = ui.Text("No filter results")
|
2024-04-12 05:09:29 +03:00
|
|
|
else
|
2024-10-14 14:39:59 +03:00
|
|
|
text = ui.Text(self._folder.stage.is_loading and "Loading..." or "No items")
|
2024-04-12 05:09:29 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2024-10-14 14:39:59 +03:00
|
|
|
text:area(self._area):align(ui.Text.CENTER),
|
2024-04-12 05:09:29 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-10-30 14:06:06 +03:00
|
|
|
function Current:reflow() return { self } end
|
|
|
|
|
|
|
|
function Current:redraw()
|
2024-07-12 13:32:01 +03:00
|
|
|
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-10-30 14:06:06 +03:00
|
|
|
entities[#entities + 1] = Entity:new(f):redraw()
|
|
|
|
linemodes[#linemodes + 1] = Linemode:new(f):redraw()
|
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-10-13 20:54:03 +03:00
|
|
|
ui.List(entities):area(self._area),
|
|
|
|
ui.Text(linemodes):area(self._area):align(ui.Text.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
|