diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index 42c8204c5..1d0bd1c13 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -1,3 +1,7 @@ +--[[-- + Dispatcher module +--]]-- + local CreOptions = require("ui/data/creoptions") local Device = require("device") local Event = require("ui/event") @@ -73,12 +77,6 @@ local settingsList = { toggle_flash_on_chapter_boundaries = { category="none", event="ToggleFlashOnChapterBoundaries", title=_("Toggle flashing on chapter boundaries"), device=true, condition=Device:hasEinkScreen(),}, set_no_flash_on_second_chapter_page = { category="string", event="SetNoFlashOnSecondChapterPage", title=_("Never flash on chapter's 2nd page"), device=true, condition=Device:hasEinkScreen(), args={true, false}, toggle={_("On"), _("Off")},}, toggle_no_flash_on_second_chapter_page = { category="none", event="ToggleNoFlashOnSecondChapterPage", title=_("Toggle flashing on chapter's 2nd page"), device=true, condition=Device:hasEinkScreen(), separator=true,}, - wallabag_download = { category="none", event="SynchronizeWallabag", title=_("Wallabag retrieval"), device=true,}, - calibre_search = { category="none", event="CalibreSearch", title=_("Search in calibre metadata"), device=true,}, - calibre_browse_tags = { category="none", event="CalibreBrowseTags", title=_("Browse all calibre tags"), device=true,}, - calibre_browse_series = { category="none", event="CalibreBrowseSeries", title=_("Browse all calibre series"), device=true, separator=true,}, - show_terminal = { category = "none", event = "TerminalStart", title = _("Show terminal"), device = true, }, - edit_last_edited_file = { category = "none", event = "OpenLastEditedFile", title = _("Texteditor: open last file"), device = true, separator = true, }, favorites = { category="none", event="ShowColl", arg="favorites", title=_("Favorites"), device=true,}, -- filemanager settings @@ -113,8 +111,6 @@ local settingsList = { toggle_inverse_reading_order = { category="none", event="ToggleReadingOrder", title=_("Toggle page turn direction"), rolling=true, paging=true,}, cycle_highlight_action = { category="none", event="CycleHighlightAction", title=_("Cycle highlight action"), rolling=true, paging=true,}, cycle_highlight_style = { category="none", event="CycleHighlightStyle", title=_("Cycle highlight style"), rolling=true, paging=true,}, - kosync_push_progress = { category="none", event="KOSyncPushProgress", title=_("Push progress from this device"), rolling=true, paging=true,}, - kosync_pull_progress = { category="none", event="KOSyncPullProgress", title=_("Pull progress from other devices"), rolling=true, paging=true, separator=true,}, page_jmp = { category="absolutenumber", event="GotoViewRel", min=-100, max=100, title=_("Go %1 pages"), rolling=true, paging=true,}, panel_zoom_toggle = { category="none", event="TogglePanelZoomSetting", title=_("Toggle panel zoom"), paging=true, separator=true,}, @@ -205,14 +201,6 @@ local dispatcher_menu_order = { "wifi_off", "toggle_wifi", - "wallabag_download", - "calibre_search", - "calibre_browse_tags", - "calibre_browse_series", - - "show_terminal", - "edit_last_edited_file", - "rotation_mode", -- filemanager @@ -263,9 +251,6 @@ local dispatcher_menu_order = { "cycle_highlight_style", "panel_zoom_toggle", - "kosync_push_progress", - "kosync_pull_progress", - "visible_pages", "h_page_margins", @@ -332,11 +317,29 @@ function Dispatcher:init() for i=1,#CreOptions do parseoptions(CreOptions, i) end + UIManager:broadcastEvent(Event:new("DispatcherRegisterActions")) Dispatcher.initialized = true end +--[[-- + add settings at runtime + @param name: the key to use in the table + @param value: a table per settingsList above. + see helloworld plugin for an example. +--]]-- +function Dispatcher:registerAction(name, value) + if settingsList[name] == nil then + settingsList[name] = value + table.insert(dispatcher_menu_order, name) + end + return true +end + -- Returns a display name for the item. function Dispatcher:getNameFromItem(item, location, settings) + if settingsList[item] == nil then + return _("Unknown item") + end local amount if location[settings] ~= nil and location[settings][item] ~= nil then amount = location[settings][item] @@ -542,7 +545,7 @@ function Dispatcher:addSubMenu(caller, menu, location, settings) checked_func = function() if location[settings] ~= nil then for k, _ in pairs(location[settings]) do - if settingsList[k][section[1]] == true and + if settingsList[k] ~= nil and settingsList[k][section[1]] == true and (settingsList[k].condition == nil or settingsList[k].condition) then return true end end @@ -551,7 +554,7 @@ function Dispatcher:addSubMenu(caller, menu, location, settings) hold_callback = function(touchmenu_instance) if location[settings] ~= nil then for k, _ in pairs(location[settings]) do - if settingsList[k][section[1]] == true then + if settingsList[k] ~= nil and settingsList[k][section[1]] == true then location[settings][k] = nil caller.updated = true end @@ -573,7 +576,7 @@ arguments are: --]]-- function Dispatcher:execute(ui, settings, gesture) for k, v in pairs(settings) do - if settingsList[k].conditions == nil or settingsList[k].conditions == true then + if settingsList[k] ~= nil and (settingsList[k].conditions == nil or settingsList[k].conditions == true) then if settingsList[k].category == "none" then if settingsList[k].arg ~= nil then ui:handleEvent(Event:new(settingsList[k].event, settingsList[k].arg)) diff --git a/plugins/calibre.koplugin/main.lua b/plugins/calibre.koplugin/main.lua index 35e41451b..01199332a 100644 --- a/plugins/calibre.koplugin/main.lua +++ b/plugins/calibre.koplugin/main.lua @@ -10,6 +10,7 @@ local BD = require("ui/bidi") local CalibreSearch = require("search") local CalibreWireless = require("wireless") +local Dispatcher = require("dispatcher") local InfoMessage = require("ui/widget/infomessage") local LuaSettings = require("luasettings") local UIManager = require("ui/uimanager") @@ -57,8 +58,15 @@ function Calibre:closeWirelessConnection() end end +function Calibre:onDispatcherRegisterActions() + Dispatcher:registerAction("calibre_search", { category="none", event="CalibreSearch", title=_("Search in calibre metadata"), device=true,}) + Dispatcher:registerAction("calibre_browse_tags", { category="none", event="CalibreBrowseTags", title=_("Browse all calibre tags"), device=true,}) + Dispatcher:registerAction("calibre_browse_series", { category="none", event="CalibreBrowseSeries", title=_("Browse all calibre series"), device=true, separator=true,}) +end + function Calibre:init() CalibreWireless:init() + self:onDispatcherRegisterActions() self.ui.menu:registerToMainMenu(self) end diff --git a/plugins/hello.koplugin/main.lua b/plugins/hello.koplugin/main.lua index 9f8699dac..a8d820891 100644 --- a/plugins/hello.koplugin/main.lua +++ b/plugins/hello.koplugin/main.lua @@ -3,7 +3,8 @@ if true then return { disabled = true, } end -local InfoMessage = require("ui/widget/infomessage") -- luacheck:ignore +local Dispatcher = require("dispatcher") -- luacheck:ignore +local InfoMessage = require("ui/widget/infomessage") local UIManager = require("ui/uimanager") local WidgetContainer = require("ui/widget/container/widgetcontainer") local _ = require("gettext") @@ -13,7 +14,12 @@ local Hello = WidgetContainer:new{ is_doc_only = false, } +function Hello:onDispatcherRegisterActions() + Dispatcher:registerAction("helloworld_action", {category="none", event="HelloWorld", title=_("Hello World"), filemanager=true,}) +end + function Hello:init() + self:onDispatcherRegisterActions() self.ui.menu:registerToMainMenu(self) end @@ -21,7 +27,7 @@ function Hello:addToMainMenu(menu_items) menu_items.hello_world = { text = _("Hello World"), -- in which menu this should be appended - sorting_hint = "more_plugins", + sorting_hint = "more_tools", -- a callback when tapping callback = function() UIManager:show(InfoMessage:new{ @@ -31,4 +37,11 @@ function Hello:addToMainMenu(menu_items) } end +function Hello:onHelloWorld() + local popup = InfoMessage:new{ + text = _("Hello World"), + } + UIManager:show(popup) +end + return Hello diff --git a/plugins/kosync.koplugin/main.lua b/plugins/kosync.koplugin/main.lua index 88408f392..74a90ffa7 100644 --- a/plugins/kosync.koplugin/main.lua +++ b/plugins/kosync.koplugin/main.lua @@ -1,3 +1,4 @@ +local Dispatcher = require("dispatcher") local InputContainer = require("ui/widget/container/inputcontainer") local LoginDialog = require("ui/widget/logindialog") local InfoMessage = require("ui/widget/infomessage") @@ -97,6 +98,11 @@ local function validateUser(user, pass) end end +function KOSync:onDispatcherRegisterActions() + Dispatcher:registerAction("kosync_push_progress", { category="none", event="KOSyncPushProgress", title=_("Push progress from this device"), rolling=true, paging=true,}) + Dispatcher:registerAction("kosync_pull_progress", { category="none", event="KOSyncPullProgress", title=_("Pull progress from other devices"), rolling=true, paging=true, separator=true,}) +end + function KOSync:onReaderReady() local settings = G_reader_settings:readSetting("kosync") or {} self.kosync_custom_server = settings.custom_server @@ -112,6 +118,7 @@ function KOSync:onReaderReady() self:_onResume() end self:registerEvents() + self:onDispatcherRegisterActions() self.ui.menu:registerToMainMenu(self) -- Make sure checksum has been calculated at the very first time a document has been opened, to -- avoid document saving feature to impact the checksum, and eventually impact the document diff --git a/plugins/terminal.koplugin/main.lua b/plugins/terminal.koplugin/main.lua index d5cecf4b8..fd8965775 100644 --- a/plugins/terminal.koplugin/main.lua +++ b/plugins/terminal.koplugin/main.lua @@ -1,6 +1,7 @@ local ButtonDialog = require("ui/widget/buttondialog") local CenterContainer = require("ui/widget/container/centercontainer") local DataStorage = require("datastorage") +local Dispatcher = require("dispatcher") local Font = require("ui/font") local InfoMessage = require("ui/widget/infomessage") local InputDialog = require("ui/widget/inputdialog") @@ -30,7 +31,12 @@ local Terminal = WidgetContainer:new{ source = "terminal", } +function Terminal:onDispatcherRegisterActions() + Dispatcher:registerAction("show_terminal", { category = "none", event = "TerminalStart", title = _("Show terminal"), device = true, }) +end + function Terminal:init() + self:onDispatcherRegisterActions() self.ui.menu:registerToMainMenu(self) self.shortcuts = self.settings:readSetting("shortcuts") or {} end diff --git a/plugins/texteditor.koplugin/main.lua b/plugins/texteditor.koplugin/main.lua index 95f272850..71316b4c7 100644 --- a/plugins/texteditor.koplugin/main.lua +++ b/plugins/texteditor.koplugin/main.lua @@ -1,6 +1,7 @@ local BD = require("ui/bidi") local ConfirmBox = require("ui/widget/confirmbox") local DataStorage = require("datastorage") +local Dispatcher = require("dispatcher") local Font = require("ui/font") local InfoMessage = require("ui/widget/infomessage") local InputDialog = require("ui/widget/inputdialog") @@ -29,7 +30,12 @@ local TextEditor = WidgetContainer:new{ min_file_size_warn = 200000, -- warn/ask when opening files bigger than this } +function TextEditor:onDispatcherRegisterActions() + Dispatcher:registerAction("edit_last_edited_file", { category = "none", event = "OpenLastEditedFile", title = _("Texteditor: open last file"), device = true, separator = true, }) +end + function TextEditor:init() + self:onDispatcherRegisterActions() self.ui.menu:registerToMainMenu(self) end diff --git a/plugins/wallabag.koplugin/main.lua b/plugins/wallabag.koplugin/main.lua index fe23c3244..c434bad4e 100644 --- a/plugins/wallabag.koplugin/main.lua +++ b/plugins/wallabag.koplugin/main.lua @@ -4,6 +4,7 @@ local BD = require("ui/bidi") local DataStorage = require("datastorage") +local Dispatcher = require("dispatcher") local DocSettings = require("docsettings") local Event = require("ui/event") local FFIUtil = require("ffi/util") @@ -38,6 +39,10 @@ local Wallabag = WidgetContainer:new{ name = "wallabag", } +function Wallabag:onDispatcherRegisterActions() + Dispatcher:registerAction("wallabag_download", { category="none", event="SynchronizeWallabag", title=_("Wallabag retrieval"), device=true,}) +end + function Wallabag:init() self.token_expiry = 0 -- default values so that user doesn't have to explicitely set them @@ -50,6 +55,7 @@ function Wallabag:init() self.ignore_tags = "" self.articles_per_sync = 30 + self:onDispatcherRegisterActions() self.ui.menu:registerToMainMenu(self) self.wb_settings = self.readSettings() self.server_url = self.wb_settings.data.wallabag.server_url