Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set global settings independent of local setting #5522

Merged
merged 10 commits into from Oct 25, 2019
29 changes: 16 additions & 13 deletions frontend/apps/reader/modules/readerdictionary.lua
Expand Up @@ -9,6 +9,7 @@ local InputDialog = require("ui/widget/inputdialog")
local JSON = require("json")
local KeyValuePage = require("ui/widget/keyvaluepage")
local LuaData = require("luadata")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local NetworkMgr = require("ui/network/manager")
local Trapper = require("ui/trapper")
local UIManager = require("ui/uimanager")
Expand Down Expand Up @@ -249,7 +250,7 @@ If you'd like to change the order in which dictionaries are queried (and their r
self.disable_fuzzy_search = not self.disable_fuzzy_search
end,
hold_callback = function()
self:makeDisableFuzzyDefault(self.disable_fuzzy_search)
self:toggleFuzzyDefault()
end,
separator = true,
},
Expand Down Expand Up @@ -950,21 +951,23 @@ function ReaderDictionary:onSaveSettings()
self.ui.doc_settings:saveSetting("disable_fuzzy_search", self.disable_fuzzy_search)
end

function ReaderDictionary:makeDisableFuzzyDefault(disable_fuzzy_search)
logger.dbg("disable fuzzy search", self.disable_fuzzy_search)
UIManager:show(ConfirmBox:new{
function ReaderDictionary:toggleFuzzyDefault()
local disable_fuzzy_search = G_reader_settings:isTrue("disable_fuzzy_search")
UIManager:show(MultiConfirmBox:new{
text = T(
disable_fuzzy_search
and _("Disable fuzzy search by default?")
or _("Enable fuzzy search by default?")
and _("Enable fuzzy search by default?")
or _("Disable fuzzy search by default?")
yparitcher marked this conversation as resolved.
Show resolved Hide resolved
),
ok_text = T(
disable_fuzzy_search
and _("Disable")
or _("Enable")
),
ok_callback = function()
G_reader_settings:saveSetting("disable_fuzzy_search", disable_fuzzy_search)
choice1_text = _("Disable"),
choice1_enabled = not disable_fuzzy_search,
choice1_callback = function()
G_reader_settings:saveSetting("disable_fuzzy_search", true)
end,
choice2_text = _("Enable"),
choice2_enabled = disable_fuzzy_search,
choice2_callback = function()
G_reader_settings:saveSetting("disable_fuzzy_search", false)
end,
})
end
Expand Down
31 changes: 17 additions & 14 deletions frontend/apps/reader/modules/readerhighlight.lua
@@ -1,10 +1,10 @@
local ButtonDialog = require("ui/widget/buttondialog")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local Notification = require("ui/widget/notification")
local InputContainer = require("ui/widget/container/inputcontainer")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local Notification = require("ui/widget/notification")
local TimeVal = require("ui/timeval")
local Translator = require("ui/translator")
local UIManager = require("ui/uimanager")
Expand Down Expand Up @@ -116,7 +116,7 @@ function ReaderHighlight:genHighlightDrawerMenu()
self.view.highlight.disabled = not self.view.highlight.disabled
end,
hold_callback = function(touchmenu_instance)
self:makeDefault(not self.view.highlight.disabled)
self:toggleDefault()
end,
separator = true,
},
Expand Down Expand Up @@ -1179,17 +1179,20 @@ function ReaderHighlight:onClose()
self:clear()
end

function ReaderHighlight:makeDefault(highlight_disabled)
local new_text
if highlight_disabled then
new_text = _("Disable highlight by default.")
else
new_text = _("Enable highlight by default.")
end
UIManager:show(ConfirmBox:new{
text = new_text,
ok_callback = function()
G_reader_settings:saveSetting("highlight_disabled", highlight_disabled)
function ReaderHighlight:toggleDefault()
local highlight_disabled = G_reader_settings:isTrue("highlight_disabled")
UIManager:show(MultiConfirmBox:new{
text = highlight_disabled and _("Enable highlighting by default.")
yparitcher marked this conversation as resolved.
Show resolved Hide resolved
or _("Disable highlighting by default."),
choice1_text = _("Disable"),
choice1_enabled = not highlight_disabled,
choice1_callback = function()
G_reader_settings:saveSetting("highlight_disabled", true)
end,
choice2_text = _("Enable"),
choice2_enabled = highlight_disabled,
choice2_callback = function()
G_reader_settings:saveSetting("highlight_disabled", false)
end,
})
end
Expand Down
23 changes: 15 additions & 8 deletions frontend/apps/reader/modules/readerpaging.lua
@@ -1,9 +1,9 @@
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
local Geom = require("ui/geometry")
local InputContainer = require("ui/widget/container/inputcontainer")
local Math = require("optmath")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local UIManager = require("ui/uimanager")
local logger = require("logger")
local _ = require("gettext")
Expand Down Expand Up @@ -244,13 +244,20 @@ function ReaderPaging:addToMainMenu(menu_items)
self.ui:handleEvent(Event:new("ToggleReadingOrder"))
end,
hold_callback = function(touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = self.inverse_reading_order and _("Enable right to left reading by default?")
or _("Disable right to left reading by default?"),
ok_text = self.inverse_reading_order and _("Enable")
or _("Disable"),
ok_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
local inverse_reading_order = G_reader_settings:isTrue("inverse_reading_order")
UIManager:show(MultiConfirmBox:new{
text = inverse_reading_order and _("The default for newly opened books is Right To Left page turning.\nWould you like to change it?")
yparitcher marked this conversation as resolved.
Show resolved Hide resolved
or _("The default for newly opened books is Left To Right page turning.\nWould you like to change it?"),
yparitcher marked this conversation as resolved.
Show resolved Hide resolved
choice1_text = _("Left-To-Right"),
yparitcher marked this conversation as resolved.
Show resolved Hide resolved
choice1_enabled = inverse_reading_order,
choice1_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", false)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text = _("Right-To-Left"),
choice2_enabled = not inverse_reading_order,
choice2_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", true)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
Expand Down
22 changes: 15 additions & 7 deletions frontend/apps/reader/modules/readerrolling.lua
Expand Up @@ -3,6 +3,7 @@ local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
local InputContainer = require("ui/widget/container/inputcontainer")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local ProgressWidget = require("ui/widget/progresswidget")
local ReaderPanning = require("apps/reader/modules/readerpanning")
local TimeVal = require("ui/timeval")
Expand Down Expand Up @@ -370,13 +371,20 @@ function ReaderRolling:addToMainMenu(menu_items)
self.ui:handleEvent(Event:new("ToggleReadingOrder"))
end,
hold_callback = function(touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = self.inverse_reading_order and _("Enable right to left reading by default?")
or _("Disable right to left reading by default?"),
ok_text = self.inverse_reading_order and _("Enable")
or _("Disable"),
ok_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
local inverse_reading_order = G_reader_settings:isTrue("inverse_reading_order")
UIManager:show(MultiConfirmBox:new{
text = inverse_reading_order and _("The default for newly opened books is Right To Left page turning.\nWould you like to change it?")
or _("The default for newly opened books is Left To Right page turning.\nWould you like to change it?"),
choice1_text = _("Left-To-Right"),
choice1_enabled = inverse_reading_order,
choice1_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", false)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text = _("Right-To-Left"),
choice2_enabled = not inverse_reading_order,
choice2_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", true)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
Expand Down
19 changes: 14 additions & 5 deletions frontend/apps/reader/modules/readertypeset.lua
Expand Up @@ -2,6 +2,7 @@ local ConfirmBox = require("ui/widget/confirmbox")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local UIManager = require("ui/uimanager")
local Math = require("optmath")
local lfs = require("libs/libkoreader-lfs")
Expand Down Expand Up @@ -428,14 +429,22 @@ function ReaderTypeset:addToMainMenu(menu_items)
end

function ReaderTypeset:makeDefaultFloatingPunctuation()
local toggler = self.floating_punctuation == 1 and _("On") or _("Off")
UIManager:show(ConfirmBox:new{
local floating_punctuation = G_reader_settings:isTrue("floating_punctuation")
local toggler = floating_punctuation and _("Disable") or _("Enable")
UIManager:show(MultiConfirmBox:new{
text = T(
_("Set default hanging punctuation to %1?"),
_("%1 hanging punctuation by default?"),
yparitcher marked this conversation as resolved.
Show resolved Hide resolved
toggler
),
ok_callback = function()
G_reader_settings:saveSetting("floating_punctuation", self.floating_punctuation)
choice1_text = _("Disable"),
choice1_enabled = floating_punctuation,
choice1_callback = function()
G_reader_settings:saveSetting("floating_punctuation", false)
end,
choice2_text = _("Enable"),
choice2_enabled = not floating_punctuation,
choice2_callback = function()
G_reader_settings:saveSetting("floating_punctuation", true)
end,
})
end
Expand Down
4 changes: 4 additions & 0 deletions frontend/ui/widget/multiconfirmbox.lua
Expand Up @@ -48,6 +48,8 @@ local MultiConfirmBox = InputContainer:new{
choice1_callback = function() end,
choice2_callback = function() end,
cancel_callback = function() end,
choice1_enabled = true,
yparitcher marked this conversation as resolved.
Show resolved Hide resolved
choice2_enabled = true,
margin = Size.margin.default,
padding = Size.padding.default,
dismissable = true, -- set to false if any button callback is required
Expand Down Expand Up @@ -102,13 +104,15 @@ function MultiConfirmBox:init()
},
{
text = self.choice1_text,
enabled = self.choice1_enabled,
callback = function()
self.choice1_callback()
UIManager:close(self)
end,
},
{
text = self.choice2_text,
enabled = self.choice2_enabled,
callback = function()
self.choice2_callback()
UIManager:close(self)
Expand Down