koreader/frontend/apps/reader/modules/readerhyphenation.lua

67 lines
1.9 KiB
Lua
Raw Normal View History

2013-10-18 22:38:07 +02:00
local InputContainer = require("ui/widget/container/inputcontainer")
local UIManager = require("ui/uimanager")
local InfoMessage = require("ui/widget/infomessage")
local _ = require("gettext")
2013-04-16 13:11:28 -04:00
2013-10-18 22:38:07 +02:00
local ReaderHyphenation = InputContainer:new{
2014-03-13 21:52:43 +08:00
hyph_menu_title = _("Hyphenation"),
hyph_table = nil,
cur_hyph_idx = nil,
2013-04-16 13:11:28 -04:00
}
function ReaderHyphenation:_changeSel(k)
2014-03-13 21:52:43 +08:00
if self.cur_hyph_idx then
self.hyph_table[self.cur_hyph_idx].selected = false
end
self.hyph_table[k].selected = true
self.cur_hyph_idx = k
end
2013-04-16 13:11:28 -04:00
function ReaderHyphenation:init()
2014-03-13 21:52:43 +08:00
self.hyph_table = {}
self.hyph_alg = cre.getSelectedHyphDict()
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, {
text = v,
callback = function()
self.hyph_alg = v
UIManager:show(InfoMessage:new{
text = _("Change Hyphenation to ")..v,
})
self:_changeSel(k)
cre.setHyphDictionary(v)
end
})
end
self.ui.menu:registerToMainMenu(self)
2013-04-16 13:11:28 -04:00
end
function ReaderHyphenation:onReadSettings(config)
2014-03-13 21:52:43 +08:00
local hyph_alg = config:readSetting("hyph_alg")
if hyph_alg then
cre.setHyphDictionary(hyph_alg)
end
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
function ReaderHyphenation:onSaveSettings()
self.ui.doc_settings:saveSetting("hyph_alg", self.hyph_alg)
end
2013-04-16 13:11:28 -04:00
function ReaderHyphenation:addToMainMenu(tab_item_table)
2014-03-13 21:52:43 +08:00
-- insert table to main reader menu
table.insert(tab_item_table.typeset, {
text = self.hyph_menu_title,
sub_item_table = self.hyph_table,
})
2013-04-16 13:11:28 -04:00
end
2013-10-18 22:38:07 +02:00
return ReaderHyphenation