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