2020-10-12 03:06:04 +00:00
--[[--
2020-10-12 15:20:16 +00:00
This module is responsible for dispatching events .
To add a new action an entry must be added to ` settingsList ` & ` dispatcher_menu_order `
This can also be done at runtime via @ { registerAction } ( ) .
` settingsList ` contains the list of dispatchable settings .
Each setting contains :
* category : one of :
* none : a direct event call
* arg : a event that expects a gesture object or an argument
* absolutenumber : event that sets a number
* incrementalnumber : event that increments a number & accepts a gesture object
* string : event with a list of arguments to chose from
2021-05-14 22:13:27 +00:00
* configurable : like string but instead of an event it updates the configurable ( used by kopt )
2020-10-12 15:20:16 +00:00
* event : what to call .
* title : for use in ui .
2021-09-10 20:11:24 +00:00
* section : under which menu to display ( currently : general , device , screen , filemanager , reader , rolling , paging )
2020-10-12 15:20:16 +00:00
and optionally
* min / max : for number
2021-05-05 18:48:42 +00:00
* step : for number
2020-10-12 15:20:16 +00:00
* default
* args : allowed values for string .
* toggle : display name for args
* separator : put a separator after in the menu list
2021-05-13 15:57:48 +00:00
* configurable : can be parsed from cre / kopt and used to set ` document.configurable ` . Should not be set manually
2020-10-12 03:06:04 +00:00
--]]--
2020-06-19 21:38:53 +00:00
local CreOptions = require ( " ui/data/creoptions " )
2021-05-14 22:13:27 +00:00
local KoptOptions = require ( " ui/data/koptoptions " )
2020-07-14 21:39:03 +00:00
local Device = require ( " device " )
2020-06-19 21:38:53 +00:00
local Event = require ( " ui/event " )
2024-06-01 07:33:14 +00:00
local FileManager = require ( " apps/filemanager/filemanager " )
2021-05-20 21:14:11 +00:00
local Notification = require ( " ui/widget/notification " )
2022-11-02 17:58:12 +00:00
local ReaderHighlight = require ( " apps/reader/modules/readerhighlight " )
2020-11-28 16:18:57 +00:00
local ReaderZooming = require ( " apps/reader/modules/readerzooming " )
2023-07-08 05:17:42 +00:00
local Screen = Device.screen
2020-06-19 21:38:53 +00:00
local UIManager = require ( " ui/uimanager " )
2021-09-10 20:14:07 +00:00
local util = require ( " util " )
2020-06-19 21:38:53 +00:00
local _ = require ( " gettext " )
2022-11-01 19:59:19 +00:00
local NC_ = _.npgettext
2020-08-17 07:55:03 +00:00
local T = require ( " ffi/util " ) . template
2020-06-19 21:38:53 +00:00
local Dispatcher = {
initialized = false ,
}
2020-10-12 15:20:16 +00:00
-- See above for description.
2020-06-19 21:38:53 +00:00
local settingsList = {
2023-05-04 23:27:52 +00:00
-- General
reading_progress = { category = " none " , event = " ShowReaderProgress " , title = _ ( " Reading progress " ) , general = true } ,
open_previous_document = { category = " none " , event = " OpenLastDoc " , title = _ ( " Open previous document " ) , general = true } ,
history = { category = " none " , event = " ShowHist " , title = _ ( " History " ) , general = true } ,
2023-11-09 05:34:56 +00:00
history_search = { category = " none " , event = " SearchHistory " , title = _ ( " History search " ) , general = true } ,
2024-05-01 06:01:59 +00:00
favorites = { category = " none " , event = " ShowColl " , title = _ ( " Favorites " ) , general = true } ,
collections = { category = " none " , event = " ShowCollList " , title = _ ( " Collections " ) , general = true } ,
2023-05-04 23:27:52 +00:00
filemanager = { category = " none " , event = " Home " , title = _ ( " File browser " ) , general = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-04 23:27:52 +00:00
dictionary_lookup = { category = " none " , event = " ShowDictionaryLookup " , title = _ ( " Dictionary lookup " ) , general = true } ,
2023-10-12 05:58:52 +00:00
wikipedia_lookup = { category = " none " , event = " ShowWikipediaLookup " , title = _ ( " Wikipedia lookup " ) , general = true , separator = true } ,
----
2023-05-04 23:27:52 +00:00
show_menu = { category = " none " , event = " ShowMenu " , title = _ ( " Show menu " ) , general = true } ,
menu_search = { category = " none " , event = " MenuSearch " , title = _ ( " Menu search " ) , general = true } ,
screenshot = { category = " none " , event = " Screenshot " , title = _ ( " Screenshot " ) , general = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-04 23:27:52 +00:00
2023-10-12 05:58:52 +00:00
-- Device
2024-04-08 20:47:17 +00:00
exit_screensaver = { category = " none " , event = " ExitScreensaver " , title = _ ( " Exit sleep screen " ) , device = true } ,
2023-11-22 17:59:07 +00:00
start_usbms = { category = " none " , event = " RequestUSBMS " , title = _ ( " Start USB storage " ) , device = true , condition = Device : canToggleMassStorage ( ) } ,
2023-05-04 23:27:52 +00:00
suspend = { category = " none " , event = " RequestSuspend " , title = _ ( " Suspend " ) , device = true , condition = Device : canSuspend ( ) } ,
restart = { category = " none " , event = " Restart " , title = _ ( " Restart KOReader " ) , device = true , condition = Device : canRestart ( ) } ,
reboot = { category = " none " , event = " RequestReboot " , title = _ ( " Reboot the device " ) , device = true , condition = Device : canReboot ( ) } ,
2023-10-12 05:58:52 +00:00
poweroff = { category = " none " , event = " RequestPowerOff " , title = _ ( " Power off " ) , device = true , condition = Device : canPowerOff ( ) } ,
exit = { category = " none " , event = " Exit " , title = _ ( " Exit KOReader " ) , device = true , separator = true } ,
----
2023-05-04 23:27:52 +00:00
toggle_hold_corners = { category = " none " , event = " IgnoreHoldCorners " , title = _ ( " Toggle hold corners " ) , device = true } ,
2023-07-03 04:58:51 +00:00
touch_input_on = { category = " none " , event = " IgnoreTouchInput " , arg = false , title = _ ( " Enable touch input " ) , device = true } ,
touch_input_off = { category = " none " , event = " IgnoreTouchInput " , arg = true , title = _ ( " Disable touch input " ) , device = true } ,
2023-05-04 23:27:52 +00:00
toggle_touch_input = { category = " none " , event = " IgnoreTouchInput " , title = _ ( " Toggle touch input " ) , device = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-08-11 22:34:29 +00:00
swap_page_turn_buttons = { category = " none " , event = " SwapPageTurnButtons " , title = _ ( " Invert page turn buttons " ) , device = true , condition = Device : hasKeys ( ) , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-08-11 22:34:29 +00:00
toggle_key_repeat = { category = " none " , event = " ToggleKeyRepeat " , title = _ ( " Toggle key repeat " ) , device = true , condition = Device : hasKeys ( ) and Device : canKeyRepeat ( ) , separator = true } ,
2023-05-04 23:27:52 +00:00
toggle_gsensor = { category = " none " , event = " ToggleGSensor " , title = _ ( " Toggle accelerometer " ) , device = true , condition = Device : hasGSensor ( ) } ,
2024-05-11 09:47:33 +00:00
lock_gsensor = { category = " none " , event = " LockGSensor " , title = _ ( " Lock auto rotation to current orientation " ) , device = true , condition = Device : hasGSensor ( ) } ,
2023-05-04 23:27:52 +00:00
toggle_rotation = { category = " none " , event = " SwapRotation " , title = _ ( " Toggle orientation " ) , device = true } ,
invert_rotation = { category = " none " , event = " InvertRotation " , title = _ ( " Invert rotation " ) , device = true } ,
iterate_rotation = { category = " none " , event = " IterateRotation " , title = _ ( " Rotate by 90° CW " ) , device = true } ,
iterate_rotation_ccw = { category = " none " , event = " IterateRotation " , arg = true , title = _ ( " Rotate by 90° CCW " ) , device = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-04 23:27:52 +00:00
wifi_on = { category = " none " , event = " InfoWifiOn " , title = _ ( " Turn on Wi-Fi " ) , device = true , condition = Device : hasWifiToggle ( ) } ,
wifi_off = { category = " none " , event = " InfoWifiOff " , title = _ ( " Turn off Wi-Fi " ) , device = true , condition = Device : hasWifiToggle ( ) } ,
toggle_wifi = { category = " none " , event = " ToggleWifi " , title = _ ( " Toggle Wi-Fi " ) , device = true , condition = Device : hasWifiToggle ( ) } ,
toggle_fullscreen = { category = " none " , event = " ToggleFullscreen " , title = _ ( " Toggle Fullscreen " ) , device = true , condition = not Device : isAlwaysFullscreen ( ) } ,
show_network_info = { category = " none " , event = " ShowNetworkInfo " , title = _ ( " Show network info " ) , device = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-04 23:27:52 +00:00
2023-10-12 05:58:52 +00:00
-- Screen and lights
2021-09-10 20:11:24 +00:00
show_frontlight_dialog = { category = " none " , event = " ShowFlDialog " , title = _ ( " Show frontlight dialog " ) , screen = true , condition = Device : hasFrontlight ( ) } ,
toggle_frontlight = { category = " none " , event = " ToggleFrontlight " , title = _ ( " Toggle frontlight " ) , screen = true , condition = Device : hasFrontlight ( ) } ,
2022-11-14 20:42:06 +00:00
set_frontlight = { category = " absolutenumber " , event = " SetFlIntensity " , min = 0 , max = Device : getPowerDevice ( ) . fl_max , title = _ ( " Set frontlight brightness " ) , screen = true , condition = Device : hasFrontlight ( ) } ,
2023-12-15 06:27:15 +00:00
increase_frontlight = { category = " incrementalnumber " , event = " IncreaseFlIntensity " , min = 0 , max = Device : getPowerDevice ( ) . fl_max , title = _ ( " Increase frontlight brightness " ) , screen = true , condition = Device : hasFrontlight ( ) } ,
decrease_frontlight = { category = " incrementalnumber " , event = " DecreaseFlIntensity " , min = 0 , max = Device : getPowerDevice ( ) . fl_max , title = _ ( " Decrease frontlight brightness " ) , screen = true , condition = Device : hasFrontlight ( ) } ,
2022-11-14 20:42:06 +00:00
set_frontlight_warmth = { category = " absolutenumber " , event = " SetFlWarmth " , min = 0 , max = 100 , title = _ ( " Set frontlight warmth " ) , screen = true , condition = Device : hasNaturalLight ( ) } ,
2023-12-15 06:27:15 +00:00
increase_frontlight_warmth = { category = " incrementalnumber " , event = " IncreaseFlWarmth " , min = 0 , max = Device : getPowerDevice ( ) . fl_warmth_max , title = _ ( " Increase frontlight warmth " ) , screen = true , condition = Device : hasNaturalLight ( ) } ,
decrease_frontlight_warmth = { category = " incrementalnumber " , event = " DecreaseFlWarmth " , min = 0 , max = Device : getPowerDevice ( ) . fl_warmth_max , title = _ ( " Decrease frontlight warmth " ) , screen = true , condition = Device : hasNaturalLight ( ) , separator = true } ,
2021-09-10 20:11:24 +00:00
night_mode = { category = " none " , event = " ToggleNightMode " , title = _ ( " Toggle night mode " ) , screen = true } ,
2022-11-14 20:42:06 +00:00
set_night_mode = { category = " string " , event = " SetNightMode " , title = _ ( " Set night mode " ) , screen = true , args = { true , false } , toggle = { _ ( " on " ) , _ ( " off " ) } , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-04 23:27:52 +00:00
full_refresh = { category = " none " , event = " FullRefresh " , title = _ ( " Full screen refresh " ) , screen = true } ,
2022-11-14 20:42:06 +00:00
set_refresh_rate = { category = " absolutenumber " , event = " SetBothRefreshRates " , min =- 1 , max = 200 , title = _ ( " Full refresh rate (always) " ) , screen = true , condition = Device : hasEinkScreen ( ) } ,
set_day_refresh_rate = { category = " absolutenumber " , event = " SetDayRefreshRate " , min =- 1 , max = 200 , title = _ ( " Full refresh rate (not in night mode) " ) , screen = true , condition = Device : hasEinkScreen ( ) } ,
set_night_refresh_rate = { category = " absolutenumber " , event = " SetNightRefreshRate " , min =- 1 , max = 200 , title = _ ( " Full refresh rate (in night mode) " ) , screen = true , condition = Device : hasEinkScreen ( ) } ,
set_flash_on_chapter_boundaries = { category = " string " , event = " SetFlashOnChapterBoundaries " , title = _ ( " Always flash on chapter boundaries " ) , screen = true , condition = Device : hasEinkScreen ( ) , args = { true , false } , toggle = { _ ( " on " ) , _ ( " off " ) } } ,
2021-09-10 20:11:24 +00:00
toggle_flash_on_chapter_boundaries = { category = " none " , event = " ToggleFlashOnChapterBoundaries " , title = _ ( " Toggle flashing on chapter boundaries " ) , screen = true , condition = Device : hasEinkScreen ( ) } ,
2022-11-14 20:42:06 +00:00
set_no_flash_on_second_chapter_page = { category = " string " , event = " SetNoFlashOnSecondChapterPage " , title = _ ( " Never flash on chapter's 2nd page " ) , screen = true , condition = Device : hasEinkScreen ( ) , args = { true , false } , toggle = { _ ( " on " ) , _ ( " off " ) } } ,
2023-10-12 05:58:52 +00:00
toggle_no_flash_on_second_chapter_page = { category = " none " , event = " ToggleNoFlashOnSecondChapterPage " , title = _ ( " Toggle flashing on chapter's 2nd page " ) , screen = true , condition = Device : hasEinkScreen ( ) } ,
2023-02-02 20:09:29 +00:00
set_flash_on_pages_with_images = { category = " string " , event = " SetFlashOnPagesWithImages " , title = _ ( " Always flash on pages with images " ) , screen = true , condition = Device : hasEinkScreen ( ) , args = { true , false } , toggle = { _ ( " on " ) , _ ( " off " ) } } ,
2023-10-12 05:58:52 +00:00
toggle_flash_on_pages_with_images = { category = " none " , event = " ToggleFlashOnPagesWithImages " , title = _ ( " Toggle flashing on pages with images " ) , screen = true , condition = Device : hasEinkScreen ( ) , separator = true } ,
----
2021-09-10 20:11:24 +00:00
2023-10-12 05:58:52 +00:00
-- File browser
2024-06-01 07:33:14 +00:00
set_display_mode = { category = " string " , event = " SetDisplayMode " , title = _ ( " Set display mode " ) , args_func = FileManager.getDisplayModeActions , filemanager = true } ,
set_sort_by = { category = " string " , event = " SetSortBy " , title = _ ( " Sort by " ) , args_func = FileManager.getSortByActions , filemanager = true } ,
set_reverse_sorting = { category = " string " , event = " SetReverseSorting " , title = _ ( " Reverse sorting " ) , args = { true , false } , toggle = { _ ( " on " ) , _ ( " off " ) } , filemanager = true } ,
set_mixed_sorting = { category = " string " , event = " SetMixedSorting " , title = _ ( " Folders and files mixed " ) , args = { true , false } , toggle = { _ ( " on " ) , _ ( " off " ) } , filemanager = true , separator = true } ,
----
2021-05-10 10:44:55 +00:00
folder_up = { category = " none " , event = " FolderUp " , title = _ ( " Folder up " ) , filemanager = true } ,
show_plus_menu = { category = " none " , event = " ShowPlusMenu " , title = _ ( " Show plus menu " ) , filemanager = true } ,
2021-12-16 11:12:25 +00:00
toggle_select_mode = { category = " none " , event = " ToggleSelectMode " , title = _ ( " Toggle select mode " ) , filemanager = true } ,
2021-05-10 10:44:55 +00:00
refresh_content = { category = " none " , event = " RefreshContent " , title = _ ( " Refresh content " ) , filemanager = true } ,
2023-10-12 05:58:52 +00:00
folder_shortcuts = { category = " none " , event = " ShowFolderShortcutsDialog " , title = _ ( " Folder shortcuts " ) , filemanager = true } ,
2024-06-01 07:33:14 +00:00
file_search = { category = " none " , event = " ShowFileSearch " , title = _ ( " File search " ) , filemanager = true } ,
2023-10-12 05:58:52 +00:00
----
-- go_to
-- back
2020-07-14 21:39:03 +00:00
2023-10-12 05:58:52 +00:00
-- Reader
2022-12-14 19:40:24 +00:00
open_next_document_in_folder = { category = " none " , event = " OpenNextDocumentInFolder " , title = _ ( " Open next document in folder " ) , reader = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-04 23:27:52 +00:00
show_config_menu = { category = " none " , event = " ShowConfigMenu " , title = _ ( " Show bottom menu " ) , reader = true } ,
2024-03-10 06:05:30 +00:00
toggle_status_bar = { category = " none " , event = " ToggleFooterMode " , title = _ ( " Toggle status bar " ) , reader = true } ,
toggle_chapter_progress_bar = { category = " none " , event = " ToggleChapterProgressBar " , title = _ ( " Toggle chapter progress bar " ) , reader = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2021-09-10 20:11:24 +00:00
prev_chapter = { category = " none " , event = " GotoPrevChapter " , title = _ ( " Previous chapter " ) , reader = true } ,
next_chapter = { category = " none " , event = " GotoNextChapter " , title = _ ( " Next chapter " ) , reader = true } ,
first_page = { category = " none " , event = " GoToBeginning " , title = _ ( " First page " ) , reader = true } ,
last_page = { category = " none " , event = " GoToEnd " , title = _ ( " Last page " ) , reader = true } ,
2024-04-28 15:03:58 +00:00
random_page = { category = " none " , event = " GoToRandomPage " , title = _ ( " Random page " ) , reader = true } ,
2023-05-04 23:27:52 +00:00
page_jmp = { category = " absolutenumber " , event = " GotoViewRel " , min =- 100 , max = 100 , title = _ ( " Turn pages " ) , reader = true } ,
2021-09-10 20:11:24 +00:00
go_to = { category = " none " , event = " ShowGotoDialog " , title = _ ( " Go to page " ) , filemanager = true , reader = true } ,
skim = { category = " none " , event = " ShowSkimtoDialog " , title = _ ( " Skim document " ) , reader = true } ,
2023-05-04 23:27:52 +00:00
prev_bookmark = { category = " none " , event = " GotoPreviousBookmarkFromPage " , title = _ ( " Previous bookmark " ) , reader = true } ,
next_bookmark = { category = " none " , event = " GotoNextBookmarkFromPage " , title = _ ( " Next bookmark " ) , reader = true } ,
2023-09-15 04:24:31 +00:00
first_bookmark = { category = " none " , event = " GotoFirstBookmark " , title = _ ( " First bookmark " ) , reader = true } ,
last_bookmark = { category = " none " , event = " GotoLastBookmark " , title = _ ( " Last bookmark " ) , reader = true } ,
latest_bookmark = { category = " none " , event = " GoToLatestBookmark " , title = _ ( " Latest bookmark " ) , reader = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-06-02 15:54:54 +00:00
back = { category = " none " , event = " Back " , title = _ ( " Back " ) , filemanager = true , reader = true } ,
2021-09-10 20:11:24 +00:00
previous_location = { category = " none " , event = " GoBackLink " , arg = true , title = _ ( " Back to previous location " ) , reader = true } ,
2023-03-29 16:32:44 +00:00
next_location = { category = " none " , event = " GoForwardLink " , arg = true , title = _ ( " Forward to next location " ) , reader = true } ,
2021-09-10 20:11:24 +00:00
follow_nearest_link = { category = " arg " , event = " GoToPageLink " , arg = { pos = { x = 0 , y = 0 } } , title = _ ( " Follow nearest link " ) , reader = true } ,
follow_nearest_internal_link = { category = " arg " , event = " GoToInternalPageLink " , arg = { pos = { x = 0 , y = 0 } } , title = _ ( " Follow nearest internal link " ) , reader = true } ,
2023-05-04 23:00:28 +00:00
add_location_to_history = { category = " none " , event = " AddCurrentLocationToStack " , arg = true , title = _ ( " Add current location to history " ) , reader = true } ,
2021-09-10 20:11:24 +00:00
clear_location_history = { category = " none " , event = " ClearLocationStack " , arg = true , title = _ ( " Clear location history " ) , reader = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
fulltext_search = { category = " none " , event = " ShowFulltextSearchInput " , title = _ ( " Fulltext search " ) , reader = true } ,
2024-01-20 08:00:21 +00:00
fulltext_search_findall_results = { category = " none " , event = " ShowFindAllResults " , title = _ ( " Last fulltext search results " ) , reader = true } ,
2021-09-10 20:11:24 +00:00
toc = { category = " none " , event = " ShowToc " , title = _ ( " Table of contents " ) , reader = true } ,
2022-01-04 20:58:56 +00:00
book_map = { category = " none " , event = " ShowBookMap " , title = _ ( " Book map " ) , reader = true , condition = Device : isTouchDevice ( ) } ,
2023-06-02 18:44:47 +00:00
book_map_overview = { category = " none " , event = " ShowBookMap " , arg = true , title = _ ( " Book map (overview) " ) , reader = true , condition = Device : isTouchDevice ( ) } ,
2022-01-04 20:58:56 +00:00
page_browser = { category = " none " , event = " ShowPageBrowser " , title = _ ( " Page browser " ) , reader = true , condition = Device : isTouchDevice ( ) } ,
2021-09-10 20:11:24 +00:00
bookmarks = { category = " none " , event = " ShowBookmark " , title = _ ( " Bookmarks " ) , reader = true } ,
2023-10-12 05:58:52 +00:00
bookmark_search = { category = " none " , event = " SearchBookmark " , title = _ ( " Bookmark search " ) , reader = true } ,
toggle_bookmark = { category = " none " , event = " ToggleBookmark " , title = _ ( " Toggle bookmark " ) , reader = true , separator = true } ,
----
2021-09-10 20:11:24 +00:00
book_status = { category = " none " , event = " ShowBookStatus " , title = _ ( " Book status " ) , reader = true } ,
book_info = { category = " none " , event = " ShowBookInfo " , title = _ ( " Book information " ) , reader = true } ,
book_description = { category = " none " , event = " ShowBookDescription " , title = _ ( " Book description " ) , reader = true } ,
book_cover = { category = " none " , event = " ShowBookCover " , title = _ ( " Book cover " ) , reader = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-17 04:34:37 +00:00
translate_page = { category = " none " , event = " TranslateCurrentPage " , title = _ ( " Translate current page " ) , reader = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
toggle_page_change_animation = { category = " none " , event = " TogglePageChangeAnimation " , title = _ ( " Toggle page turn animations " ) , reader = true , condition = Device : canDoSwipeAnimation ( ) } ,
toggle_inverse_reading_order = { category = " none " , event = " ToggleReadingOrder " , title = _ ( " Toggle page turn direction " ) , reader = true } ,
toggle_handmade_toc = { category = " none " , event = " ToggleHandmadeToc " , title = _ ( " Toggle custom TOC " ) , reader = true } ,
toggle_handmade_flows = { category = " none " , event = " ToggleHandmadeFlows " , title = _ ( " Toggle custom hidden flows " ) , reader = true , separator = true } ,
----
set_highlight_action = { category = " string " , event = " SetHighlightAction " , title = _ ( " Set highlight action " ) , args_func = ReaderHighlight.getHighlightActions , reader = true } ,
cycle_highlight_action = { category = " none " , event = " CycleHighlightAction " , title = _ ( " Cycle highlight action " ) , reader = true } ,
cycle_highlight_style = { category = " none " , event = " CycleHighlightStyle " , title = _ ( " Cycle highlight style " ) , reader = true , separator = true } ,
----
flush_settings = { category = " none " , event = " FlushSettings " , arg = true , title = _ ( " Save book metadata " ) , reader = true , separator = true } ,
----
2023-05-17 04:34:37 +00:00
2023-10-12 05:58:52 +00:00
-- Reflowable documents
2021-12-16 20:31:22 +00:00
set_font = { category = " string " , event = " SetFont " , title = _ ( " Set font " ) , rolling = true , args_func = require ( " fontlist " ) . getFontArgFunc , } ,
2022-11-14 20:42:06 +00:00
increase_font = { category = " incrementalnumber " , event = " IncreaseFontSize " , min = 0.5 , max = 255 , step = 0.5 , title = _ ( " Increase font size " ) , rolling = true } ,
decrease_font = { category = " incrementalnumber " , event = " DecreaseFontSize " , min = 0.5 , max = 255 , step = 0.5 , title = _ ( " Decrease font size " ) , rolling = true } ,
2020-07-14 21:39:03 +00:00
2023-10-12 05:58:52 +00:00
-- Page layout documents
2021-05-10 10:44:55 +00:00
toggle_page_flipping = { category = " none " , event = " TogglePageFlipping " , title = _ ( " Toggle page flipping " ) , paging = true } ,
2023-03-13 07:52:10 +00:00
toggle_bookmark_flipping = { category = " none " , event = " ToggleBookmarkFlipping " , title = _ ( " Toggle bookmark flipping " ) , paging = true } ,
2021-05-10 10:44:55 +00:00
toggle_reflow = { category = " none " , event = " ToggleReflow " , title = _ ( " Toggle reflow " ) , paging = true } ,
2023-03-30 05:36:41 +00:00
zoom = { category = " string " , event = " SetZoomMode " , title = _ ( " Zoom mode " ) , args_func = ReaderZooming.getZoomModeActions , paging = true } ,
2020-11-28 16:18:57 +00:00
zoom_factor_change = { category = " none " , event = " ZoomFactorChange " , title = _ ( " Change zoom factor " ) , paging = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2023-05-04 23:27:52 +00:00
panel_zoom_toggle = { category = " none " , event = " TogglePanelZoomSetting " , title = _ ( " Toggle panel zoom " ) , paging = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
-- parsed from CreOptions
2021-09-10 20:11:24 +00:00
rotation_mode = { category = " string " , device = true } ,
2023-10-12 05:58:52 +00:00
font_size = { category = " absolutenumber " , title = _ ( " Set font size " ) , rolling = true , step = 0.5 } ,
word_spacing = { category = " string " , rolling = true } ,
word_expansion = { category = " string " , rolling = true } ,
font_gamma = { category = " string " , rolling = true } ,
font_base_weight = { category = " string " , rolling = true } ,
font_hinting = { category = " string " , rolling = true } ,
font_kerning = { category = " string " , rolling = true , separator = true } ,
----
2021-05-10 10:44:55 +00:00
visible_pages = { category = " string " , rolling = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2021-10-19 09:50:31 +00:00
h_page_margins = { category = " string " , rolling = true } ,
2020-07-14 21:39:03 +00:00
sync_t_b_page_margins = { category = " string " , rolling = true } ,
t_page_margin = { category = " absolutenumber " , rolling = true } ,
2021-05-10 10:44:55 +00:00
b_page_margin = { category = " absolutenumber " , rolling = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
view_mode = { category = " string " , rolling = true } ,
block_rendering_mode = { category = " string " , rolling = true } ,
2022-11-14 20:42:06 +00:00
render_dpi = { category = " string " , title = _ ( " Zoom " ) , rolling = true } ,
2021-05-10 10:44:55 +00:00
line_spacing = { category = " absolutenumber " , rolling = true , separator = true } ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
status_line = { category = " string " , rolling = true } ,
embedded_css = { category = " string " , rolling = true } ,
embedded_fonts = { category = " string " , rolling = true } ,
smooth_scaling = { category = " string " , rolling = true } ,
2023-10-12 05:58:52 +00:00
nightmode_images = { category = " string " , rolling = true } ,
2021-05-14 22:13:27 +00:00
-- parsed from KoptOptions
kopt_trim_page = { category = " string " , paging = true } ,
kopt_page_margin = { category = " string " , paging = true } ,
2021-10-01 21:06:59 +00:00
kopt_zoom_overlap_h = { category = " absolutenumber " , paging = true } ,
kopt_zoom_overlap_v = { category = " absolutenumber " , paging = true } ,
2021-05-14 22:13:27 +00:00
kopt_zoom_mode_type = { category = " string " , paging = true } ,
2023-10-12 05:58:52 +00:00
-- kopt_zoom_range_number = {category="string", paging=true},
2021-05-14 22:13:27 +00:00
kopt_zoom_factor = { category = " string " , paging = true } ,
kopt_zoom_mode_genus = { category = " string " , paging = true } ,
kopt_zoom_direction = { category = " string " , paging = true } ,
kopt_page_scroll = { category = " string " , paging = true } ,
kopt_page_gap_height = { category = " string " , paging = true } ,
kopt_full_screen = { category = " string " , paging = true } ,
kopt_line_spacing = { category = " configurable " , paging = true } ,
kopt_justification = { category = " configurable " , paging = true } ,
kopt_font_size = { category = " string " , paging = true , title = _ ( " Font Size " ) } ,
kopt_font_fine_tune = { category = " string " , paging = true } ,
kopt_word_spacing = { category = " configurable " , paging = true } ,
kopt_text_wrap = { category = " string " , paging = true } ,
2023-09-02 06:41:27 +00:00
kopt_contrast = { category = " string " , paging = true } ,
2021-05-14 22:13:27 +00:00
kopt_page_opt = { category = " configurable " , paging = true } ,
kopt_hw_dithering = { category = " configurable " , paging = true , condition = Device : hasEinkScreen ( ) and Device : canHWDither ( ) } ,
2022-02-05 19:20:15 +00:00
kopt_sw_dithering = { category = " configurable " , paging = true , condition = Device : hasEinkScreen ( ) and not Device : canHWDither ( ) and Device.screen . fb_bpp == 8 } ,
2021-05-14 22:13:27 +00:00
kopt_quality = { category = " configurable " , paging = true } ,
kopt_doc_language = { category = " string " , paging = true } ,
kopt_forced_ocr = { category = " configurable " , paging = true } ,
kopt_writing_direction = { category = " configurable " , paging = true } ,
kopt_defect_size = { category = " string " , paging = true , condition = false } ,
2021-10-01 21:06:59 +00:00
kopt_auto_straighten = { category = " absolutenumber " , paging = true } ,
2021-05-14 22:13:27 +00:00
kopt_detect_indent = { category = " configurable " , paging = true , condition = false } ,
kopt_max_columns = { category = " configurable " , paging = true } ,
2022-09-19 02:22:41 +00:00
settings = nil , -- reserved for per instance dispatcher settings
2020-07-14 21:39:03 +00:00
}
-- array for item order in menu
local dispatcher_menu_order = {
2023-10-12 05:58:52 +00:00
-- General
2020-07-14 21:39:03 +00:00
" reading_progress " ,
" open_previous_document " ,
2021-09-10 20:11:24 +00:00
" history " ,
2023-11-09 05:34:56 +00:00
" history_search " ,
2020-07-14 21:39:03 +00:00
" favorites " ,
2024-05-01 06:01:59 +00:00
" collections " ,
2020-07-14 21:39:03 +00:00
" filemanager " ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
" dictionary_lookup " ,
" wikipedia_lookup " ,
2023-10-12 05:58:52 +00:00
----
2021-09-10 20:11:24 +00:00
" show_menu " ,
2022-12-06 21:02:21 +00:00
" menu_search " ,
2021-09-10 20:11:24 +00:00
" screenshot " ,
2023-10-12 05:58:52 +00:00
----
2021-09-10 20:11:24 +00:00
2023-10-12 05:58:52 +00:00
-- Device
2022-07-11 11:50:28 +00:00
" exit_screensaver " ,
2023-11-22 17:59:07 +00:00
" start_usbms " ,
2020-07-14 21:39:03 +00:00
" suspend " ,
" restart " ,
" reboot " ,
" poweroff " ,
2023-10-12 05:58:52 +00:00
" exit " ,
----
2021-09-10 20:11:24 +00:00
" toggle_hold_corners " ,
2023-07-03 04:58:51 +00:00
" touch_input_on " ,
" touch_input_off " ,
2022-11-02 22:20:56 +00:00
" toggle_touch_input " ,
2023-10-12 05:58:52 +00:00
----
2023-08-11 22:34:29 +00:00
" swap_page_turn_buttons " ,
2023-10-12 05:58:52 +00:00
----
2023-08-11 22:34:29 +00:00
" toggle_key_repeat " ,
2021-09-10 20:11:24 +00:00
" toggle_gsensor " ,
2024-05-11 09:47:33 +00:00
" lock_gsensor " ,
2021-09-10 20:11:24 +00:00
" rotation_mode " ,
" toggle_rotation " ,
" invert_rotation " ,
" iterate_rotation " ,
2022-09-04 00:38:27 +00:00
" iterate_rotation_ccw " ,
2023-10-12 05:58:52 +00:00
----
2021-09-10 20:11:24 +00:00
" wifi_on " ,
" wifi_off " ,
" toggle_wifi " ,
2022-06-24 21:19:38 +00:00
" toggle_fullscreen " ,
2022-05-06 17:19:55 +00:00
" show_network_info " ,
2023-10-12 05:58:52 +00:00
----
2021-09-10 20:11:24 +00:00
2023-10-12 05:58:52 +00:00
-- Screen and lights
2020-07-14 21:39:03 +00:00
" show_frontlight_dialog " ,
" toggle_frontlight " ,
2020-07-29 21:48:28 +00:00
" set_frontlight " ,
2020-07-14 21:39:03 +00:00
" increase_frontlight " ,
" decrease_frontlight " ,
2020-07-29 21:48:28 +00:00
" set_frontlight_warmth " ,
2020-07-14 21:39:03 +00:00
" increase_frontlight_warmth " ,
" decrease_frontlight_warmth " ,
2021-09-10 20:11:24 +00:00
" night_mode " ,
" set_night_mode " ,
2023-10-12 05:58:52 +00:00
----
2021-09-10 20:11:24 +00:00
" full_refresh " ,
2020-08-21 12:33:08 +00:00
" set_refresh_rate " ,
" set_day_refresh_rate " ,
" set_night_refresh_rate " ,
" set_flash_on_chapter_boundaries " ,
" toggle_flash_on_chapter_boundaries " ,
" set_no_flash_on_second_chapter_page " ,
" toggle_no_flash_on_second_chapter_page " ,
2023-02-02 20:09:29 +00:00
" set_flash_on_pages_with_images " ,
" toggle_flash_on_pages_with_images " ,
2023-10-12 05:58:52 +00:00
----
2020-08-21 12:33:08 +00:00
2023-10-12 05:58:52 +00:00
-- File browser
2024-06-01 07:33:14 +00:00
" set_display_mode " ,
" set_sort_by " ,
" set_reverse_sorting " ,
" set_mixed_sorting " ,
----
2020-07-14 21:39:03 +00:00
" folder_up " ,
" show_plus_menu " ,
2021-12-16 11:12:25 +00:00
" toggle_select_mode " ,
2021-05-05 18:43:43 +00:00
" refresh_content " ,
2020-07-14 21:39:03 +00:00
" folder_shortcuts " ,
2023-10-12 05:58:52 +00:00
" file_search " ,
----
-- "go_to"
-- "back"
2020-07-14 21:39:03 +00:00
2023-10-12 05:58:52 +00:00
-- Reader
2022-12-14 19:40:24 +00:00
" open_next_document_in_folder " ,
2023-10-12 05:58:52 +00:00
----
2021-09-10 20:11:24 +00:00
" show_config_menu " ,
2021-04-26 19:45:34 +00:00
" toggle_status_bar " ,
2024-03-10 06:05:30 +00:00
" toggle_chapter_progress_bar " ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
" prev_chapter " ,
" next_chapter " ,
" first_page " ,
" last_page " ,
2024-04-28 15:03:58 +00:00
" random_page " ,
2021-05-10 10:44:55 +00:00
" page_jmp " ,
2020-07-14 21:39:03 +00:00
" go_to " ,
" skim " ,
2021-05-10 10:44:55 +00:00
" prev_bookmark " ,
" next_bookmark " ,
2023-09-15 04:24:31 +00:00
" first_bookmark " ,
" last_bookmark " ,
2021-05-10 10:44:55 +00:00
" latest_bookmark " ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
" back " ,
" previous_location " ,
2023-03-29 16:32:44 +00:00
" next_location " ,
2020-07-14 21:39:03 +00:00
" follow_nearest_link " ,
" follow_nearest_internal_link " ,
2023-05-04 23:00:28 +00:00
" add_location_to_history " ,
2020-07-14 21:39:03 +00:00
" clear_location_history " ,
2023-10-12 05:58:52 +00:00
----
" fulltext_search " ,
2024-01-20 08:00:21 +00:00
" fulltext_search_findall_results " ,
2020-07-14 21:39:03 +00:00
" toc " ,
2022-01-04 20:58:56 +00:00
" book_map " ,
2023-06-02 18:44:47 +00:00
" book_map_overview " ,
2022-01-04 20:58:56 +00:00
" page_browser " ,
2020-07-14 21:39:03 +00:00
" bookmarks " ,
2021-12-04 17:37:00 +00:00
" bookmark_search " ,
2023-10-12 05:58:52 +00:00
" toggle_bookmark " ,
----
2020-07-14 21:39:03 +00:00
" book_status " ,
" book_info " ,
" book_description " ,
" book_cover " ,
2023-10-12 05:58:52 +00:00
----
2023-05-17 04:34:37 +00:00
" translate_page " ,
2023-10-12 05:58:52 +00:00
----
" toggle_page_change_animation " ,
" toggle_inverse_reading_order " ,
" toggle_handmade_toc " ,
" toggle_handmade_flows " ,
----
" set_highlight_action " ,
" cycle_highlight_action " ,
" cycle_highlight_style " ,
----
" flush_settings " ,
----
2023-05-17 04:34:37 +00:00
2023-10-12 05:58:52 +00:00
-- Reflowable documents
2021-12-16 20:31:22 +00:00
" set_font " ,
2020-07-14 21:39:03 +00:00
" increase_font " ,
" decrease_font " ,
" font_size " ,
2023-02-14 01:16:23 +00:00
" word_spacing " ,
" word_expansion " ,
2020-09-21 21:51:12 +00:00
" font_gamma " ,
2021-04-28 23:37:53 +00:00
" font_base_weight " ,
2020-07-14 21:39:03 +00:00
" font_hinting " ,
" font_kerning " ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
" visible_pages " ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
" h_page_margins " ,
" sync_t_b_page_margins " ,
" t_page_margin " ,
" b_page_margin " ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
" view_mode " ,
" block_rendering_mode " ,
" render_dpi " ,
" line_spacing " ,
2023-10-12 05:58:52 +00:00
----
2020-07-14 21:39:03 +00:00
" status_line " ,
" embedded_css " ,
" embedded_fonts " ,
" smooth_scaling " ,
" nightmode_images " ,
2021-05-14 22:13:27 +00:00
2023-10-12 05:58:52 +00:00
-- Fixed layout documents
" toggle_page_flipping " ,
" toggle_bookmark_flipping " ,
" toggle_reflow " ,
" zoom " ,
" zoom_factor_change " ,
----
" panel_zoom_toggle " ,
----
2021-05-14 22:13:27 +00:00
" kopt_trim_page " ,
" kopt_page_margin " ,
" kopt_zoom_overlap_h " ,
" kopt_zoom_overlap_v " ,
" kopt_zoom_mode_type " ,
--"kopt_zoom_range_number", -- can't figure out how this name text func works
" kopt_zoom_factor " ,
" kopt_zoom_mode_genus " ,
" kopt_zoom_direction " ,
" kopt_page_scroll " ,
" kopt_page_gap_height " ,
" kopt_full_screen " ,
" kopt_line_spacing " ,
" kopt_justification " ,
" kopt_font_size " ,
" kopt_font_fine_tune " ,
" kopt_word_spacing " ,
" kopt_text_wrap " ,
" kopt_contrast " ,
" kopt_page_opt " ,
" kopt_hw_dithering " ,
2022-02-05 18:49:13 +00:00
" kopt_sw_dithering " ,
2021-05-14 22:13:27 +00:00
" kopt_quality " ,
" kopt_doc_language " ,
" kopt_forced_ocr " ,
" kopt_writing_direction " ,
" kopt_defect_size " ,
" kopt_auto_straighten " ,
" kopt_detect_indent " ,
" kopt_max_columns " ,
2020-06-19 21:38:53 +00:00
}
--[[--
add settings from CreOptions / KoptOptions
--]]--
function Dispatcher : init ( )
2020-09-22 00:05:02 +00:00
if Dispatcher.initialized then return end
2021-05-14 22:13:27 +00:00
local parseoptions = function ( base , i , prefix )
for y = 1 , # base [ i ] . options do
2020-06-19 21:38:53 +00:00
local option = base [ i ] . options [ y ]
2021-05-14 22:13:27 +00:00
local name = prefix and prefix .. option.name or option.name
if settingsList [ name ] ~= nil then
2021-01-07 22:19:23 +00:00
if option.name ~= nil and option.values ~= nil then
2021-05-14 22:13:27 +00:00
settingsList [ name ] . configurable = { name = option.name , values = option.values }
2021-01-07 22:19:23 +00:00
end
2021-05-14 22:13:27 +00:00
if settingsList [ name ] . event == nil then
settingsList [ name ] . event = option.event
2020-06-19 21:38:53 +00:00
end
2021-05-14 22:13:27 +00:00
if settingsList [ name ] . title == nil then
settingsList [ name ] . title = option.name_text
2020-06-19 21:38:53 +00:00
end
2021-05-14 22:13:27 +00:00
if settingsList [ name ] . category == " string " or settingsList [ name ] . category == " configurable " then
if settingsList [ name ] . toggle == nil then
settingsList [ name ] . toggle = option.toggle or option.labels
if settingsList [ name ] . toggle == nil then
settingsList [ name ] . toggle = { }
2020-06-28 10:18:45 +00:00
for z = 1 , # option.values do
if type ( option.values [ z ] ) == " table " then
2021-05-14 22:13:27 +00:00
settingsList [ name ] . toggle [ z ] = option.values [ z ] [ 1 ]
else
settingsList [ name ] . toggle [ z ] = option.values [ z ]
2020-06-28 10:18:45 +00:00
end
2020-06-19 21:38:53 +00:00
end
end
end
2021-05-14 22:13:27 +00:00
if settingsList [ name ] . args == nil then
settingsList [ name ] . args = option.args or option.values
2020-06-19 21:38:53 +00:00
end
2021-05-14 22:13:27 +00:00
elseif settingsList [ name ] . category == " absolutenumber " then
if settingsList [ name ] . min == nil then
2021-10-01 21:06:59 +00:00
settingsList [ name ] . min = option.args and option.args [ 1 ] or option.values [ 1 ]
2020-06-19 21:38:53 +00:00
end
2021-05-14 22:13:27 +00:00
if settingsList [ name ] . max == nil then
2021-10-01 21:06:59 +00:00
settingsList [ name ] . max = option.args and option.args [ # option.args ] or option.values [ # option.values ]
2020-06-19 21:38:53 +00:00
end
2021-05-14 22:13:27 +00:00
if settingsList [ name ] . default == nil then
settingsList [ name ] . default = option.default_value
2020-06-19 21:38:53 +00:00
end
end
2022-11-14 20:42:06 +00:00
settingsList [ name ] . unit = option.more_options_param and option.more_options_param . unit
2020-06-19 21:38:53 +00:00
end
end
end
for i = 1 , # CreOptions do
parseoptions ( CreOptions , i )
end
2021-05-14 22:13:27 +00:00
for i = 1 , # KoptOptions do
parseoptions ( KoptOptions , i , " kopt_ " )
end
2020-10-12 03:06:04 +00:00
UIManager : broadcastEvent ( Event : new ( " DispatcherRegisterActions " ) )
2020-06-19 21:38:53 +00:00
Dispatcher.initialized = true
end
2020-10-12 03:06:04 +00:00
--[[--
2020-10-12 15:20:16 +00:00
Adds settings at runtime .
@ usage
function Hello : onDispatcherRegisterActions ( )
2021-09-10 20:11:24 +00:00
Dispatcher : registerAction ( " helloworld_action " , { category = " none " , event = " HelloWorld " , title = _ ( " Hello World " ) , general = true } )
2020-10-12 15:20:16 +00:00
end
function Hello : init ( )
self : onDispatcherRegisterActions ( )
end
@ param name the key to use in the table
@ param value a table per settingsList above
2020-10-12 03:06:04 +00:00
--]]--
function Dispatcher : registerAction ( name , value )
if settingsList [ name ] == nil then
settingsList [ name ] = value
table.insert ( dispatcher_menu_order , name )
end
return true
end
2021-09-10 20:14:07 +00:00
--[[--
Removes settings at runtime .
@ param name the key to use in the table
--]]--
function Dispatcher : removeAction ( name )
local k = util.arrayContains ( dispatcher_menu_order , name )
if k then
table.remove ( dispatcher_menu_order , k )
settingsList [ name ] = nil
end
return true
end
2022-09-19 02:22:41 +00:00
local function iter_func ( settings )
if settings and settings.settings and settings.settings . order then
return ipairs ( settings.settings . order )
else
return pairs ( settings )
end
end
2022-10-27 12:29:50 +00:00
-- Returns the number of items present in the settings table
function Dispatcher : _itemsCount ( settings )
if settings then
local count = util.tableSize ( settings )
if count > 0 and settings.settings ~= nil then
count = count - 1
end
return count
end
end
2020-07-28 18:49:55 +00:00
-- Returns a display name for the item.
2022-11-14 20:42:06 +00:00
function Dispatcher : getNameFromItem ( item , settings , dont_show_value )
2020-10-12 03:06:04 +00:00
if settingsList [ item ] == nil then
return _ ( " Unknown item " )
end
2022-11-14 20:42:06 +00:00
local title , category = settingsList [ item ] . title , settingsList [ item ] . category
local value = settings and settings [ item ]
if dont_show_value or value == nil or ( value == 0 and category == " incrementalnumber " ) then
return title
else
local display_value
if category == " string " or category == " configurable " then
if type ( value ) == " table " then
display_value = string.format ( " %d / %d " , unpack ( value ) )
else
2023-02-05 09:47:38 +00:00
if not settingsList [ item ] . args and settingsList [ item ] . args_func then
settingsList [ item ] . args , settingsList [ item ] . toggle = settingsList [ item ] . args_func ( )
end
2022-11-14 20:42:06 +00:00
local value_num = util.arrayContains ( settingsList [ item ] . args , value )
2023-05-28 05:06:29 +00:00
display_value = settingsList [ item ] . toggle [ value_num ] or string.format ( " %.1f " , value )
2022-11-14 20:42:06 +00:00
end
elseif category == " absolutenumber " or category == " incrementalnumber " then
display_value = tostring ( value )
end
if display_value then
2023-05-28 05:06:29 +00:00
if settingsList [ item ] . unit and ( type ( value ) == " table " or tonumber ( display_value ) ) then
2022-11-14 20:42:06 +00:00
display_value = display_value .. " " .. settingsList [ item ] . unit
end
title = title .. " : " .. display_value
end
2020-07-28 18:49:55 +00:00
end
2022-11-14 20:42:06 +00:00
return title
2020-07-28 18:49:55 +00:00
end
2023-08-11 05:38:29 +00:00
-- Converts copt/kopt-options values to args.
function Dispatcher : getArgFromValue ( item , value )
local value_num = util.arrayContains ( settingsList [ item ] . configurable.values , value )
return settingsList [ item ] . args [ value_num ]
end
2022-09-19 02:22:41 +00:00
-- Add the item to the end of the execution order.
-- If item or the order is nil all items will be added.
function Dispatcher : _addToOrder ( location , settings , item )
if location [ settings ] then
if not location [ settings ] . settings then location [ settings ] . settings = { } end
if not location [ settings ] . settings.order or item == nil then
location [ settings ] . settings.order = { }
for k in pairs ( location [ settings ] ) do
if settingsList [ k ] ~= nil then
table.insert ( location [ settings ] . settings.order , k )
end
end
else
2022-10-12 21:17:10 +00:00
if not util.arrayContains ( location [ settings ] . settings.order , item ) then
table.insert ( location [ settings ] . settings.order , item )
end
2022-09-19 02:22:41 +00:00
end
end
end
-- Remove the item from the execution order.
-- If item is nil all items will be removed.
-- If the resulting order is empty it will be nilled
function Dispatcher : _removeFromOrder ( location , settings , item )
if location [ settings ] and location [ settings ] . settings then
if location [ settings ] . settings.order then
if item then
local k = util.arrayContains ( location [ settings ] . settings.order , item )
if k then table.remove ( location [ settings ] . settings.order , k ) end
else
location [ settings ] . settings.order = { }
end
if next ( location [ settings ] . settings.order ) == nil then
location [ settings ] . settings.order = nil
if next ( location [ settings ] . settings ) == nil then
location [ settings ] . settings = nil
end
end
end
end
end
-- Get a textual representation of the enabled actions to display in a menu item.
function Dispatcher : menuTextFunc ( settings )
local action_name = _ ( " Pass through " )
if settings then
2022-10-27 12:29:50 +00:00
local count = Dispatcher : _itemsCount ( settings )
2022-09-19 02:22:41 +00:00
if count == 0 then return _ ( " Nothing " ) end
if count == 1 then
local item = next ( settings )
if item == " settings " then item = next ( settings , item ) end
action_name = Dispatcher : getNameFromItem ( item , settings )
else
2022-11-03 07:46:16 +00:00
action_name = T ( NC_ ( " Dispatcher " , " 1 action " , " %1 actions " , count ) , count )
2022-09-19 02:22:41 +00:00
end
end
return action_name
end
-- Get a list of all enabled actions to display in a menu.
function Dispatcher : getDisplayList ( settings )
local item_table = { }
if not settings then return item_table end
for item , v in iter_func ( settings ) do
if type ( item ) == " number " then item = v end
if settingsList [ item ] ~= nil and ( settingsList [ item ] . condition == nil or settingsList [ item ] . condition == true ) then
table.insert ( item_table , { text = Dispatcher : getNameFromItem ( item , settings ) , key = item } )
end
end
return item_table
end
-- Display a SortWidget to sort the enable actions execution order.
function Dispatcher : _sortActions ( caller , location , settings , touchmenu_instance )
local display_list = Dispatcher : getDisplayList ( location [ settings ] )
local SortWidget = require ( " ui/widget/sortwidget " )
local sort_widget
sort_widget = SortWidget : new {
2024-05-01 06:01:59 +00:00
title = _ ( " Arrange actions " ) ,
2022-09-19 02:22:41 +00:00
item_table = display_list ,
callback = function ( )
if location [ settings ] and next ( location [ settings ] ) ~= nil then
if not location [ settings ] . settings then
location [ settings ] . settings = { }
end
location [ settings ] . settings.order = { }
for i , v in ipairs ( sort_widget.item_table ) do
location [ settings ] . settings.order [ i ] = v.key
end
end
2023-07-08 05:17:42 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
2022-09-19 02:22:41 +00:00
caller.updated = true
end
}
UIManager : show ( sort_widget )
end
function Dispatcher : _addItem ( caller , menu , location , settings , section )
2020-07-14 21:39:03 +00:00
for _ , k in ipairs ( dispatcher_menu_order ) do
if settingsList [ k ] [ section ] == true and
( settingsList [ k ] . condition == nil or settingsList [ k ] . condition )
then
if settingsList [ k ] . category == " none " or settingsList [ k ] . category == " arg " then
2020-06-19 21:38:53 +00:00
table.insert ( menu , {
2022-11-22 12:46:44 +00:00
text = settingsList [ k ] . title ,
checked_func = function ( )
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
end ,
callback = function ( touchmenu_instance )
if location [ settings ] == nil then
location [ settings ] = { }
end
if location [ settings ] [ k ] then
location [ settings ] [ k ] = nil
Dispatcher : _removeFromOrder ( location , settings , k )
else
location [ settings ] [ k ] = true
Dispatcher : _addToOrder ( location , settings , k )
end
caller.updated = true
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
2020-06-19 21:38:53 +00:00
end ,
2021-05-25 14:12:16 +00:00
separator = settingsList [ k ] . separator ,
} )
2020-06-19 21:38:53 +00:00
elseif settingsList [ k ] . category == " absolutenumber " then
table.insert ( menu , {
text_func = function ( )
2022-09-19 02:22:41 +00:00
return Dispatcher : getNameFromItem ( k , location [ settings ] )
2020-06-19 21:38:53 +00:00
end ,
checked_func = function ( )
2022-11-22 12:46:44 +00:00
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
2020-06-19 21:38:53 +00:00
end ,
callback = function ( touchmenu_instance )
local SpinWidget = require ( " ui/widget/spinwidget " )
2021-05-13 02:38:52 +00:00
local precision
2021-05-05 18:48:42 +00:00
if settingsList [ k ] . step and math.floor ( settingsList [ k ] . step ) ~= settingsList [ k ] . step then
2021-05-13 02:38:52 +00:00
precision = " %0.1f "
2021-05-05 18:48:42 +00:00
end
2020-06-19 21:38:53 +00:00
local items = SpinWidget : new {
2022-11-14 20:42:06 +00:00
value = location [ settings ] ~= nil and location [ settings ] [ k ] or settingsList [ k ] . default or settingsList [ k ] . min ,
2020-06-19 21:38:53 +00:00
value_min = settingsList [ k ] . min ,
2021-05-05 18:48:42 +00:00
value_step = settingsList [ k ] . step or 1 ,
2021-05-13 02:38:52 +00:00
precision = precision ,
2021-01-11 17:14:10 +00:00
value_hold_step = 5 ,
2020-06-19 21:38:53 +00:00
value_max = settingsList [ k ] . max ,
2021-05-05 18:48:42 +00:00
default_value = settingsList [ k ] . default ,
2022-11-14 20:42:06 +00:00
title_text = Dispatcher : getNameFromItem ( k , location [ settings ] , true ) ,
2021-12-16 11:55:05 +00:00
ok_always_enabled = true ,
2020-06-19 21:38:53 +00:00
callback = function ( spin )
2020-07-28 18:49:55 +00:00
if location [ settings ] == nil then
location [ settings ] = { }
end
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = spin.value
2022-09-19 02:22:41 +00:00
Dispatcher : _addToOrder ( location , settings , k )
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end
}
UIManager : show ( items )
end ,
hold_callback = function ( touchmenu_instance )
2020-07-28 18:49:55 +00:00
if location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil then
location [ settings ] [ k ] = nil
2022-09-19 02:22:41 +00:00
Dispatcher : _removeFromOrder ( location , settings , k )
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
2020-06-19 21:38:53 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
2020-07-14 21:39:03 +00:00
separator = settingsList [ k ] . separator ,
2020-06-19 21:38:53 +00:00
} )
elseif settingsList [ k ] . category == " incrementalnumber " then
table.insert ( menu , {
text_func = function ( )
2022-09-19 02:22:41 +00:00
return Dispatcher : getNameFromItem ( k , location [ settings ] )
2020-06-19 21:38:53 +00:00
end ,
checked_func = function ( )
2022-11-22 12:46:44 +00:00
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
2020-06-19 21:38:53 +00:00
end ,
callback = function ( touchmenu_instance )
2020-07-14 21:39:03 +00:00
local _ = require ( " gettext " )
2021-05-13 02:38:52 +00:00
local precision
2021-05-05 18:48:42 +00:00
if settingsList [ k ] . step and math.floor ( settingsList [ k ] . step ) ~= settingsList [ k ] . step then
2021-05-13 02:38:52 +00:00
precision = " %0.1f "
2021-05-05 18:48:42 +00:00
end
2020-06-19 21:38:53 +00:00
local SpinWidget = require ( " ui/widget/spinwidget " )
local items = SpinWidget : new {
2022-11-14 20:42:06 +00:00
value = location [ settings ] ~= nil and location [ settings ] [ k ] or settingsList [ k ] . min ,
2020-06-19 21:38:53 +00:00
value_min = settingsList [ k ] . min ,
2021-05-05 18:48:42 +00:00
value_step = settingsList [ k ] . step or 1 ,
2021-05-13 02:38:52 +00:00
precision = precision ,
2021-01-11 17:14:10 +00:00
value_hold_step = 5 ,
2020-06-19 21:38:53 +00:00
value_max = settingsList [ k ] . max ,
2022-11-14 20:42:06 +00:00
title_text = Dispatcher : getNameFromItem ( k , location [ settings ] , true ) ,
2023-12-15 06:27:15 +00:00
info_text = _ ( [[When set to 0, the gesture's distance (if any) is used]] ) ,
2021-12-16 11:55:05 +00:00
ok_always_enabled = true ,
2020-06-19 21:38:53 +00:00
callback = function ( spin )
2020-07-28 18:49:55 +00:00
if location [ settings ] == nil then
location [ settings ] = { }
end
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = spin.value
2022-09-19 02:22:41 +00:00
Dispatcher : _addToOrder ( location , settings , k )
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end
}
UIManager : show ( items )
end ,
hold_callback = function ( touchmenu_instance )
2020-07-28 18:49:55 +00:00
if location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil then
location [ settings ] [ k ] = nil
2022-09-19 02:22:41 +00:00
Dispatcher : _removeFromOrder ( location , settings , k )
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end ,
2020-07-14 21:39:03 +00:00
separator = settingsList [ k ] . separator ,
2020-06-19 21:38:53 +00:00
} )
2021-05-14 22:13:27 +00:00
elseif settingsList [ k ] . category == " string " or settingsList [ k ] . category == " configurable " then
2020-06-19 21:38:53 +00:00
local sub_item_table = { }
2023-02-05 09:47:38 +00:00
if not settingsList [ k ] . args and settingsList [ k ] . args_func then
2021-12-16 20:30:48 +00:00
settingsList [ k ] . args , settingsList [ k ] . toggle = settingsList [ k ] . args_func ( )
end
2020-06-19 21:38:53 +00:00
for i = 1 , # settingsList [ k ] . args do
table.insert ( sub_item_table , {
text = tostring ( settingsList [ k ] . toggle [ i ] ) ,
checked_func = function ( )
2022-11-14 20:42:06 +00:00
if location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil then
if type ( location [ settings ] [ k ] ) == " table " then
return location [ settings ] [ k ] [ 1 ] == settingsList [ k ] . args [ i ] [ 1 ]
else
return location [ settings ] [ k ] == settingsList [ k ] . args [ i ]
end
end
2020-06-19 21:38:53 +00:00
end ,
callback = function ( )
2020-07-28 18:49:55 +00:00
if location [ settings ] == nil then
location [ settings ] = { }
end
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = settingsList [ k ] . args [ i ]
2022-09-19 02:22:41 +00:00
Dispatcher : _addToOrder ( location , settings , k )
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-06-19 21:38:53 +00:00
end ,
} )
end
table.insert ( menu , {
text_func = function ( )
2022-09-19 02:22:41 +00:00
return Dispatcher : getNameFromItem ( k , location [ settings ] )
2020-06-19 21:38:53 +00:00
end ,
checked_func = function ( )
2020-07-28 18:49:55 +00:00
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
2020-06-19 21:38:53 +00:00
end ,
sub_item_table = sub_item_table ,
keep_menu_open = true ,
hold_callback = function ( touchmenu_instance )
2020-07-28 18:49:55 +00:00
if location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil then
location [ settings ] [ k ] = nil
2022-09-19 02:22:41 +00:00
Dispatcher : _removeFromOrder ( location , settings , k )
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end ,
2020-07-14 21:39:03 +00:00
separator = settingsList [ k ] . separator ,
2021-05-25 14:16:53 +00:00
menu_item_id = k ,
2020-06-19 21:38:53 +00:00
} )
end
end
2020-07-14 21:39:03 +00:00
end
end
--[[--
Add a submenu to edit which items are dispatched
arguments are :
2020-08-04 22:19:28 +00:00
1 ) the caller so dispatcher can set the updated flag
2 ) the table representing the submenu ( can be empty )
3 ) the object ( table ) in which the settings table is found
4 ) the name of the settings table
2020-07-14 21:39:03 +00:00
example usage :
2021-09-10 20:14:07 +00:00
Dispatcher : addSubMenu ( self , sub_items , self.data , " profile1 " )
2020-07-14 21:39:03 +00:00
--]]--
2020-08-04 22:19:28 +00:00
function Dispatcher : addSubMenu ( caller , menu , location , settings )
2020-09-22 00:05:02 +00:00
Dispatcher : init ( )
2022-12-18 00:25:41 +00:00
menu.ignored_by_menu_search = true -- all those would be duplicated
2020-07-14 21:39:03 +00:00
table.insert ( menu , {
2020-07-28 18:49:55 +00:00
text = _ ( " Nothing " ) ,
2020-07-14 21:39:03 +00:00
separator = true ,
checked_func = function ( )
2022-10-27 12:29:50 +00:00
return location [ settings ] ~= nil and Dispatcher : _itemsCount ( location [ settings ] ) == 0
2020-07-14 21:39:03 +00:00
end ,
callback = function ( touchmenu_instance )
2022-10-27 12:29:50 +00:00
local name = location [ settings ] and location [ settings ] . settings and location [ settings ] . settings.name
2020-07-28 01:26:56 +00:00
location [ settings ] = { }
2022-10-27 12:29:50 +00:00
if name then
location [ settings ] . settings = { name = name }
end
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-14 21:39:03 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
} )
local section_list = {
2021-09-10 20:11:24 +00:00
{ " general " , _ ( " General " ) } ,
2020-07-14 21:39:03 +00:00
{ " device " , _ ( " Device " ) } ,
2021-09-14 07:22:43 +00:00
{ " screen " , _ ( " Screen and lights " ) } ,
2020-07-17 07:57:46 +00:00
{ " filemanager " , _ ( " File browser " ) } ,
2021-09-10 20:11:24 +00:00
{ " reader " , _ ( " Reader " ) } ,
2020-07-14 21:39:03 +00:00
{ " rolling " , _ ( " Reflowable documents (epub, fb2, txt…) " ) } ,
{ " paging " , _ ( " Fixed layout documents (pdf, djvu, pics…) " ) } ,
}
2023-11-26 05:52:43 +00:00
menu.max_per_page = 1 + # section_list -- settings in page 2
2020-07-14 21:39:03 +00:00
for _ , section in ipairs ( section_list ) do
local submenu = { }
2022-09-19 02:22:41 +00:00
Dispatcher : _addItem ( caller , submenu , location , settings , section [ 1 ] )
2020-07-14 21:39:03 +00:00
table.insert ( menu , {
text = section [ 2 ] ,
2020-07-28 18:49:55 +00:00
checked_func = function ( )
if location [ settings ] ~= nil then
for k , _ in pairs ( location [ settings ] ) do
2020-10-12 03:06:04 +00:00
if settingsList [ k ] ~= nil and settingsList [ k ] [ section [ 1 ] ] == true and
2020-07-28 18:49:55 +00:00
( settingsList [ k ] . condition == nil or settingsList [ k ] . condition )
then return true end
end
end
end ,
hold_callback = function ( touchmenu_instance )
if location [ settings ] ~= nil then
for k , _ in pairs ( location [ settings ] ) do
2020-10-12 03:06:04 +00:00
if settingsList [ k ] ~= nil and settingsList [ k ] [ section [ 1 ] ] == true then
2020-07-28 18:49:55 +00:00
location [ settings ] [ k ] = nil
2022-09-19 02:22:41 +00:00
Dispatcher : _removeFromOrder ( location , settings , k )
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
end
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end
end ,
2020-07-14 21:39:03 +00:00
sub_item_table = submenu ,
} )
end
2022-09-19 02:22:41 +00:00
menu [ # menu ] . separator = true
table.insert ( menu , {
2024-05-01 06:01:59 +00:00
text = _ ( " Arrange actions " ) ,
2022-09-19 02:22:41 +00:00
checked_func = function ( )
return location [ settings ] ~= nil
and location [ settings ] . settings ~= nil
2023-07-08 05:17:42 +00:00
and location [ settings ] . settings.order ~= nil
2022-09-19 02:22:41 +00:00
end ,
2023-07-08 05:17:42 +00:00
callback = function ( touchmenu_instance )
Dispatcher : _sortActions ( caller , location , settings , touchmenu_instance )
end ,
hold_callback = function ( touchmenu_instance )
if location [ settings ]
and location [ settings ] . settings
and location [ settings ] . settings.order then
Dispatcher : _removeFromOrder ( location , settings )
2022-10-06 00:46:58 +00:00
caller.updated = true
2023-07-08 05:17:42 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
2022-09-19 02:22:41 +00:00
end
end ,
} )
2023-07-03 04:58:51 +00:00
table.insert ( menu , {
2023-07-08 05:17:42 +00:00
text = _ ( " Show as QuickMenu " ) ,
2023-07-03 04:58:51 +00:00
checked_func = function ( )
return location [ settings ] ~= nil
and location [ settings ] . settings ~= nil
2023-07-08 05:17:42 +00:00
and location [ settings ] . settings.show_as_quickmenu
2023-07-03 04:58:51 +00:00
end ,
callback = function ( )
if location [ settings ] then
if location [ settings ] . settings then
2023-07-08 05:17:42 +00:00
if location [ settings ] . settings.show_as_quickmenu then
location [ settings ] . settings.show_as_quickmenu = nil
2023-07-03 04:58:51 +00:00
if next ( location [ settings ] . settings ) == nil then
location [ settings ] . settings = nil
end
else
2023-07-08 05:17:42 +00:00
location [ settings ] . settings.show_as_quickmenu = true
2023-07-03 04:58:51 +00:00
end
else
2023-07-08 05:17:42 +00:00
location [ settings ] . settings = { [ " show_as_quickmenu " ] = true }
2023-07-03 04:58:51 +00:00
end
caller.updated = true
end
end ,
} )
2023-11-26 05:52:43 +00:00
table.insert ( menu , {
text = _ ( " Keep QuickMenu open " ) ,
checked_func = function ( )
return location [ settings ] ~= nil
and location [ settings ] . settings ~= nil
and location [ settings ] . settings.keep_open_on_apply
end ,
callback = function ( )
if location [ settings ] then
if location [ settings ] . settings then
if location [ settings ] . settings.keep_open_on_apply then
location [ settings ] . settings.keep_open_on_apply = nil
if next ( location [ settings ] . settings ) == nil then
location [ settings ] . settings = nil
end
else
location [ settings ] . settings.keep_open_on_apply = true
end
else
location [ settings ] . settings = { [ " keep_open_on_apply " ] = true }
end
caller.updated = true
end
end ,
} )
2022-09-19 02:22:41 +00:00
end
2023-06-02 15:54:54 +00:00
function Dispatcher : isActionEnabled ( action )
local disabled = true
if action and ( action.condition == nil or action.condition == true ) then
local ui = require ( " apps/reader/readerui " ) . instance
local context = ui and ( ui.paging and " paging " or " rolling " )
if context == " paging " then
2023-10-20 09:16:26 +00:00
disabled = action [ " rolling " ]
2023-06-02 15:54:54 +00:00
elseif context == " rolling " then
2023-10-20 09:16:26 +00:00
disabled = action [ " paging " ]
2023-06-02 15:54:54 +00:00
else -- FM
disabled = ( action [ " reader " ] or action [ " rolling " ] or action [ " paging " ] ) and not action [ " filemanager " ]
end
end
return not disabled
end
2023-07-28 15:10:35 +00:00
function Dispatcher : _showAsMenu ( settings , exec_props )
2023-11-26 05:52:43 +00:00
local title = settings.settings . name or _ ( " QuickMenu " )
local keep_open_on_apply = settings.settings . keep_open_on_apply
2022-09-19 02:22:41 +00:00
local display_list = Dispatcher : getDisplayList ( settings )
local quickmenu
local buttons = { }
2023-07-28 15:10:35 +00:00
if exec_props and exec_props.qm_show then
table.insert ( buttons , { {
text = _ ( " Execute all " ) ,
align = " left " ,
font_face = " smallinfofont " ,
font_size = 22 ,
callback = function ( )
UIManager : close ( quickmenu )
Dispatcher : execute ( settings , { qm_show = false } )
end ,
} } )
end
2022-09-19 02:22:41 +00:00
for _ , v in ipairs ( display_list ) do
table.insert ( buttons , { {
text = v.text ,
2023-06-02 15:54:54 +00:00
enabled = Dispatcher : isActionEnabled ( settingsList [ v.key ] ) ,
2022-09-19 02:22:41 +00:00
align = " left " ,
font_face = " smallinfofont " ,
font_size = 22 ,
font_bold = false ,
callback = function ( )
UIManager : close ( quickmenu )
Dispatcher : execute ( { [ v.key ] = settings [ v.key ] } )
2023-11-26 05:52:43 +00:00
if keep_open_on_apply and not util.stringStartsWith ( v.key , " touch_input " ) then
quickmenu : setTitle ( title )
UIManager : show ( quickmenu )
end
2022-09-19 02:22:41 +00:00
end ,
2023-07-28 15:10:35 +00:00
hold_callback = function ( )
if v.key : sub ( 1 , 13 ) == " profile_exec_ " then
UIManager : close ( quickmenu )
UIManager : sendEvent ( Event : new ( settingsList [ v.key ] . event , settingsList [ v.key ] . arg , { qm_show = true } ) )
end
end ,
2022-09-19 02:22:41 +00:00
} } )
end
2023-06-04 12:29:30 +00:00
local ButtonDialog = require ( " ui/widget/buttondialog " )
quickmenu = ButtonDialog : new {
2023-11-26 05:52:43 +00:00
title = title ,
2022-09-19 02:22:41 +00:00
title_align = " center " ,
2023-07-08 05:17:42 +00:00
shrink_unneeded_width = true ,
shrink_min_width = math.floor ( 0.6 * Screen : getWidth ( ) ) ,
2022-09-19 02:22:41 +00:00
use_info_style = false ,
buttons = buttons ,
2023-07-28 15:10:35 +00:00
anchor = exec_props and exec_props.qm_anchor ,
2022-09-19 02:22:41 +00:00
}
UIManager : show ( quickmenu )
2020-06-19 21:38:53 +00:00
end
2020-07-28 01:26:56 +00:00
--[[--
Calls the events in a settings list
arguments are :
2022-11-02 22:20:56 +00:00
1 ) the settings table
2023-07-28 15:10:35 +00:00
2 ) execution management table : { qm_show = true | false } - forcibly show QM / run
{ qm_anchor = ges.pos } - anchor position
{ gesture = ges } - a ` gestures ` object
2020-07-28 01:26:56 +00:00
--]]--
2023-07-28 15:10:35 +00:00
function Dispatcher : execute ( settings , exec_props )
if ( ( exec_props == nil or exec_props.qm_show == nil ) and settings.settings and settings.settings . show_as_quickmenu )
or ( exec_props and exec_props.qm_show ) then
return Dispatcher : _showAsMenu ( settings , exec_props )
2022-09-19 02:22:41 +00:00
end
2022-10-27 12:29:50 +00:00
local has_many = Dispatcher : _itemsCount ( settings ) > 1
2022-10-25 11:16:01 +00:00
if has_many then
UIManager : broadcastEvent ( Event : new ( " BatchedUpdate " ) )
end
2023-07-28 15:10:35 +00:00
local gesture = exec_props and exec_props.gesture
2022-09-19 02:22:41 +00:00
for k , v in iter_func ( settings ) do
if type ( k ) == " number " then
k = v
v = settings [ k ]
end
2023-06-02 15:54:54 +00:00
if Dispatcher : isActionEnabled ( settingsList [ k ] ) then
2021-07-23 11:27:12 +00:00
Notification : setNotifySource ( Notification.SOURCE_DISPATCHER )
2021-08-30 15:01:46 +00:00
if settingsList [ k ] . configurable then
local value = v
if type ( v ) ~= " number " then
for i , r in ipairs ( settingsList [ k ] . args ) do
if v == r then value = settingsList [ k ] . configurable.values [ i ] break end
end
end
UIManager : sendEvent ( Event : new ( " ConfigChange " , settingsList [ k ] . configurable.name , value ) )
end
2023-07-28 15:10:35 +00:00
local category = settingsList [ k ] . category
local event = settingsList [ k ] . event
if category == " none " then
2021-07-23 11:27:12 +00:00
if settingsList [ k ] . arg ~= nil then
2023-07-28 15:10:35 +00:00
UIManager : sendEvent ( Event : new ( event , settingsList [ k ] . arg , exec_props ) )
2021-07-23 11:27:12 +00:00
else
2023-07-28 15:10:35 +00:00
UIManager : sendEvent ( Event : new ( event ) )
2021-05-20 17:23:34 +00:00
end
2023-07-28 15:10:35 +00:00
elseif category == " absolutenumber " or category == " string " then
UIManager : sendEvent ( Event : new ( event , v ) )
elseif category == " arg " then
-- the event can accept a gesture object or an argument
2021-07-23 11:27:12 +00:00
local arg = gesture or settingsList [ k ] . arg
2023-07-28 15:10:35 +00:00
UIManager : sendEvent ( Event : new ( event , arg ) )
elseif category == " incrementalnumber " then
-- the event can accept a gesture object or a number
2021-07-23 11:27:12 +00:00
local arg = v ~= 0 and v or gesture or 0
2023-07-28 15:10:35 +00:00
UIManager : sendEvent ( Event : new ( event , arg ) )
2021-07-23 11:27:12 +00:00
end
2020-06-19 21:38:53 +00:00
end
2021-07-23 11:27:12 +00:00
Notification : resetNotifySource ( )
2020-06-19 21:38:53 +00:00
end
2022-10-25 11:16:01 +00:00
if has_many then
UIManager : broadcastEvent ( Event : new ( " BatchedUpdateDone " ) )
end
2020-06-19 21:38:53 +00:00
end
return Dispatcher