Use checked_func instead of remembering the checked item.

pull/1178/head
Andrey Golovizin 10 years ago
parent a3e51b339d
commit 50d9041c1d

@ -20,17 +20,8 @@ local ReaderFont = InputContainer:new{
face_table = nil, face_table = nil,
-- default gamma from crengine's lvfntman.cpp -- default gamma from crengine's lvfntman.cpp
gamma_index = nil, gamma_index = nil,
cur_face_idx = nil,
} }
function ReaderFont:_changeSel(k)
if self.cur_face_idx then
self.face_table[self.cur_face_idx].checked = false
end
self.face_table[k].checked = true
self.cur_face_idx = k
end
function ReaderFont:init() function ReaderFont:init()
if Device:hasKeyboard() then if Device:hasKeyboard() then
-- add shortcut for keyboard -- add shortcut for keyboard
@ -58,18 +49,17 @@ function ReaderFont:init()
self.face_table = {} self.face_table = {}
local face_list = cre.getFontFaces() local face_list = cre.getFontFaces()
for k,v in ipairs(face_list) do for k,v in ipairs(face_list) do
if v == self.font_face then
self.cur_face_idx = k
end
table.insert(self.face_table, { table.insert(self.face_table, {
text = v, text = v,
callback = function() callback = function()
self:_changeSel(k)
self:setFont(v) self:setFont(v)
end, end,
hold_callback = function() hold_callback = function()
self:makeDefault(v) self:makeDefault(v)
end, end,
checked_func = function()
return v == self.font_face
end
}) })
face_list[k] = {text = v} face_list[k] = {text = v}
end end
@ -114,12 +104,6 @@ function ReaderFont:onReadSettings(config)
table.insert(self.ui.postInitCallback, function() table.insert(self.ui.postInitCallback, function()
self.ui:handleEvent(Event:new("UpdatePos")) self.ui:handleEvent(Event:new("UpdatePos"))
end) end)
for k,v in ipairs(self.face_table) do
if v.text == self.font_face then
self:_changeSel(k)
end
end
end end
function ReaderFont:onShowFontMenu() function ReaderFont:onShowFontMenu()

@ -6,24 +6,12 @@ local _ = require("gettext")
local ReaderHyphenation = InputContainer:new{ local ReaderHyphenation = InputContainer:new{
hyph_menu_title = _("Hyphenation"), hyph_menu_title = _("Hyphenation"),
hyph_table = nil, hyph_table = nil,
cur_hyph_idx = nil,
} }
function ReaderHyphenation:_changeSel(k)
if self.cur_hyph_idx then
self.hyph_table[self.cur_hyph_idx].checked = false
end
self.hyph_table[k].checked = true
self.cur_hyph_idx = k
end
function ReaderHyphenation:init() function ReaderHyphenation:init()
self.hyph_table = {} self.hyph_table = {}
self.hyph_alg = cre.getSelectedHyphDict() self.hyph_alg = cre.getSelectedHyphDict()
for k,v in ipairs(cre.getHyphDictList()) do for k,v in ipairs(cre.getHyphDictList()) do
if v == self.hyph_alg then
self.cur_hyph_idx = k
end
table.insert(self.hyph_table, { table.insert(self.hyph_table, {
text = v, text = v,
callback = function() callback = function()
@ -31,9 +19,11 @@ function ReaderHyphenation:init()
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = _("Change Hyphenation to ")..v, text = _("Change Hyphenation to ")..v,
}) })
self:_changeSel(k)
self.ui.document:setHyphDictionary(v) self.ui.document:setHyphDictionary(v)
self.ui.toc:onUpdateToc() self.ui.toc:onUpdateToc()
end,
checked_func = function()
return v == self.hyph_alg
end end
}) })
end end
@ -46,11 +36,6 @@ function ReaderHyphenation:onReadSettings(config)
self.ui.document:setHyphDictionary(hyph_alg) self.ui.document:setHyphDictionary(hyph_alg)
end end
self.hyph_alg = cre.getSelectedHyphDict() self.hyph_alg = cre.getSelectedHyphDict()
for k,v in ipairs(self.hyph_table) do
if v.text == self.hyph_alg then
self:_changeSel(k)
end
end
end end
function ReaderHyphenation:onSaveSettings() function ReaderHyphenation:onSaveSettings()

Loading…
Cancel
Save