Checkbutton: optimize callback (#8134)

pull/8141/head
hius07 3 years ago committed by GitHub
parent 27bf5b59dd
commit 68782c3f89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,15 +21,9 @@ local _ = require("gettext")
local Screen = require("device").screen
local FileSearcher = InputContainer:new{
search_dialog = nil,
--filesearcher
-- state buffer
dirs = {},
files = {},
results = {},
items = 0,
commands = nil,
}
function FileSearcher:readDir()
@ -109,8 +103,6 @@ function FileSearcher:setSearchResults()
end
end
end
self.keywords = keywords
self.items = #self.results
end
function FileSearcher:close()
@ -172,11 +164,7 @@ function FileSearcher:onShowFileSearch(search_string)
parent = self.search_dialog,
max_width = self.search_dialog._input_widget.width,
callback = function()
if self.check_button_case.checked then
self.check_button_case:unCheck()
else
self.check_button_case:check()
end
self.check_button_case:toggleCheck()
self.case_sensitive = self.check_button_case.checked
end,
}

@ -142,11 +142,7 @@ function ReaderSearch:onShowFulltextSearchInput()
parent = self.input_dialog,
max_width = self.input_dialog._input_widget.width,
callback = function()
if not self.check_button_case.checked then
self.check_button_case:check()
else
self.check_button_case:unCheck()
end
self.check_button_case:toggleCheck()
end,
}
self.check_button_regex = CheckButton:new{
@ -155,11 +151,7 @@ function ReaderSearch:onShowFulltextSearchInput()
parent = self.input_dialog,
max_width = self.input_dialog._input_widget.width,
callback = function()
if not self.check_button_regex.checked then
self.check_button_regex:check()
else
self.check_button_regex:unCheck()
end
self.check_button_regex:toggleCheck()
end,
hold_callback = function()
UIManager:show(InfoMessage:new{ text = help_text })

@ -57,11 +57,7 @@ local sub_item_table = {
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
if check_button_bold.checked then
check_button_bold:unCheck()
else
check_button_bold:check()
end
check_button_bold:toggleCheck()
end,
}
check_button_border = CheckButton:new{
@ -70,11 +66,7 @@ local sub_item_table = {
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
if check_button_border.checked then
check_button_border:unCheck()
else
check_button_border:check()
end
check_button_border:toggleCheck()
end,
}

@ -174,15 +174,8 @@ function CheckButton:onHoldReleaseCheckButton()
return false
end
function CheckButton:check()
self:initCheckButton(true)
UIManager:setDirty(self.parent, function()
return "ui", self.dimen
end)
end
function CheckButton:unCheck()
self:initCheckButton(false)
function CheckButton:toggleCheck()
self:initCheckButton(not self.checked)
UIManager:setDirty(self.parent, function()
return "ui", self.dimen
end)

@ -820,13 +820,8 @@ function InputDialog:_addScrollButtons(nav_bar)
parent = input_dialog,
max_width = input_dialog._input_widget.width,
callback = function()
if not self.check_button_case.checked then
self.check_button_case:check()
self.case_sensitive = true
else
self.check_button_case:unCheck()
self.case_sensitive = false
end
self.check_button_case:toggleCheck()
self.case_sensitive = self.check_button_case.checked
end,
}

@ -394,13 +394,8 @@ function InputText:initTextBox(text, char_added)
parent = self,
max_width = self.width,
callback = function()
if self.text_type == "text" then
self.text_type = "password"
self._check_button:unCheck()
else
self.text_type = "text"
self._check_button:check()
end
self._check_button:toggleCheck()
self.text_type = self._check_button.checked and "text" or "password"
self:setText(self:getText(), true)
end,
}

@ -64,11 +64,7 @@ function OpenWithDialog:init()
self._check_file_button = self._check_file_button or CheckButton:new{
text = _("Always use this engine for this file"),
callback = function()
if self._check_file_button.checked then
self._check_file_button:unCheck()
else
self._check_file_button:check()
end
self._check_file_button:toggleCheck()
end,
max_width = self.element_width,
@ -88,11 +84,7 @@ function OpenWithDialog:init()
self._check_global_button = self._check_global_button or CheckButton:new{
text = _("Always use this engine for file type"),
callback = function()
if self._check_global_button.checked then
self._check_global_button:unCheck()
else
self._check_global_button:check()
end
self._check_global_button:toggleCheck()
end,
max_width = self.element_width,

Loading…
Cancel
Save