diff --git a/main.lua b/main.lua index 9241a0a..f1f4d6e 100644 --- a/main.lua +++ b/main.lua @@ -489,34 +489,56 @@ function IrcChatView:onClose() end -- Extend the hamburger menu to add a list of joined channels/targets. +function IrcChatView:showChannelSwitcher() + local Menu = require("ui/widget/menu") + local items = {} + local targets = self._ordered_targets or {} + for _, tgt in ipairs(targets) do + local label = (tgt == "*" and _("Server console")) or tgt + table.insert(items, { + text_func = function() + local n = self._unread[tgt] or 0 + if n > 0 then + return string.format("%s (%d)", label, n) + else + return label + end + end, + checked_func = function() return self._current_target == tgt end, + callback = function(item) + self:switchTarget(tgt) + UIManager:close(self._switcher_menu) + end, + }) + end + self._switcher_menu = Menu:new{ + title = _("Switch channel"), + item_table = items, + covers_fullscreen = true, + is_borderless = true, + is_popout = false, + close_callback = function() + UIManager:close(self._switcher_menu) + self._switcher_menu = nil + end, + } + UIManager:show(self._switcher_menu) +end + function IrcChatView:onShowMenu() local ButtonDialog = require("ui/widget/buttondialog") local SpinWidget = require("ui/widget/spinwidget") local buttons = {} - -- Channels/Targets section - if self._ordered_targets and #self._ordered_targets > 0 then - for _, tgt in ipairs(self._ordered_targets) do - table.insert(buttons, { - { - text_func = function() - local n = self._unread[tgt] or 0 - if n > 0 then - return string.format("%s (%d)", tgt, n) - else - return tgt - end - end, - checked_func = function() return self._current_target == tgt end, - callback = function() - self:switchTarget(tgt) - end, - }, - }) - end - -- separator row - table.insert(buttons, { { text = "—", enabled = false, callback = function() end } }) - end + table.insert(buttons, { + { + text = _("Switch channel"), + enabled_func = function() return self._ordered_targets and #self._ordered_targets > 0 end, + callback = function() + self:showChannelSwitcher() + end, + } + }) -- Font size table.insert(buttons, {