Book style tweak editor: fix double notification on discard

Avoid two identical stacked notifications "Book tweak not modified"
after Close + Discard when text was modified.
This commit is contained in:
poire-z
2024-08-25 20:40:08 +02:00
parent db8786f058
commit 9f308399f9
2 changed files with 9 additions and 9 deletions

View File

@@ -1171,16 +1171,15 @@ function ReaderStyleTweak:editBookTweak(touchmenu_instance)
editor.save_callback_called = true
return true, msg
end,
close_callback = function()
close_callback = function(close_status)
-- save_callback() will always have shown some notification,
-- so don't add another one
if not editor.save_callback_called then
-- so don't add another one.
-- If close_status is false, text was modified but then discarded, and
-- InputDialog will show our close_discarded_notif_text
if not editor.save_callback_called and close_status ~= false then
UIManager:show(Notification:new{
text = NOT_MODIFIED_MSG,
text = NOT_MODIFIED_MSG
})
-- This has to be the same message above and below: when
-- discarding, we can't prevent these 2 notifications from
-- being shown: having them identical will hide that.
end
end,
close_discarded_notif_text = NOT_MODIFIED_MSG,

View File

@@ -159,6 +159,7 @@ local InputDialog = FocusManager:extend{
-- - on success: as the notification text instead of the default one
-- - on failure: in an InfoMessage
close_callback = nil, -- Called when closing (if discarded or saved, after save_callback if saved)
-- (passed true/false if text modified and saved/discarded, nil if closed with text unmodified)
edited_callback = nil, -- Called on each text modification
-- For use by TextEditor plugin:
@@ -844,7 +845,7 @@ function InputDialog:_addSaveCloseButtons()
cancel_text = self.close_cancel_button_text or _("Cancel"),
choice1_text = self.close_discard_button_text or _("Discard"),
choice1_callback = function()
if self.close_callback then self.close_callback() end
if self.close_callback then self.close_callback(false) end
UIManager:close(self)
UIManager:show(Notification:new{
text = self.close_discarded_notif_text or _("Changes discarded"),
@@ -863,7 +864,7 @@ function InputDialog:_addSaveCloseButtons()
})
end
else -- nil or true
if self.close_callback then self.close_callback() end
if self.close_callback then self.close_callback(true) end
UIManager:close(self)
UIManager:show(Notification:new{
text = msg or _("Saved"),