From 002b4d4be9141be4f21010a6258448aa976d016e Mon Sep 17 00:00:00 2001 From: yparitcher Date: Wed, 12 May 2021 22:38:52 -0400 Subject: [PATCH] Kopt/Creoptions: change to using an event to update configurable. Abstract implimentation out of ConfigDialog --- .../reader/modules/readercoptlistener.lua | 6 ++ .../reader/modules/readerkoptlistener.lua | 8 +++ frontend/dispatcher.lua | 2 +- frontend/ui/data/koptoptions.lua | 1 - frontend/ui/widget/configdialog.lua | 58 +++++-------------- 5 files changed, 30 insertions(+), 45 deletions(-) diff --git a/frontend/apps/reader/modules/readercoptlistener.lua b/frontend/apps/reader/modules/readercoptlistener.lua index 741443491..817892dbc 100644 --- a/frontend/apps/reader/modules/readercoptlistener.lua +++ b/frontend/apps/reader/modules/readercoptlistener.lua @@ -63,6 +63,12 @@ function ReaderCoptListener:onReadSettings(config) self:rescheduleHeaderRefreshIfNeeded() -- schedule (or not) first refresh end +function ReaderCoptListener:onConfigChange(option_name, option_value) + self.document.configurable[option_name] = option_value + self.ui:handleEvent(Event:new("StartActivityIndicator")) + return true +end + function ReaderCoptListener:onSetFontSize(font_size) self.document.configurable.font_size = font_size end diff --git a/frontend/apps/reader/modules/readerkoptlistener.lua b/frontend/apps/reader/modules/readerkoptlistener.lua index c59719bea..da5703d36 100644 --- a/frontend/apps/reader/modules/readerkoptlistener.lua +++ b/frontend/apps/reader/modules/readerkoptlistener.lua @@ -1,6 +1,7 @@ local EventListener = require("ui/widget/eventlistener") local Event = require("ui/event") local ReaderZooming = require("apps/reader/modules/readerzooming") +local UIManager = require("ui/uimanager") local util = require("util") local ReaderKoptListener = EventListener:new{} @@ -72,4 +73,11 @@ function ReaderKoptListener:onDocLangUpdate(lang) end end +function ReaderKoptListener:onConfigChange(option_name, option_value) + self.document.configurable[option_name] = option_value + self.ui:handleEvent(Event:new("StartActivityIndicator")) + UIManager:setDirty("all", "partial") + return true +end + return ReaderKoptListener diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index 2f62da10d..1c13c4bf2 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -651,7 +651,7 @@ function Dispatcher:execute(ui, settings, gesture) if v == r then value = settingsList[k].configurable.values[i] break end end end - ui.document.configurable[settingsList[k].configurable.name] = value + ui:handleEvent(Event:new("ConfigChange", settingsList[k].configurable.name, value)) end end end diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 9fb351964..a354dea92 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -22,7 +22,6 @@ end local KoptOptions = { prefix = "kopt", - needs_redraw_on_change = true, { icon = "appbar.rotation", options = { diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 0a340b724..dd835a017 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -959,8 +959,7 @@ function ConfigDialog:onShowConfigPanel(index) end function ConfigDialog:onConfigChoice(option_name, option_value) - self.configurable[option_name] = option_value - self.ui:handleEvent(Event:new("StartActivityIndicator")) + self.ui:handleEvent(Event:new("ConfigChange", option_name, option_value)) return true end @@ -982,18 +981,9 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position -- Repainting may be delayed depending on options local refresh_dialog_func = function() self.skip_paint = nil - if self.config_options.needs_redraw_on_change then - -- Some Kopt document event handlers just save their setting, - -- and need a full repaint for kopt to load these settings, - -- notice the change, and redraw the document - UIManager:setDirty("all", "partial") - else - -- CreDocument event handlers do their own refresh: - -- we can just redraw our frame - UIManager:setDirty(self, function() - return "ui", self.dialog_frame.dimen - end) - end + UIManager:setDirty(self, function() + return "ui", self.dialog_frame.dimen + end) end local when_applied_callback = nil if type(hide_on_apply) == "number" then -- timeout @@ -1033,18 +1023,9 @@ function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, -- Repainting may be delayed depending on options local refresh_dialog_func = function() self.skip_paint = nil - if self.config_options.needs_redraw_on_change then - -- Some Kopt document event handlers just save their setting, - -- and need a full repaint for kopt to load these settings, - -- notice the change, and redraw the document - UIManager:setDirty("all", "partial") - else - -- CreDocument event handlers do their own refresh: - -- we can just redraw our frame - UIManager:setDirty(self, function() - return "ui", self.dialog_frame.dimen - end) - end + UIManager:setDirty(self, function() + return "ui", self.dialog_frame.dimen + end) end local when_applied_callback = nil if type(hide_on_apply) == "number" then -- timeout @@ -1139,24 +1120,15 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m if self.skip_paint and not keep_skip_paint then self.skip_paint = nil end - if self.config_options.needs_redraw_on_change then - -- Some Kopt document event handlers just save their setting, - -- and need a full repaint for kopt to load these settings, - -- notice the change, and redraw the document - UIManager:setDirty("all", "partial") + if self.skip_paint then + -- Redraw anything below the now hidden ConfigDialog + UIManager:setDirty("all", function() + return "partial", self.dialog_frame.dimen + end) else - -- CreDocument event handlers do their own refresh: - -- we can just redraw our frame - if self.skip_paint then - -- Redraw anything below the now hidden ConfigDialog - UIManager:setDirty("all", function() - return "partial", self.dialog_frame.dimen - end) - else - UIManager:setDirty(self, function() - return "ui", self.dialog_frame.dimen - end) - end + UIManager:setDirty(self, function() + return "ui", self.dialog_frame.dimen + end) end end local hide_on_picker_show = more_options_param.hide_on_picker_show