2019-12-06 21:55:39 +00:00
local BD = require ( " ui/bidi " )
2013-10-18 20:38:07 +00:00
local CenterContainer = require ( " ui/widget/container/centercontainer " )
2017-03-28 22:10:36 +00:00
local CloudStorage = require ( " apps/cloudstorage/cloudstorage " )
2014-08-01 04:36:32 +00:00
local ConfirmBox = require ( " ui/widget/confirmbox " )
2017-03-28 22:10:36 +00:00
local Device = require ( " device " )
2019-03-03 11:43:09 +00:00
local Event = require ( " ui/event " )
2020-09-15 18:39:32 +00:00
local FFIUtil = require ( " ffi/util " )
2017-03-28 22:10:36 +00:00
local InputContainer = require ( " ui/widget/container/inputcontainer " )
2018-08-17 18:54:11 +00:00
local PluginLoader = require ( " pluginloader " )
2014-08-11 08:39:08 +00:00
local SetDefaults = require ( " apps/filemanager/filemanagersetdefaults " )
[RFC] Pagination UI shenanigans (#7335)
* Menu/KeyValuePage/ReaderGoTo: Unify the dialogs. (Generally, "Enter page number" as title, and "Go to page" as OK button).
* Allow *tapping* on pagination buttons, too. Added spacers around the text to accommodate for that.
* Disable input handlers when <= 1 pages, while still printing the label in black.
* Always display both the label and the chevrons, even on single page content. (Menu being an exception, because it can handle showing no content at all, in which case we hide the chevrons).
* KVP: Tweak the pagination buttons layout in order to have consistent centering, regardless of whether the return arrow is enabled or not. (Also, match Menu's layout, more or less).
* Menu: Minor layout tweaks to follow the KVP tweaks above. Fixes, among possibly other things, buttons in (non-FM) "List" menus overlapping the final entry (e.g., OPDS), and popout menus with a border being misaligned (e.g., Calibre, Find a file).
* CalendarView: Minor layout tweaks to follow the KVP tweaks. Ensures the pagination buttons are laid out in the same way as everywhere else (they used to be a wee bit higher).
2021-02-25 04:15:23 +00:00
local Size = require ( " ui/size " )
2017-03-28 22:10:36 +00:00
local UIManager = require ( " ui/uimanager " )
local Screen = Device.screen
2017-04-21 09:19:14 +00:00
local dbg = require ( " dbg " )
2019-09-26 21:13:35 +00:00
local lfs = require ( " libs/libkoreader-lfs " )
2017-04-21 09:19:14 +00:00
local logger = require ( " logger " )
2018-07-05 05:40:40 +00:00
local util = require ( " util " )
2017-04-21 09:19:14 +00:00
local _ = require ( " gettext " )
2020-09-15 18:39:32 +00:00
local T = FFIUtil.template
2013-10-18 20:38:07 +00:00
local FileManagerMenu = InputContainer : extend {
2014-03-13 13:52:43 +00:00
tab_item_table = nil ,
2017-02-28 21:46:32 +00:00
menu_items = { } ,
2016-05-02 02:39:31 +00:00
registered_widgets = nil ,
2013-08-14 09:29:05 +00:00
}
function FileManagerMenu : init ( )
2017-03-03 06:41:10 +00:00
self.menu_items = {
[ " KOMenu:menu_buttons " ] = {
-- top menu
} ,
-- items in top menu
2018-04-06 09:32:54 +00:00
filemanager_settings = {
2020-12-19 11:18:30 +00:00
icon = " appbar.filebrowser " ,
2018-04-06 09:32:54 +00:00
} ,
2017-03-03 06:41:10 +00:00
setting = {
2020-12-19 11:18:30 +00:00
icon = " appbar.settings " ,
2017-03-03 06:41:10 +00:00
} ,
tools = {
2020-12-19 11:18:30 +00:00
icon = " appbar.tools " ,
2017-03-03 06:41:10 +00:00
} ,
search = {
2020-12-19 11:18:30 +00:00
icon = " appbar.search " ,
2017-03-03 06:41:10 +00:00
} ,
main = {
2020-12-19 11:18:30 +00:00
icon = " appbar.menu " ,
2017-03-03 06:41:10 +00:00
} ,
2014-03-13 13:52:43 +00:00
}
2017-02-28 21:46:32 +00:00
2014-03-13 13:52:43 +00:00
self.registered_widgets = { }
2014-06-10 07:57:10 +00:00
if Device : hasKeys ( ) then
2014-03-13 13:52:43 +00:00
self.key_events = {
2014-06-05 06:58:53 +00:00
ShowMenu = { { " Menu " } , doc = " show menu " } ,
2014-03-13 13:52:43 +00:00
}
end
2017-08-08 16:20:46 +00:00
self.activation_menu = G_reader_settings : readSetting ( " activate_menu " )
if self.activation_menu == nil then
self.activation_menu = " swipe_tap "
end
2013-08-14 09:29:05 +00:00
end
function FileManagerMenu : initGesListener ( )
2017-04-15 12:45:56 +00:00
if not Device : isTouchDevice ( ) then return end
self : registerTouchZones ( {
2017-06-01 16:32:06 +00:00
{
id = " filemanager_tap " ,
ges = " tap " ,
screen_zone = {
ratio_x = DTAP_ZONE_MENU.x , ratio_y = DTAP_ZONE_MENU.y ,
ratio_w = DTAP_ZONE_MENU.w , ratio_h = DTAP_ZONE_MENU.h ,
} ,
handler = function ( ges ) return self : onTapShowMenu ( ges ) end ,
} ,
2020-12-03 16:33:54 +00:00
{
id = " filemanager_ext_tap " ,
ges = " tap " ,
screen_zone = {
ratio_x = DTAP_ZONE_MENU_EXT.x , ratio_y = DTAP_ZONE_MENU_EXT.y ,
ratio_w = DTAP_ZONE_MENU_EXT.w , ratio_h = DTAP_ZONE_MENU_EXT.h ,
} ,
overrides = {
" filemanager_tap " ,
} ,
handler = function ( ges ) return self : onTapShowMenu ( ges ) end ,
} ,
2017-04-15 12:45:56 +00:00
{
id = " filemanager_swipe " ,
ges = " swipe " ,
screen_zone = {
ratio_x = DTAP_ZONE_MENU.x , ratio_y = DTAP_ZONE_MENU.y ,
ratio_w = DTAP_ZONE_MENU.w , ratio_h = DTAP_ZONE_MENU.h ,
} ,
2019-03-30 20:05:44 +00:00
overrides = {
" rolling_swipe " ,
" paging_swipe " ,
} ,
2017-04-15 12:45:56 +00:00
handler = function ( ges ) return self : onSwipeShowMenu ( ges ) end ,
2014-03-13 13:52:43 +00:00
} ,
2020-12-03 16:33:54 +00:00
{
id = " filemanager_ext_swipe " ,
ges = " swipe " ,
screen_zone = {
ratio_x = DTAP_ZONE_MENU_EXT.x , ratio_y = DTAP_ZONE_MENU_EXT.y ,
ratio_w = DTAP_ZONE_MENU_EXT.w , ratio_h = DTAP_ZONE_MENU_EXT.h ,
} ,
overrides = {
" filemanager_swipe " ,
} ,
handler = function ( ges ) return self : onSwipeShowMenu ( ges ) end ,
} ,
2017-04-15 12:45:56 +00:00
} )
2013-08-14 09:29:05 +00:00
end
2020-07-12 18:47:49 +00:00
function FileManagerMenu : onOpenLastDoc ( )
2018-05-23 20:25:33 +00:00
local last_file = G_reader_settings : readSetting ( " lastfile " )
if not last_file or lfs.attributes ( last_file , " mode " ) ~= " file " then
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " Cannot open last document " ) ,
} )
return
end
2019-02-22 15:29:19 +00:00
ReaderUI: Saner FM/RD lifecycle
* Ensure that going from one to the other tears down the former and
its plugins before instantiating the latter and its plugins.
UIManager: Unify Event sending & broadcasting
* Make the two behave the same way (walk the widget stack from top to
bottom), and properly handle the window stack shrinking shrinking
*and* growing.
Previously, broadcasting happened bottom-to-top and didn't really
handle the list shrinking/growing, while sending only handled the list
shrinking by a single element, and hopefully that element being the one
the event was just sent to.
These two items combined allowed us to optimize suboptimal
refresh behavior with Menu and other Menu classes when
opening/closing a document.
e.g., the "opening document" Notification is now properly regional,
and the "open last doc" option no longer flashes like a crazy person
anymore.
Plugins: Allow optimizing Menu refresh with custom menus, too.
Requires moving Menu's close_callback *after* onMenuSelect, which, eh,
probably makes sense, and is probably harmless in the grand scheme of
things.
2021-05-01 16:53:04 +00:00
-- Only close menu if we were called from the menu
2019-02-22 15:29:19 +00:00
if self.menu_container then
ReaderUI: Saner FM/RD lifecycle
* Ensure that going from one to the other tears down the former and
its plugins before instantiating the latter and its plugins.
UIManager: Unify Event sending & broadcasting
* Make the two behave the same way (walk the widget stack from top to
bottom), and properly handle the window stack shrinking shrinking
*and* growing.
Previously, broadcasting happened bottom-to-top and didn't really
handle the list shrinking/growing, while sending only handled the list
shrinking by a single element, and hopefully that element being the one
the event was just sent to.
These two items combined allowed us to optimize suboptimal
refresh behavior with Menu and other Menu classes when
opening/closing a document.
e.g., the "opening document" Notification is now properly regional,
and the "open last doc" option no longer flashes like a crazy person
anymore.
Plugins: Allow optimizing Menu refresh with custom menus, too.
Requires moving Menu's close_callback *after* onMenuSelect, which, eh,
probably makes sense, and is probably harmless in the grand scheme of
things.
2021-05-01 16:53:04 +00:00
-- Mimic's FileManager's onShowingReader refresh optimizations
self.ui . tearing_down = true
self.ui . dithered = nil
2019-02-22 15:29:19 +00:00
self : onCloseFileManagerMenu ( )
end
ReaderUI: Saner FM/RD lifecycle
* Ensure that going from one to the other tears down the former and
its plugins before instantiating the latter and its plugins.
UIManager: Unify Event sending & broadcasting
* Make the two behave the same way (walk the widget stack from top to
bottom), and properly handle the window stack shrinking shrinking
*and* growing.
Previously, broadcasting happened bottom-to-top and didn't really
handle the list shrinking/growing, while sending only handled the list
shrinking by a single element, and hopefully that element being the one
the event was just sent to.
These two items combined allowed us to optimize suboptimal
refresh behavior with Menu and other Menu classes when
opening/closing a document.
e.g., the "opening document" Notification is now properly regional,
and the "open last doc" option no longer flashes like a crazy person
anymore.
Plugins: Allow optimizing Menu refresh with custom menus, too.
Requires moving Menu's close_callback *after* onMenuSelect, which, eh,
probably makes sense, and is probably harmless in the grand scheme of
things.
2021-05-01 16:53:04 +00:00
local ReaderUI = require ( " apps/reader/readerui " )
ReaderUI : showReader ( last_file )
2018-05-23 20:25:33 +00:00
end
2013-08-14 09:29:05 +00:00
function FileManagerMenu : setUpdateItemTable ( )
2014-03-13 13:52:43 +00:00
2014-07-27 13:41:38 +00:00
-- setting tab
2021-02-09 11:41:17 +00:00
self.menu_items . filebrowser_settings = {
text = _ ( " Settings " ) ,
2019-07-28 06:37:43 +00:00
sub_item_table = {
2021-02-09 11:41:17 +00:00
{
text = _ ( " Show hidden files " ) ,
checked_func = function ( ) return self.ui . file_chooser.show_hidden end ,
callback = function ( ) self.ui : toggleHiddenFiles ( ) end ,
} ,
{
text = _ ( " Show unsupported files " ) ,
checked_func = function ( ) return self.ui . file_chooser.show_unsupported end ,
callback = function ( ) self.ui : toggleUnsupportedFiles ( ) end ,
separator = true ,
} ,
2019-07-28 06:37:43 +00:00
{
2021-07-23 13:47:02 +00:00
text = _ ( " Classic mode settings " ) ,
sub_item_table = {
{
text = _ ( " Items per page " ) ,
help_text = _ ( [ [ This sets the number of items per page in :
2021-02-04 16:43:52 +00:00
- File browser , history and favorites in ' classic ' display mode
- Search results and folder shortcuts
2021-07-23 13:47:02 +00:00
- File and folder selection
2021-02-04 16:43:52 +00:00
- Calibre and OPDS browsers / search results ] ] ) ,
2021-07-23 13:47:02 +00:00
callback = function ( )
local SpinWidget = require ( " ui/widget/spinwidget " )
local Menu = require ( " ui/widget/menu " )
local default_perpage = Menu.items_per_page_default
local curr_perpage = G_reader_settings : readSetting ( " items_per_page " ) or default_perpage
local items = SpinWidget : new {
value = curr_perpage ,
value_min = 6 ,
value_max = 24 ,
default_value = default_perpage ,
title_text = _ ( " Items per page " ) ,
keep_shown_on_apply = true ,
callback = function ( spin )
G_reader_settings : saveSetting ( " items_per_page " , spin.value )
self.ui : onRefresh ( )
end
}
UIManager : show ( items )
end ,
} ,
{
text = _ ( " Item font size " ) ,
callback = function ( )
local SpinWidget = require ( " ui/widget/spinwidget " )
local Menu = require ( " ui/widget/menu " )
local curr_perpage = G_reader_settings : readSetting ( " items_per_page " ) or Menu.items_per_page_default
local default_font_size = Menu.getItemFontSize ( curr_perpage )
local curr_font_size = G_reader_settings : readSetting ( " items_font_size " ) or default_font_size
local items_font = SpinWidget : new {
value = curr_font_size ,
value_min = 10 ,
value_max = 72 ,
default_value = default_font_size ,
keep_shown_on_apply = true ,
title_text = _ ( " Item font size " ) ,
callback = function ( spin )
if spin.value == default_font_size then
-- We can't know if the user has set a size or hit "Use default", but
-- assume that if it is the default font size, he will prefer to have
-- our default font size if he later updates per-page
G_reader_settings : delSetting ( " items_font_size " )
else
G_reader_settings : saveSetting ( " items_font_size " , spin.value )
end
self.ui : onRefresh ( )
end
}
UIManager : show ( items_font )
end ,
} ,
{
text = _ ( " Shrink item font size to fit more text " ) ,
checked_func = function ( )
return G_reader_settings : isTrue ( " items_multilines_show_more_text " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " items_multilines_show_more_text " )
2019-07-28 06:37:43 +00:00
self.ui : onRefresh ( )
2021-07-23 13:47:02 +00:00
end ,
separator = true ,
} ,
{
text = _ ( " Show opened files in bold " ) ,
checked_func = function ( )
return G_reader_settings : readSetting ( " show_file_in_bold " ) == " opened "
end ,
callback = function ( )
if G_reader_settings : readSetting ( " show_file_in_bold " ) == " opened " then
G_reader_settings : saveSetting ( " show_file_in_bold " , false )
2021-02-04 16:43:52 +00:00
else
2021-07-23 13:47:02 +00:00
G_reader_settings : saveSetting ( " show_file_in_bold " , " opened " )
2021-02-04 16:43:52 +00:00
end
2019-07-28 06:37:43 +00:00
self.ui : onRefresh ( )
2021-07-23 13:47:02 +00:00
end ,
} ,
{
text = _ ( " Show new (not yet opened) files in bold " ) ,
checked_func = function ( )
return G_reader_settings : hasNot ( " show_file_in_bold " )
end ,
callback = function ( )
if G_reader_settings : hasNot ( " show_file_in_bold " ) then
G_reader_settings : saveSetting ( " show_file_in_bold " , false )
else
G_reader_settings : delSetting ( " show_file_in_bold " )
end
self.ui : onRefresh ( )
end ,
} ,
} ,
2021-02-09 11:41:17 +00:00
} ,
{
2021-07-23 13:47:02 +00:00
text = _ ( " History settings " ) ,
2021-02-09 11:41:17 +00:00
sub_item_table = {
{
2021-07-23 13:47:02 +00:00
text = _ ( " Clear history of deleted files " ) ,
2021-02-09 11:41:17 +00:00
callback = function ( )
2021-07-23 13:47:02 +00:00
UIManager : show ( ConfirmBox : new {
text = _ ( " Clear history of deleted files? " ) ,
ok_text = _ ( " Clear " ) ,
ok_callback = function ( )
require ( " readhistory " ) : clearMissing ( )
end ,
} )
2021-02-09 11:41:17 +00:00
end ,
} ,
{
2021-07-23 13:47:02 +00:00
text = _ ( " Auto-remove deleted or purged items from history " ) ,
checked_func = function ( )
return G_reader_settings : isTrue ( " autoremove_deleted_items_from_history " )
end ,
2021-02-09 11:41:17 +00:00
callback = function ( )
2021-07-23 13:47:02 +00:00
G_reader_settings : flipNilOrFalse ( " autoremove_deleted_items_from_history " )
2021-02-09 11:41:17 +00:00
end ,
2021-07-23 13:47:02 +00:00
separator = true ,
2021-02-09 11:41:17 +00:00
} ,
{
2021-07-23 13:47:02 +00:00
text = _ ( " Show filename in Open last/previous menu items " ) ,
2021-02-09 11:41:17 +00:00
checked_func = function ( )
2021-07-23 13:47:02 +00:00
return G_reader_settings : isTrue ( " open_last_menu_show_filename " )
2021-02-09 11:41:17 +00:00
end ,
callback = function ( )
2021-07-23 13:47:02 +00:00
G_reader_settings : flipNilOrFalse ( " open_last_menu_show_filename " )
2021-02-09 11:41:17 +00:00
end ,
} ,
} ,
} ,
{
2021-07-23 13:47:02 +00:00
text = _ ( " Home folder settings " ) ,
sub_item_table = {
{
text = _ ( " Set home folder " ) ,
callback = function ( )
local text
local home_dir = G_reader_settings : readSetting ( " home_dir " )
if home_dir then
text = T ( _ ( " Home folder is set to: \n %1 " ) , home_dir )
else
text = _ ( " Home folder is not set. " )
home_dir = Device.home_dir
end
UIManager : show ( ConfirmBox : new {
text = text .. " \n Choose new folder to set as home? " ,
ok_text = _ ( " Choose folder " ) ,
ok_callback = function ( )
local path_chooser = require ( " ui/widget/pathchooser " ) : new {
select_file = false ,
show_files = false ,
path = home_dir ,
onConfirm = function ( new_path )
G_reader_settings : saveSetting ( " home_dir " , new_path )
end
}
UIManager : show ( path_chooser )
end ,
} )
end ,
} ,
{
text = _ ( " Shorten home folder " ) ,
checked_func = function ( )
return G_reader_settings : nilOrTrue ( " shorten_home_dir " )
end ,
callback = function ( )
G_reader_settings : flipNilOrTrue ( " shorten_home_dir " )
local FileManager = require ( " apps/filemanager/filemanager " )
if FileManager.instance then FileManager.instance : reinit ( ) end
end ,
help_text = _ ( [ [
2021-03-02 09:33:05 +00:00
" Shorten home folder " will display the home folder itself as " Home " instead of its full path .
Assuming the home folder is :
` / mnt / onboard / . books `
A subfolder will be shortened from :
` / mnt / onboard / . books / Manga / Cells at Work `
To :
` Manga / Cells at Work ` . ] ] ) ,
2021-07-23 13:47:02 +00:00
} ,
{
text = _ ( " Lock home folder " ) ,
enabled_func = function ( )
return G_reader_settings : has ( " home_dir " )
end ,
checked_func = function ( )
return G_reader_settings : isTrue ( " lock_home_folder " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " lock_home_folder " )
self.ui : onRefresh ( )
end ,
} ,
} ,
2021-02-20 19:15:43 +00:00
separator = true ,
} ,
{
text = _ ( " Info lists items per page " ) ,
help_text = _ ( [ [ This sets the number of items per page in :
- Book information
- Dictionary and Wikipedia lookup history
- Reading statistics details
- A few other plugins ] ] ) ,
keep_menu_open = true ,
callback = function ( )
local SpinWidget = require ( " ui/widget/spinwidget " )
local KeyValuePage = require ( " ui/widget/keyvaluepage " )
local default_perpage = KeyValuePage : getDefaultKeyValuesPerPage ( )
local curr_perpage = G_reader_settings : readSetting ( " keyvalues_per_page " ) or default_perpage
local items = SpinWidget : new {
value = curr_perpage ,
value_min = 10 ,
value_max = 24 ,
default_value = default_perpage ,
title_text = _ ( " Info lists items per page " ) ,
callback = function ( spin )
if spin.value == default_perpage then
-- We can't know if the user has set a value or hit "Use default", but
-- assume that if it is the default, he will prefer to stay with our
-- default if he later changes screen DPI
G_reader_settings : delSetting ( " keyvalues_per_page " )
else
G_reader_settings : saveSetting ( " keyvalues_per_page " , spin.value )
end
end
}
UIManager : show ( items )
end ,
2021-02-09 11:41:17 +00:00
} ,
2019-07-28 06:37:43 +00:00
}
2018-01-13 22:38:53 +00:00
}
2021-07-23 13:47:02 +00:00
for _ , widget in pairs ( self.registered_widgets ) do
local ok , err = pcall ( widget.addToMainMenu , widget , self.menu_items )
if not ok then
logger.err ( " failed to register widget " , widget.name , err )
end
end
2017-03-03 06:41:10 +00:00
self.menu_items . sort_by = self.ui : getSortingMenuTable ( )
self.menu_items . reverse_sorting = {
2014-10-30 14:41:49 +00:00
text = _ ( " Reverse sorting " ) ,
checked_func = function ( ) return self.ui . file_chooser.reverse_collate end ,
callback = function ( ) self.ui : toggleReverseCollate ( ) end
2017-02-28 21:46:32 +00:00
}
2017-08-14 11:15:12 +00:00
self.menu_items . start_with = self.ui : getStartWithMenuTable ( )
2017-04-13 17:55:31 +00:00
if Device : supportsScreensaver ( ) then
2017-03-03 06:41:10 +00:00
self.menu_items . screensaver = {
2016-08-01 01:26:26 +00:00
text = _ ( " Screensaver " ) ,
2017-12-17 17:27:24 +00:00
sub_item_table = require ( " ui/elements/screensaver_menu " ) ,
2017-02-28 21:46:32 +00:00
}
2016-08-01 01:26:26 +00:00
end
2014-11-21 14:41:14 +00:00
-- insert common settings
2019-03-02 20:45:12 +00:00
for id , common_setting in pairs ( dofile ( " frontend/ui/elements/common_settings_menu_table.lua " ) ) do
2017-02-28 21:46:32 +00:00
self.menu_items [ id ] = common_setting
2014-03-13 13:52:43 +00:00
end
2014-11-21 14:41:14 +00:00
2014-08-11 14:14:15 +00:00
-- tools tab
2017-03-03 06:41:10 +00:00
self.menu_items . advanced_settings = {
2014-11-26 17:16:54 +00:00
text = _ ( " Advanced settings " ) ,
2014-08-11 14:14:15 +00:00
callback = function ( )
SetDefaults : ConfirmEdit ( )
end ,
hold_callback = function ( )
SetDefaults : ConfirmSave ( )
end ,
2017-02-28 21:46:32 +00:00
}
2018-08-17 18:54:11 +00:00
self.menu_items . plugin_management = {
text = _ ( " Plugin management " ) ,
sub_item_table = PluginLoader : genPluginManagerSubItem ( )
}
2017-03-03 06:41:10 +00:00
self.menu_items . developer_options = {
2016-12-03 13:30:08 +00:00
text = _ ( " Developer options " ) ,
sub_item_table = {
{
2021-04-09 16:30:51 +00:00
text = _ ( " Clear caches " ) ,
2016-12-03 13:30:08 +00:00
callback = function ( )
UIManager : show ( ConfirmBox : new {
2021-04-09 16:30:51 +00:00
text = _ ( " Clear the cache folder? " ) ,
2016-12-03 13:30:08 +00:00
ok_callback = function ( )
local DataStorage = require ( " datastorage " )
local cachedir = DataStorage : getDataDir ( ) .. " /cache "
if lfs.attributes ( cachedir , " mode " ) == " directory " then
2020-09-15 18:39:32 +00:00
FFIUtil.purgeDir ( cachedir )
2016-12-03 13:30:08 +00:00
end
lfs.mkdir ( cachedir )
2021-04-09 16:30:51 +00:00
-- Also remove from the Cache objet references to the cache files we've just deleted
2016-12-12 22:37:48 +00:00
local Cache = require ( " cache " )
Cache.cached = { }
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
2021-04-09 16:30:51 +00:00
text = _ ( " Caches cleared. Please restart KOReader. " ) ,
2016-12-12 22:37:48 +00:00
} )
2016-12-03 13:30:08 +00:00
end ,
} )
end ,
} ,
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
{
text = _ ( " Enable debug logging " ) ,
checked_func = function ( )
return G_reader_settings : isTrue ( " debug " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " debug " )
if G_reader_settings : isTrue ( " debug " ) then
dbg : turnOn ( )
else
dbg : setVerbose ( false )
dbg : turnOff ( )
2021-03-06 21:44:18 +00:00
G_reader_settings : makeFalse ( " debug_verbose " )
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
end
end ,
} ,
{
text = _ ( " Enable verbose debug logging " ) ,
enabled_func = function ( )
return G_reader_settings : isTrue ( " debug " )
end ,
checked_func = function ( )
return G_reader_settings : isTrue ( " debug_verbose " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " debug_verbose " )
if G_reader_settings : isTrue ( " debug_verbose " ) then
dbg : setVerbose ( true )
else
dbg : setVerbose ( false )
end
end ,
} ,
2016-12-03 13:30:08 +00:00
}
2017-02-28 21:46:32 +00:00
}
2021-07-21 16:12:58 +00:00
if Device : isKobo ( ) and not Device : isSunxi ( ) then
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
table.insert ( self.menu_items . developer_options.sub_item_table , {
2019-04-08 21:05:08 +00:00
text = _ ( " Disable forced 8-bit pixel depth " ) ,
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
checked_func = function ( )
return G_reader_settings : isTrue ( " dev_startup_no_fbdepth " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " dev_startup_no_fbdepth " )
2019-03-29 19:12:09 +00:00
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end ,
} )
end
2021-03-21 09:56:21 +00:00
--- @note Currently, only Kobo, rM & PB have a fancy crash display (#5328)
if Device : isKobo ( ) or Device : isRemarkable ( ) or Device : isPocketBook ( ) then
2019-09-07 01:19:18 +00:00
table.insert ( self.menu_items . developer_options.sub_item_table , {
text = _ ( " Always abort on crash " ) ,
checked_func = function ( )
return G_reader_settings : isTrue ( " dev_abort_on_crash " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " dev_abort_on_crash " )
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end ,
} )
end
2021-01-02 02:00:39 +00:00
if not Device.should_restrict_JIT then
2020-09-22 21:26:05 +00:00
local Blitbuffer = require ( " ffi/blitbuffer " )
2019-03-29 19:12:09 +00:00
table.insert ( self.menu_items . developer_options.sub_item_table , {
text = _ ( " Disable C blitter " ) ,
enabled_func = function ( )
2020-09-22 21:26:05 +00:00
return Blitbuffer.has_cblitbuffer
2019-03-29 19:12:09 +00:00
end ,
checked_func = function ( )
return G_reader_settings : isTrue ( " dev_no_c_blitter " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " dev_no_c_blitter " )
2020-09-22 21:26:05 +00:00
Blitbuffer : enableCBB ( G_reader_settings : nilOrFalse ( " dev_no_c_blitter " ) )
[feat, Kobo] On Kobo, drop fb to 8bpp on startup (#4637)
* The Great 8bpp Experiment
Swap to 8bpp on Kobo, because we're 'effing grayscale, for pete's sake!
* Always swap to 8bpp, no matter the launch method.
Because it turned out that, even when restarting Nickel, we had to
restore the expected bitdepth ourselves, because pickel/Nickel didn't do
the job completely.
(I'm going to guess the grayscale flag wasn't getting flipped properly).
* Dither every non-transparent icon to the eInk palette
* Make sure hasBGRFrameBuffer is only enabled when the Kobo fb actually is
@ 32bpp...
* Re-process badly grayscaled icons
* And re-grayscale that one w/ gamma correction so the squares show up
better.
* Allow the fbdepth switch to be disabled (in Developer settings).
Also, allow setting debug mode that way.
Also, forcibly disable verbose logging when disabling debug.
* Update setting name to piggyback on the existing check in reader.lua
* Update icons postprocessing info
2019-03-03 11:31:55 +00:00
end ,
} )
end
2019-04-18 21:26:53 +00:00
if Device : hasEinkScreen ( ) and Device : canHWDither ( ) then
table.insert ( self.menu_items . developer_options.sub_item_table , {
text = _ ( " Disable HW dithering " ) ,
checked_func = function ( )
return not Device.screen . hw_dithering
end ,
callback = function ( )
Device.screen : toggleHWDithering ( )
2020-07-23 04:01:46 +00:00
G_reader_settings : saveSetting ( " dev_no_hw_dither " , not Device.screen . hw_dithering )
2019-04-18 21:26:53 +00:00
-- Make sure SW dithering gets disabled when we enable HW dithering
if Device.screen . hw_dithering and Device.screen . sw_dithering then
2021-03-06 21:44:18 +00:00
G_reader_settings : makeTrue ( " dev_no_sw_dither " )
2020-07-23 04:01:46 +00:00
Device.screen : toggleSWDithering ( false )
2019-04-18 21:26:53 +00:00
end
UIManager : setDirty ( " all " , " full " )
end ,
} )
end
if Device : hasEinkScreen ( ) then
table.insert ( self.menu_items . developer_options.sub_item_table , {
text = _ ( " Disable SW dithering " ) ,
enabled_func = function ( )
return Device.screen . fb_bpp == 8
end ,
checked_func = function ( )
return not Device.screen . sw_dithering
end ,
callback = function ( )
Device.screen : toggleSWDithering ( )
2020-07-23 04:01:46 +00:00
G_reader_settings : saveSetting ( " dev_no_sw_dither " , not Device.screen . sw_dithering )
2019-04-18 21:26:53 +00:00
-- Make sure HW dithering gets disabled when we enable SW dithering
if Device.screen . hw_dithering and Device.screen . sw_dithering then
2021-03-06 21:44:18 +00:00
G_reader_settings : makeTrue ( " dev_no_hw_dither " )
2020-07-23 04:01:46 +00:00
Device.screen : toggleHWDithering ( false )
2019-04-18 21:26:53 +00:00
end
UIManager : setDirty ( " all " , " full " )
end ,
} )
end
2021-03-21 09:56:21 +00:00
--- @note: Currently, only Kobo implements this quirk
if Device : hasEinkScreen ( ) and Device : isKobo ( ) then
table.insert ( self.menu_items . developer_options.sub_item_table , {
-- @translators Highly technical (ioctl is a Linux API call, the uppercase stuff is a constant). What's translatable is essentially only the action ("bypass") and the article.
2021-07-21 16:12:58 +00:00
text = _ ( " Bypass the WAIT_FOR ioctls " ) ,
2021-03-21 09:56:21 +00:00
checked_func = function ( )
local mxcfb_bypass_wait_for
if G_reader_settings : has ( " mxcfb_bypass_wait_for " ) then
mxcfb_bypass_wait_for = G_reader_settings : isTrue ( " mxcfb_bypass_wait_for " )
else
mxcfb_bypass_wait_for = not Device : hasReliableMxcWaitFor ( )
end
return mxcfb_bypass_wait_for
end ,
callback = function ( )
local mxcfb_bypass_wait_for
if G_reader_settings : has ( " mxcfb_bypass_wait_for " ) then
mxcfb_bypass_wait_for = G_reader_settings : isTrue ( " mxcfb_bypass_wait_for " )
else
mxcfb_bypass_wait_for = not Device : hasReliableMxcWaitFor ( )
end
G_reader_settings : saveSetting ( " mxcfb_bypass_wait_for " , not mxcfb_bypass_wait_for )
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end ,
} )
end
2021-05-15 15:44:30 +00:00
--- @note: Intended to debug/investigate B288 quirks on PocketBook devices
if Device : hasEinkScreen ( ) and Device : isPocketBook ( ) then
table.insert ( self.menu_items . developer_options.sub_item_table , {
-- @translators B288 is the codename of the CPU/chipset (SoC stands for 'System on Chip').
text = _ ( " Ignore feature bans on B288 SoCs " ) ,
enabled_func = function ( )
return Device : isB288SoC ( )
end ,
checked_func = function ( )
return G_reader_settings : isTrue ( " pb_ignore_b288_quirks " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " pb_ignore_b288_quirks " )
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end ,
} )
end
2020-01-04 19:53:49 +00:00
if Device : isAndroid ( ) then
table.insert ( self.menu_items . developer_options.sub_item_table , {
text = _ ( " Start E-ink test " ) ,
callback = function ( )
Device : epdTest ( )
end ,
} )
end
2019-11-15 14:14:38 +00:00
table.insert ( self.menu_items . developer_options.sub_item_table , {
text = _ ( " Disable enhanced UI text shaping (xtext) " ) ,
checked_func = function ( )
return G_reader_settings : isFalse ( " use_xtext " )
end ,
callback = function ( )
G_reader_settings : flipNilOrTrue ( " use_xtext " )
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end ,
} )
2019-12-06 21:55:33 +00:00
table.insert ( self.menu_items . developer_options.sub_item_table , {
2021-02-20 19:15:43 +00:00
text = _ ( " UI layout mirroring and text direction " ) ,
2019-12-06 21:55:33 +00:00
sub_item_table = {
{
text = _ ( " Reverse UI layout mirroring " ) ,
checked_func = function ( )
return G_reader_settings : isTrue ( " dev_reverse_ui_layout_mirroring " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " dev_reverse_ui_layout_mirroring " )
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end
} ,
{
text = _ ( " Reverse UI text direction " ) ,
checked_func = function ( )
return G_reader_settings : isTrue ( " dev_reverse_ui_text_direction " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " dev_reverse_ui_text_direction " )
local InfoMessage = require ( " ui/widget/infomessage " )
UIManager : show ( InfoMessage : new {
text = _ ( " This will take effect on next restart. " ) ,
} )
end
}
}
} )
2020-01-16 11:48:34 +00:00
table.insert ( self.menu_items . developer_options.sub_item_table , {
text_func = function ( )
2020-01-30 11:25:50 +00:00
if G_reader_settings : nilOrTrue ( " use_cre_call_cache " )
2020-01-16 11:48:34 +00:00
and G_reader_settings : isTrue ( " use_cre_call_cache_log_stats " ) then
return _ ( " Enable CRE call cache (with stats) " )
end
return _ ( " Enable CRE call cache " )
end ,
checked_func = function ( )
2020-01-30 11:25:50 +00:00
return G_reader_settings : nilOrTrue ( " use_cre_call_cache " )
2020-01-16 11:48:34 +00:00
end ,
callback = function ( )
2020-01-30 11:25:50 +00:00
G_reader_settings : flipNilOrTrue ( " use_cre_call_cache " )
2020-01-16 11:48:34 +00:00
-- No need to show "This will take effect on next CRE book opening."
-- as this menu is only accessible from file browser
end ,
hold_callback = function ( touchmenu_instance )
G_reader_settings : flipNilOrFalse ( " use_cre_call_cache_log_stats " )
touchmenu_instance : updateItems ( )
end ,
} )
2019-11-15 14:14:38 +00:00
2017-03-03 06:41:10 +00:00
self.menu_items . cloud_storage = {
2016-12-20 07:34:00 +00:00
text = _ ( " Cloud storage " ) ,
callback = function ( )
local cloud_storage = CloudStorage : new { }
UIManager : show ( cloud_storage )
local filemanagerRefresh = function ( ) self.ui : onRefresh ( ) end
function cloud_storage : onClose ( )
filemanagerRefresh ( )
UIManager : close ( cloud_storage )
end
end ,
2017-02-28 21:46:32 +00:00
}
2014-11-26 17:16:54 +00:00
2017-03-03 06:41:10 +00:00
self.menu_items . find_file = {
2019-08-24 07:25:38 +00:00
-- @translators Search for files by name.
2021-04-02 15:59:29 +00:00
text = _ ( " File search " ) ,
help_text = _ ( [ [ Search a book by filename in the current or home folder and its subfolders .
2021-07-15 10:53:28 +00:00
Wildcards for one ' ? ' or more ' * ' characters can be used .
2021-04-02 15:59:29 +00:00
A search for ' * ' will show all files .
2021-07-18 18:21:39 +00:00
The sorting order is the same as in filemanager .
2021-04-02 15:59:29 +00:00
Tap a book in the search results to open it . ] ] ) ,
2014-11-26 17:16:54 +00:00
callback = function ( )
2020-07-12 18:47:49 +00:00
self.ui : handleEvent ( Event : new ( " ShowFileSearch " ) )
2014-08-07 07:14:30 +00:00
end
2017-02-28 21:46:32 +00:00
}
2014-11-26 17:16:54 +00:00
2017-02-25 10:58:39 +00:00
-- main menu tab
2017-03-03 06:41:10 +00:00
self.menu_items . open_last_document = {
2018-07-05 05:40:40 +00:00
text_func = function ( )
2021-03-06 21:44:18 +00:00
if not G_reader_settings : isTrue ( " open_last_menu_show_filename " ) or G_reader_settings : hasNot ( " lastfile " ) then
2018-07-05 05:40:40 +00:00
return _ ( " Open last document " )
end
local last_file = G_reader_settings : readSetting ( " lastfile " )
2021-03-06 21:44:18 +00:00
local path , file_name = util.splitFilePathName ( last_file ) -- luacheck: no unused
2020-01-04 00:18:51 +00:00
return T ( _ ( " Last: %1 " ) , BD.filename ( file_name ) )
2018-07-05 05:40:40 +00:00
end ,
2017-03-05 11:39:38 +00:00
enabled_func = function ( )
2021-03-06 21:44:18 +00:00
return G_reader_settings : has ( " lastfile " )
2017-03-05 11:39:38 +00:00
end ,
2014-08-16 20:32:34 +00:00
callback = function ( )
2020-07-12 18:47:49 +00:00
self : onOpenLastDoc ( )
2018-05-23 20:25:33 +00:00
end ,
hold_callback = function ( )
2017-02-25 10:58:39 +00:00
local last_file = G_reader_settings : readSetting ( " lastfile " )
2018-05-23 20:25:33 +00:00
UIManager : show ( ConfirmBox : new {
2020-01-04 00:18:51 +00:00
text = T ( _ ( " Would you like to open the last document: %1? " ) , BD.filepath ( last_file ) ) ,
2018-05-23 20:25:33 +00:00
ok_text = _ ( " OK " ) ,
ok_callback = function ( )
2020-07-12 18:47:49 +00:00
self : onOpenLastDoc ( )
2018-05-23 20:25:33 +00:00
end ,
} )
2014-08-16 20:32:34 +00:00
end
2017-02-28 21:46:32 +00:00
}
-- insert common info
2019-03-02 20:45:12 +00:00
for id , common_setting in pairs ( dofile ( " frontend/ui/elements/common_info_menu_table.lua " ) ) do
2017-02-28 21:46:32 +00:00
self.menu_items [ id ] = common_setting
2017-02-25 10:58:39 +00:00
end
2017-09-03 13:40:50 +00:00
self.menu_items . exit_menu = {
text = _ ( " Exit " ) ,
hold_callback = function ( )
self : exitOrRestart ( )
end ,
}
2017-03-03 06:41:10 +00:00
self.menu_items . exit = {
2017-02-25 10:58:39 +00:00
text = _ ( " Exit " ) ,
callback = function ( )
2017-05-16 09:11:11 +00:00
self : exitOrRestart ( )
end ,
}
self.menu_items . restart_koreader = {
text = _ ( " Restart KOReader " ) ,
callback = function ( )
2019-09-26 21:13:35 +00:00
self : exitOrRestart ( function ( )
UIManager : restartKOReader ( )
end )
2017-02-25 10:58:39 +00:00
end ,
2017-02-28 21:46:32 +00:00
}
2019-08-15 12:49:15 +00:00
if not Device : canRestart ( ) then
2019-01-21 21:44:13 +00:00
self.menu_items . exit_menu = self.menu_items . exit
self.menu_items . exit = nil
self.menu_items . restart_koreader = nil
end
2018-03-26 17:41:50 +00:00
if not Device : isTouchDevice ( ) then
2020-12-19 11:18:30 +00:00
-- add a shortcut on non touch-device
-- because this menu is not accessible otherwise
2018-03-26 17:41:50 +00:00
self.menu_items . plus_menu = {
2020-12-19 11:18:30 +00:00
icon = " plus " ,
2018-03-26 17:41:50 +00:00
remember = false ,
callback = function ( )
self : onCloseFileManagerMenu ( )
self.ui : tapPlus ( )
end ,
}
end
2017-02-28 21:46:32 +00:00
2017-03-05 11:46:27 +00:00
local order = require ( " ui/elements/filemanager_menu_order " )
2017-02-28 21:46:32 +00:00
2017-04-14 18:12:21 +00:00
local MenuSorter = require ( " ui/menusorter " )
2017-03-24 20:15:35 +00:00
self.tab_item_table = MenuSorter : mergeAndSort ( " filemanager " , self.menu_items , order )
2013-08-14 09:29:05 +00:00
end
2017-04-21 09:19:14 +00:00
dbg : guard ( FileManagerMenu , ' setUpdateItemTable ' ,
function ( self )
local mock_menu_items = { }
for _ , widget in pairs ( self.registered_widgets ) do
-- make sure addToMainMenu works in debug mode
widget : addToMainMenu ( mock_menu_items )
end
end )
2013-08-14 09:29:05 +00:00
2020-11-28 21:48:09 +00:00
function FileManagerMenu : exitOrRestart ( callback , force )
2019-09-26 21:13:35 +00:00
UIManager : close ( self.menu_container )
2020-11-28 21:48:09 +00:00
-- Only restart sets a callback, which suits us just fine for this check ;)
if callback and not force and not Device : isStartupScriptUpToDate ( ) then
UIManager : show ( ConfirmBox : new {
text = _ ( " KOReader's startup script has been updated. You'll need to completely exit KOReader to finalize the update. " ) ,
ok_text = _ ( " Restart anyway " ) ,
ok_callback = function ( )
self : exitOrRestart ( callback , true )
end ,
} )
return
end
2019-09-26 21:13:35 +00:00
self.ui : onClose ( )
if callback then
callback ( )
2017-05-16 09:11:11 +00:00
end
end
2018-03-22 15:04:42 +00:00
function FileManagerMenu : onShowMenu ( tab_index )
2017-03-05 11:46:27 +00:00
if self.tab_item_table == nil then
2014-03-13 13:52:43 +00:00
self : setUpdateItemTable ( )
end
2018-03-22 15:04:42 +00:00
if not tab_index then
tab_index = G_reader_settings : readSetting ( " filemanagermenu_tab_index " ) or 1
end
2014-03-13 13:52:43 +00:00
local menu_container = CenterContainer : new {
ignore = " height " ,
dimen = Screen : getSize ( ) ,
}
2015-04-27 00:49:27 +00:00
local main_menu
2018-03-14 21:16:38 +00:00
if Device : isTouchDevice ( ) or Device : hasDPad ( ) then
2014-10-25 08:02:42 +00:00
local TouchMenu = require ( " ui/widget/touchmenu " )
2014-03-13 13:52:43 +00:00
main_menu = TouchMenu : new {
width = Screen : getWidth ( ) ,
2014-12-01 07:32:12 +00:00
last_index = tab_index ,
2017-02-28 21:46:32 +00:00
tab_item_table = self.tab_item_table ,
2014-03-13 13:52:43 +00:00
show_parent = menu_container ,
}
else
2014-10-25 08:02:42 +00:00
local Menu = require ( " ui/widget/menu " )
2014-03-13 13:52:43 +00:00
main_menu = Menu : new {
title = _ ( " File manager menu " ) ,
2014-10-25 08:02:42 +00:00
item_table = Menu.itemTableFromTouchMenu ( self.tab_item_table ) ,
[RFC] Pagination UI shenanigans (#7335)
* Menu/KeyValuePage/ReaderGoTo: Unify the dialogs. (Generally, "Enter page number" as title, and "Go to page" as OK button).
* Allow *tapping* on pagination buttons, too. Added spacers around the text to accommodate for that.
* Disable input handlers when <= 1 pages, while still printing the label in black.
* Always display both the label and the chevrons, even on single page content. (Menu being an exception, because it can handle showing no content at all, in which case we hide the chevrons).
* KVP: Tweak the pagination buttons layout in order to have consistent centering, regardless of whether the return arrow is enabled or not. (Also, match Menu's layout, more or less).
* Menu: Minor layout tweaks to follow the KVP tweaks above. Fixes, among possibly other things, buttons in (non-FM) "List" menus overlapping the final entry (e.g., OPDS), and popout menus with a border being misaligned (e.g., Calibre, Find a file).
* CalendarView: Minor layout tweaks to follow the KVP tweaks. Ensures the pagination buttons are laid out in the same way as everywhere else (they used to be a wee bit higher).
2021-02-25 04:15:23 +00:00
width = Screen : getWidth ( ) - ( Size.margin . fullscreen_popout * 2 ) ,
2014-10-25 08:02:42 +00:00
show_parent = menu_container ,
2014-03-13 13:52:43 +00:00
}
end
ReaderUI: Saner FM/RD lifecycle
* Ensure that going from one to the other tears down the former and
its plugins before instantiating the latter and its plugins.
UIManager: Unify Event sending & broadcasting
* Make the two behave the same way (walk the widget stack from top to
bottom), and properly handle the window stack shrinking shrinking
*and* growing.
Previously, broadcasting happened bottom-to-top and didn't really
handle the list shrinking/growing, while sending only handled the list
shrinking by a single element, and hopefully that element being the one
the event was just sent to.
These two items combined allowed us to optimize suboptimal
refresh behavior with Menu and other Menu classes when
opening/closing a document.
e.g., the "opening document" Notification is now properly regional,
and the "open last doc" option no longer flashes like a crazy person
anymore.
Plugins: Allow optimizing Menu refresh with custom menus, too.
Requires moving Menu's close_callback *after* onMenuSelect, which, eh,
probably makes sense, and is probably harmless in the grand scheme of
things.
2021-05-01 16:53:04 +00:00
main_menu.close_callback = function ( )
2014-12-01 07:32:12 +00:00
self : onCloseFileManagerMenu ( )
2014-03-13 13:52:43 +00:00
end
menu_container [ 1 ] = main_menu
-- maintain a reference to menu_container
self.menu_container = menu_container
UIManager : show ( menu_container )
return true
2013-08-14 09:29:05 +00:00
end
2014-09-05 13:02:13 +00:00
function FileManagerMenu : onCloseFileManagerMenu ( )
2014-12-01 07:32:12 +00:00
local last_tab_index = self.menu_container [ 1 ] . last_index
G_reader_settings : saveSetting ( " filemanagermenu_tab_index " , last_tab_index )
2014-09-05 13:02:13 +00:00
UIManager : close ( self.menu_container )
return true
end
2018-03-22 15:04:42 +00:00
function FileManagerMenu : _getTabIndexFromLocation ( ges )
if self.tab_item_table == nil then
self : setUpdateItemTable ( )
end
local last_tab_index = G_reader_settings : readSetting ( " filemanagermenu_tab_index " ) or 1
if not ges then
return last_tab_index
-- if the start position is far right
elseif ges.pos . x > 2 * Screen : getWidth ( ) / 3 then
2019-12-06 21:55:39 +00:00
return BD.mirroredUILayout ( ) and 1 or # self.tab_item_table
2018-03-22 15:04:42 +00:00
-- if the start position is far left
elseif ges.pos . x < Screen : getWidth ( ) / 3 then
2019-12-06 21:55:39 +00:00
return BD.mirroredUILayout ( ) and # self.tab_item_table or 1
2018-03-22 15:04:42 +00:00
-- if center return the last index
else
return last_tab_index
end
end
2017-06-01 16:32:06 +00:00
function FileManagerMenu : onTapShowMenu ( ges )
2017-08-08 16:20:46 +00:00
if self.activation_menu ~= " swipe " then
2018-03-22 15:04:42 +00:00
self : onShowMenu ( self : _getTabIndexFromLocation ( ges ) )
2017-08-08 16:20:46 +00:00
return true
end
2017-06-01 16:32:06 +00:00
end
2017-04-15 12:45:56 +00:00
function FileManagerMenu : onSwipeShowMenu ( ges )
2017-08-08 16:20:46 +00:00
if self.activation_menu ~= " tap " and ges.direction == " south " then
2018-03-22 15:04:42 +00:00
self : onShowMenu ( self : _getTabIndexFromLocation ( ges ) )
2017-04-15 12:45:56 +00:00
return true
end
2013-08-14 09:29:05 +00:00
end
function FileManagerMenu : onSetDimensions ( dimen )
2014-03-13 13:52:43 +00:00
-- update listening according to new screen dimen
if Device : isTouchDevice ( ) then
self : initGesListener ( )
end
2013-08-14 09:29:05 +00:00
end
function FileManagerMenu : registerToMainMenu ( widget )
2014-03-13 13:52:43 +00:00
table.insert ( self.registered_widgets , widget )
2013-08-14 09:29:05 +00:00
end
2013-10-18 20:38:07 +00:00
return FileManagerMenu