Skip to content

Commit

Permalink
Keep some menus open when Tap or Hold (#4189)
Browse files Browse the repository at this point in the history
TouchMenu: added options to menu items with the following defaults:
    keep_menu_open = false
    hold_keep_menu_open = true
So, default for Tap callback is to close menu, and for Hold callback
to keep menu open.
In both cases, provide the TouchMenu instance as the 1st argument to
the callback functions (instead of a refresh_menu_func I added in #3941)
so the callback can do more things, like closing, refreshing,
changing menu items text and re-ordering...

ReaderZooming: show symbol for default (like it was done for
ReaderFont, ReaderHyphenation...)
TextEditor plugin: update the previously opened files list in real
time, so the menu can be kept open and used as the TextEditor main
interface.
SSH plugin: keep menu open and update the Start/Stop state in real time
ReadTimer plugin: tried to do what feels right (but I don't use it)

Also remove forgotten cp in the move/paste file code
  • Loading branch information
poire-z committed Sep 4, 2018
1 parent 4320359 commit 850be52
Show file tree
Hide file tree
Showing 33 changed files with 214 additions and 99 deletions.
1 change: 0 additions & 1 deletion frontend/apps/filemanager/filemanager.lua
Expand Up @@ -637,7 +637,6 @@ function FileManager:pasteHere(file)
timeout = 2,
})
end
util.execute(self.cp_bin, "-r", orig, dest)
end

local info_file
Expand Down
6 changes: 6 additions & 0 deletions frontend/apps/filemanager/filemanagermenu.lua
Expand Up @@ -115,6 +115,12 @@ function FileManagerMenu:setUpdateItemTable()
}
self.menu_items.items_per_page = {
text = _("Items per page"),
help_text = _([[This sets the number of items per page in:
- File browser and history in 'classic' display mode
- File and directory selection
- Table of content
- Bookmarks list]]),
keep_menu_open = true,
callback = function()
local SpinWidget = require("ui/widget/spinwidget")
local curr_items = G_reader_settings:readSetting("items_per_page") or 14
Expand Down
2 changes: 2 additions & 0 deletions frontend/apps/reader/modules/readerdictionary.lua
Expand Up @@ -228,6 +228,7 @@ function ReaderDictionary:addToMainMenu(menu_items)
},
{
text = _("Info on dictionary order"),
keep_menu_open = true,
callback = function()
UIManager:show(InfoMessage:new{
text = T(_(
Expand Down Expand Up @@ -262,6 +263,7 @@ function ReaderDictionary:addToMainMenu(menu_items)
},
{
text = _("Clean dictionary lookup history"),
keep_menu_open = true,
callback = function()
UIManager:show(ConfirmBox:new{
text = _("Clean dictionary lookup history?"),
Expand Down
11 changes: 5 additions & 6 deletions frontend/apps/reader/modules/readerfont.lua
Expand Up @@ -68,9 +68,8 @@ function ReaderFont:init()
callback = function()
self:setFont(v)
end,
hold_may_update_menu = true,
hold_callback = function(refresh_menu_func)
self:makeDefault(v, refresh_menu_func)
hold_callback = function(touchmenu_instance)
self:makeDefault(v, touchmenu_instance)
end,
checked_func = function()
return v == self.font_face
Expand Down Expand Up @@ -310,22 +309,22 @@ function ReaderFont:setFont(face)
end
end
function ReaderFont:makeDefault(face, refresh_menu_func)
function ReaderFont:makeDefault(face, touchmenu_instance)
if face then
UIManager:show(MultiConfirmBox:new{
text = T( _("Would you like %1 to be used as the default font (★), or the fallback font (�)?\n\nCharacters not found in the active font are shown in the fallback font instead."), face),
choice1_text = _("Default"),
choice1_callback = function()
G_reader_settings:saveSetting("cre_font", face)
if refresh_menu_func then refresh_menu_func() end
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text = _("Fallback"),
choice2_callback = function()
if self.ui.document:setFallbackFontFace(face) then
G_reader_settings:saveSetting("fallback_font", face)
self.ui:handleEvent(Event:new("UpdatePos"))
end
if refresh_menu_func then refresh_menu_func() end
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
end
Expand Down
5 changes: 3 additions & 2 deletions frontend/apps/reader/modules/readerhighlight.lua
Expand Up @@ -103,7 +103,9 @@ function ReaderHighlight:genHighlightDrawerMenu()
callback = function()
self.view.highlight.disabled = not self.view.highlight.disabled
end,
hold_callback = function() self:makeDefault(not self.view.highlight.disabled) end,
hold_callback = function(touchmenu_instance)
self:makeDefault(not self.view.highlight.disabled)
end,
},
get_highlight_style("lighten"),
get_highlight_style("underscore"),
Expand Down Expand Up @@ -736,7 +738,6 @@ function ReaderHighlight:makeDefault(highlight_disabled)
G_reader_settings:saveSetting("highlight_disabled", highlight_disabled)
end,
})
self.view.highlight.disabled = highlight_disabled
end
return ReaderHighlight
7 changes: 3 additions & 4 deletions frontend/apps/reader/modules/readerhyphenation.lua
Expand Up @@ -112,8 +112,7 @@ function ReaderHyphenation:init()
-- signal readerrolling to update pos in new height, and redraw page
self.ui:handleEvent(Event:new("UpdatePos"))
end,
hold_may_update_menu = true,
hold_callback = function(refresh_menu_func)
hold_callback = function(touchmenu_instance)
UIManager:show(MultiConfirmBox:new{
-- No real need for a way to remove default one, we can just
-- toggle between setting a default OR a fallback (if a default
Expand All @@ -125,13 +124,13 @@ function ReaderHyphenation:init()
choice1_callback = function()
G_reader_settings:saveSetting("hyph_alg_default", v.filename)
G_reader_settings:delSetting("hyph_alg_fallback")
if refresh_menu_func then refresh_menu_func() end
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text = _("Fallback"),
choice2_callback = function()
G_reader_settings:saveSetting("hyph_alg_fallback", v.filename)
G_reader_settings:delSetting("hyph_alg_default")
if refresh_menu_func then refresh_menu_func() end
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
end,
Expand Down
16 changes: 9 additions & 7 deletions frontend/apps/reader/modules/readerlink.lua
Expand Up @@ -154,13 +154,15 @@ If any of the other Swipe to follow link options is enabled, this will work only
text = _("Go back to previous location"),
enabled_func = function() return #self.location_stack > 0 end,
callback = function() self:onGoBackLink() end,
hold_callback = function() UIManager:show(ConfirmBox:new{
text = _("Clear location history?"),
ok_text = _("Clear"),
ok_callback = function()
self.location_stack = {}
end,
})
hold_callback = function(touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = _("Clear location history?"),
ok_text = _("Clear"),
ok_callback = function()
self.location_stack = {}
touchmenu_instance:closeMenu()
end,
})
end,
}
end
Expand Down
6 changes: 2 additions & 4 deletions frontend/apps/reader/modules/readerstyletweak.lua
Expand Up @@ -338,7 +338,6 @@ function ReaderStyleTweak:init()
self.enabled = not self.enabled
self:updateCssText(true) -- apply it immediately
end,
hold_may_update_menu = true, -- just to keep menu opened
hold_callback = function()
UIManager:show(InfoMessage:new{
text = _(
Expand Down Expand Up @@ -398,8 +397,7 @@ You can enable individual tweaks on this book with a tap, or view more details a
end
return title
end,
hold_may_update_menu = true,
hold_callback = function(refresh_menu_func)
hold_callback = function(touchmenu_instance)
UIManager:show(TweakInfoWidget:new{
tweak = item,
is_global_default = self.global_tweaks[item.id],
Expand All @@ -409,7 +407,7 @@ You can enable individual tweaks on this book with a tap, or view more details a
else
self.global_tweaks[item.id] = true
end
refresh_menu_func()
touchmenu_instance:updateItems()
self:updateCssText(true) -- apply it immediately
end
})
Expand Down
4 changes: 3 additions & 1 deletion frontend/apps/reader/modules/readertoc.lua
Expand Up @@ -476,11 +476,12 @@ function ReaderToc:addToMainMenu(menu_items)
end,
}
if self.ui.document:canHaveAlternativeToc() then
menu_items.table_of_contents.hold_callback = function()
menu_items.table_of_contents.hold_callback = function(touchmenu_instance)
if self.ui.document:isTocAlternativeToc() then
UIManager:show(ConfirmBox:new{
text = _("The table of content for this book is currently an alternative one built from the document headings.\nDo you want to get back the original table of content? (The book will be reloaded.)"),
ok_callback = function()
touchmenu_instance:closeMenu()
self.ui.doc_settings:delSetting("alternative_toc")
self.ui.document:invalidateCacheFile()
-- Allow for ConfirmBox to be closed before showing
Expand All @@ -494,6 +495,7 @@ function ReaderToc:addToMainMenu(menu_items)
UIManager:show(ConfirmBox:new{
text = _("Do you want to use an alternative table of content built from the document headings?"),
ok_callback = function()
touchmenu_instance:closeMenu()
self:resetToc()
self.ui.document:buildAlternativeToc()
self.ui.doc_settings:saveSetting("alternative_toc", true)
Expand Down
7 changes: 4 additions & 3 deletions frontend/apps/reader/modules/readertypeset.lua
Expand Up @@ -125,8 +125,8 @@ function ReaderTypeset:genStyleSheetMenu()
callback = function()
self:setStyleSheet(css_file or self.ui.document.default_css)
end,
hold_callback = function()
self:makeDefaultStyleSheet(css_file, text)
hold_callback = function(touchmenu_instance)
self:makeDefaultStyleSheet(css_file, text, touchmenu_instance)
end,
checked_func = function()
if not css_file then -- "Auto"
Expand Down Expand Up @@ -301,11 +301,12 @@ function ReaderTypeset:makeDefaultFloatingPunctuation()
})
end

function ReaderTypeset:makeDefaultStyleSheet(css, text)
function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = T( _("Set default style to %1?"), text),
ok_callback = function()
G_reader_settings:saveSetting("copt_css", css)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
end
Expand Down
3 changes: 3 additions & 0 deletions frontend/apps/reader/modules/readerwikipedia.lua
Expand Up @@ -118,6 +118,7 @@ function ReaderWikipedia:addToMainMenu(menu_items)
sub_item_table = {
{
text = _("Set Wikipedia languages"),
keep_menu_open = true,
callback = function()
local wikilang_input
local function save_wikilang()
Expand Down Expand Up @@ -171,6 +172,7 @@ function ReaderWikipedia:addToMainMenu(menu_items)
},
{ -- setting used by dictquicklookup
text = _("Set Wikipedia 'Save as EPUB' directory"),
keep_menu_open = true,
callback = function()
local choose_directory = function()
-- Default directory as chosen by DictQuickLookup
Expand Down Expand Up @@ -298,6 +300,7 @@ Where do you want them saved?]])
},
{
text = _("Clean Wikipedia history"),
keep_menu_open = true,
callback = function()
UIManager:show(ConfirmBox:new{
text = _("Clean Wikipedia history?"),
Expand Down
70 changes: 25 additions & 45 deletions frontend/apps/reader/modules/readerzooming.lua
Expand Up @@ -318,69 +318,49 @@ end

function ReaderZooming:addToMainMenu(menu_items)
if self.ui.document.info.has_pages then
local function getZoomModeMenuItem(text, mode, separator)
return {
text_func = function()
local default_zoom_mode = G_reader_settings:readSetting("zoom_mode") or self.DEFAULT_ZOOM_MODE
return text .. (mode == default_zoom_mode and "" or "")
end,
checked_func = function()
return self.zoom_mode == mode
end,
callback = self:genSetZoomModeCallBack(mode),
hold_callback = function(touchmenu_instance)
self:makeDefault(mode, touchmenu_instance)
end,
separator = separator,
}
end
menu_items.switch_zoom_mode = {
text = _("Switch zoom mode"),
enabled_func = function()
return self.ui.document.configurable.text_wrap ~= 1
end,
sub_item_table = {
{
text = _("Zoom to fit content width"),
checked_func = function() return self.zoom_mode == "contentwidth" end,
callback = self:genSetZoomModeCallBack("contentwidth"),
hold_callback = function() self:makeDefault("contentwidth") end,
},
{
text = _("Zoom to fit content height"),
checked_func = function() return self.zoom_mode == "contentheight" end,
callback = self:genSetZoomModeCallBack("contentheight"),
hold_callback = function() self:makeDefault("contentheight") end,
separator = true,
},
{
text = _("Zoom to fit page width"),
checked_func = function() return self.zoom_mode == "pagewidth" end,
callback = self:genSetZoomModeCallBack("pagewidth"),
hold_callback = function() self:makeDefault("pagewidth") end,
},
{
text = _("Zoom to fit page height"),
checked_func = function() return self.zoom_mode == "pageheight" end,
callback = self:genSetZoomModeCallBack("pageheight"),
hold_callback = function() self:makeDefault("pageheight") end,
separator = true,
},
{
text = _("Zoom to fit column"),
checked_func = function() return self.zoom_mode == "column" end,
callback = self:genSetZoomModeCallBack("column"),
hold_callback = function() self:makeDefault("column") end,
},
{
text = _("Zoom to fit content"),
checked_func = function() return self.zoom_mode == "content" end,
callback = self:genSetZoomModeCallBack("content"),
hold_callback = function() self:makeDefault("content") end,
},
{
text = _("Zoom to fit page"),
checked_func = function() return self.zoom_mode == "page" end,
callback = self:genSetZoomModeCallBack("page"),
hold_callback = function() self:makeDefault("page") end,
},
getZoomModeMenuItem(_("Zoom to fit content width"), "contentwidth"),
getZoomModeMenuItem(_("Zoom to fit content height"), "contentheight", true),
getZoomModeMenuItem(_("Zoom to fit page width"), "pagewidth"),
getZoomModeMenuItem(_("Zoom to fit page height"), "pageheight", true),
getZoomModeMenuItem(_("Zoom to fit column"), "column"),
getZoomModeMenuItem(_("Zoom to fit content"), "content"),
getZoomModeMenuItem(_("Zoom to fit page"), "page"),
}
}
end
end

function ReaderZooming:makeDefault(zoom_mode)
function ReaderZooming:makeDefault(zoom_mode, touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = T(
_("Set default zoom mode to %1?"),
zoom_mode
),
ok_callback = function()
G_reader_settings:saveSetting("zoom_mode", zoom_mode)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
end
Expand Down
5 changes: 5 additions & 0 deletions frontend/ui/elements/common_info_menu_table.lua
Expand Up @@ -15,6 +15,7 @@ end
local version = require("version"):getCurrentRevision()
common_info.version = {
text = _("Version"),
keep_menu_open = true,
callback = function()
UIManager:show(InfoMessage:new{
text = version,
Expand All @@ -41,6 +42,7 @@ common_info.quickstart_guide = {
}
common_info.about = {
text = _("About"),
keep_menu_open = true,
callback = function()
UIManager:show(InfoMessage:new{
text = T(_("KOReader %1\n\nA document viewer for E Ink devices.\n\nLicensed under Affero GPL v3. All dependencies are free software.\n\nhttp://koreader.rocks/"), version),
Expand All @@ -49,6 +51,7 @@ common_info.about = {
}
common_info.report_bug = {
text = _("Report a bug"),
keep_menu_open = true,
callback = function()
local model = Device.model
UIManager:show(InfoMessage:new{
Expand All @@ -69,6 +72,7 @@ end
if Device:isKobo() then
common_info.reboot = {
text = _("Reboot the device"),
keep_menu_open = true,
callback = function()
UIManager:show(ConfirmBox:new{
text = _("Are you sure you want to reboot the device?"),
Expand All @@ -81,6 +85,7 @@ if Device:isKobo() then
}
common_info.poweroff = {
text = _("Power off"),
keep_menu_open = true,
callback = function()
UIManager:show(ConfirmBox:new{
text = _("Are you sure you want to power off the device?"),
Expand Down
2 changes: 2 additions & 0 deletions frontend/ui/elements/common_settings_menu_table.lua
Expand Up @@ -27,6 +27,7 @@ if Device:setDateTime() then
sub_item_table = {
{
text = _("Set time"),
keep_menu_open = true,
callback = function()
local now_t = os.date("*t")
local curr_hour = now_t.hour
Expand Down Expand Up @@ -55,6 +56,7 @@ if Device:setDateTime() then
},
{
text = _("Set date"),
keep_menu_open = true,
callback = function()
local now_t = os.date("*t")
local curr_year = now_t.year
Expand Down

0 comments on commit 850be52

Please sign in to comment.