Dispatcher: add "Edit/toggle book-specific style tweak" (#14944)

This commit is contained in:
poire-z authored and GitHub committed 2026-02-10 00:58:00 +01:00
1 parent ba0e6e5838
commit 3e931f72a9
2 files changed
+57 -12

No files matched your search

@@ -706,17 +706,10 @@ You can enable individual tweaks on this book with a tap, or view more details a
enabled_func = function() return self.enabled end,
checked_func = function() return self.book_style_tweak_enabled end,
callback = function(touchmenu_instance)
if self.book_style_tweak then
-- There is a tweak: toggle it on tap, like other tweaks
self.book_style_tweak_enabled = not self.book_style_tweak_enabled
self:updateCssText(true) -- apply it immediately
else
-- No tweak defined: launch editor
self:editBookTweak(touchmenu_instance)
end
self:onToggleBookTweak(touchmenu_instance, true)
end,
hold_callback = function(touchmenu_instance)
self:editBookTweak(touchmenu_instance)
self:onEditBookTweak(touchmenu_instance)
end,
}
table.insert(self.tweaks_table, book_tweak_item)
@@ -790,6 +783,45 @@ function ReaderStyleTweak:onDispatcherRegisterActions()
end
end
function ReaderStyleTweak:onToggleStyleTweaks(no_notification)
self.enabled = not self.enabled
self:updateCssText(true) -- apply it immediately
if not no_notification then
local text
if self.enabled then
text = _("Enabled style tweaks.")
else
text = _("Disabled style tweaks.")
end
UIManager:show(Notification:new{
text = text,
})
end
end
function ReaderStyleTweak:onToggleBookTweak(touchmenu_instance, no_notification)
if self.book_style_tweak then
-- There is a tweak: toggle it on tap, like other tweaks
self.book_style_tweak_enabled = not self.book_style_tweak_enabled
self:updateCssText(true) -- apply it immediately
if not no_notification then
-- Same format as for individual tweaks
local text = _("Book-specific tweak")
if self.book_style_tweak_enabled then
text = T(C_("Style tweak", "On: %1"), text)
else
text = T(C_("Style tweak", "Off: %1"), text)
end
UIManager:show(Notification:new{
text = text,
})
end
else
-- No tweak defined: launch editor
self:onEditBookTweak(touchmenu_instance)
end
end
local BOOK_TWEAK_SAMPLE_CSS = [[
/* Remove indent from some P used as titles */
p.someTitleClassName {
@@ -936,7 +968,7 @@ If used as-is, they will act on ALL elements!]]), true},
}},
}
function ReaderStyleTweak:editBookTweak(touchmenu_instance)
function ReaderStyleTweak:onEditBookTweak(touchmenu_instance)
local InputDialog = require("ui/widget/inputdialog")
local editor -- our InputDialog instance
local tweak_button_id = "editBookTweakButton"
@@ -1195,12 +1227,16 @@ function ReaderStyleTweak:editBookTweak(touchmenu_instance)
if should_apply then
-- Let menu be closed and previous page be refreshed,
-- so one can see how the text is changed by the tweak.
touchmenu_instance:closeMenu()
if touchmenu_instance then
touchmenu_instance:closeMenu()
end
UIManager:scheduleIn(0.2, function()
self:updateCssText(true) -- have it applied
end)
else
touchmenu_instance:updateItems()
if touchmenu_instance then
touchmenu_instance:updateItems()
end
end
editor.save_callback_called = true
return true, msg
+9
View File
@@ -229,6 +229,10 @@ local settingsList = {
set_font = {category="string", event="SetFont", title=_("Font"), rolling=true, args_func=require("fontlist").getFontArgFunc,},
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},
----
toggle_style_tweaks = {category="none", event="ToggleStyleTweaks", title=_("Toggle style tweaks"), rolling=true},
edit_book_tweak = {category="none", event="EditBookTweak", title=_("Edit book-specific style tweak"), rolling=true},
toggle_book_tweak = {category="none", event="ToggleBookTweak", title=_("Toggle book-specific style tweak"), rolling=true},
-- Fixed layout documents
toggle_page_flipping = {category="none", event="TogglePageFlipping", title=_("Toggle page flipping"), paging=true},
@@ -506,6 +510,11 @@ local dispatcher_menu_order = {
"embedded_fonts",
"smooth_scaling",
"nightmode_images",
----
"toggle_style_tweaks",
"edit_book_tweak",
"toggle_book_tweak",
-- Individual tweaks will be inserted here when "show in action list"
-- Fixed layout documents
"toggle_page_flipping",