mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #786 from chrox/master
enable highlight in dictionary lookup window
This commit is contained in:
@@ -28,6 +28,9 @@ function FileManagerMenu:init()
|
||||
info = {
|
||||
icon = "resources/icons/appbar.pokeball.png",
|
||||
},
|
||||
tools = {
|
||||
icon = "resources/icons/appbar.tools.png",
|
||||
},
|
||||
home = {
|
||||
icon = "resources/icons/appbar.home.png",
|
||||
callback = function()
|
||||
@@ -104,18 +107,6 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
end
|
||||
})
|
||||
table.insert(self.tab_item_table.setting, Language:getLangMenuTable())
|
||||
table.insert(self.tab_item_table.setting, {
|
||||
text = _("Default settings"),
|
||||
callback = function()
|
||||
SetDefaults:ConfirmEdit()
|
||||
end
|
||||
})
|
||||
table.insert(self.tab_item_table.setting, {
|
||||
text = _("Save default settings"),
|
||||
callback = function()
|
||||
SetDefaults:ConfirmSave()
|
||||
end
|
||||
})
|
||||
-- info tab
|
||||
if Device:isKindle() or Device:isKobo() then
|
||||
table.insert(self.tab_item_table.info, OTAManager:getOTAMenuTable())
|
||||
@@ -136,7 +127,17 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
})
|
||||
end
|
||||
})
|
||||
table.insert(self.tab_item_table.info, {
|
||||
-- tools tab
|
||||
table.insert(self.tab_item_table.tools, {
|
||||
text = _("Set defaults"),
|
||||
callback = function()
|
||||
SetDefaults:ConfirmEdit()
|
||||
end,
|
||||
hold_callback = function()
|
||||
SetDefaults:ConfirmSave()
|
||||
end,
|
||||
})
|
||||
table.insert(self.tab_item_table.tools, {
|
||||
text = _("Search books"),
|
||||
callback = function()
|
||||
Search:init()
|
||||
@@ -161,6 +162,7 @@ function FileManagerMenu:onShowMenu()
|
||||
tab_item_table = {
|
||||
self.tab_item_table.setting,
|
||||
self.tab_item_table.info,
|
||||
self.tab_item_table.tools,
|
||||
self.tab_item_table.home,
|
||||
},
|
||||
show_parent = menu_container,
|
||||
|
||||
@@ -281,7 +281,7 @@ function ReaderHighlight:translate(selected_text)
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderHighlight:onHoldRelease(arg, ges)
|
||||
function ReaderHighlight:onHoldRelease()
|
||||
if self.selected_word then
|
||||
self:lookup(self.selected_word)
|
||||
self.selected_word = nil
|
||||
@@ -347,6 +347,16 @@ function ReaderHighlight:onHoldRelease(arg, ges)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderHighlight:onHighlight()
|
||||
if self.hold_pos then
|
||||
if not self.selected_text then
|
||||
self.selected_text = self.ui.document:getTextFromPositions(self.hold_pos, self.hold_pos)
|
||||
DEBUG("selected text:", self.selected_text)
|
||||
end
|
||||
self:saveHighlight()
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderHighlight:saveHighlight()
|
||||
DEBUG("save highlight")
|
||||
local page = self.hold_pos.page
|
||||
|
||||
@@ -27,18 +27,15 @@ local CreDocument = Document:new{
|
||||
}
|
||||
|
||||
-- NuPogodi, 20.05.12: inspect the zipfile content
|
||||
function CreDocument.zipContentExt(self, fname)
|
||||
local outfile = "./data/zip_content"
|
||||
local s = ""
|
||||
os.execute("unzip ".."-l \""..fname.."\" > "..outfile)
|
||||
local i = 1
|
||||
if io.open(outfile,"r") then
|
||||
for lines in io.lines(outfile) do
|
||||
if i == 4 then s = lines break else i = i + 1 end
|
||||
function CreDocument:zipContentExt(fname)
|
||||
local std_out = io.popen("unzip ".."-qql \""..fname.."\"")
|
||||
if std_out then
|
||||
for line in std_out:lines() do
|
||||
local size, ext = string.match(line, "%s+(%d+)%s+.+%.([^.]+)")
|
||||
-- return the extention
|
||||
if size and ext then return string.lower(ext) end
|
||||
end
|
||||
end
|
||||
-- return the extention
|
||||
return string.lower(string.match(s, ".+%.([^.]+)"))
|
||||
end
|
||||
|
||||
function CreDocument:cacheInit()
|
||||
@@ -82,7 +79,7 @@ function CreDocument:init()
|
||||
if file_type == "zip" then
|
||||
-- NuPogodi, 20.05.12: read the content of zip-file
|
||||
-- and return extention of the 1st file
|
||||
file_type = self:zipContentExt(self.file)
|
||||
file_type = self:zipContentExt(self.file) or "unknown"
|
||||
end
|
||||
-- these two format use the same css file
|
||||
if file_type == "html" then
|
||||
@@ -100,7 +97,7 @@ function CreDocument:init()
|
||||
Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE
|
||||
)
|
||||
if not ok then
|
||||
self.error_message = self.doc -- will contain error message
|
||||
self.error_message = self._document -- will contain error message
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ function DjvuDocument:init()
|
||||
local ok
|
||||
ok, self._document = pcall(djvu.openDocument, self.file, self.djvulibre_cache_size)
|
||||
if not ok then
|
||||
self.error_message = self.doc -- will contain error message
|
||||
self.error_message = self._document -- will contain error message
|
||||
return
|
||||
end
|
||||
self.is_open = true
|
||||
@@ -46,16 +46,6 @@ function DjvuDocument:init()
|
||||
self:_readMetadata()
|
||||
end
|
||||
|
||||
function DjvuDocument:invertTextYAxel(pageno, text_table)
|
||||
local _, height = self.doc:getOriginalPageSize(pageno)
|
||||
for _,text in pairs(text_table) do
|
||||
for _,line in ipairs(text) do
|
||||
line.y0, line.y1 = (height - line.y1), (height - line.y0)
|
||||
end
|
||||
end
|
||||
return text_table
|
||||
end
|
||||
|
||||
function DjvuDocument:getPageTextBoxes(pageno)
|
||||
return self._document:getPageText(pageno)
|
||||
end
|
||||
|
||||
@@ -56,7 +56,7 @@ function PdfDocument:init()
|
||||
local ok
|
||||
ok, self._document = pcall(pdf.openDocument, self.file, self.mupdf_cache_size)
|
||||
if not ok then
|
||||
self.error_message = self.doc -- will contain error message
|
||||
self.error_message = self._document -- will contain error message
|
||||
return
|
||||
end
|
||||
self.is_open = true
|
||||
|
||||
@@ -167,7 +167,8 @@ function Screen:setDPI(dpi)
|
||||
end
|
||||
|
||||
function Screen:scaleByDPI(px)
|
||||
return math.floor(px * self:getDPI()/167)
|
||||
-- scaled positive px should also be positive
|
||||
return math.ceil(px * self:getDPI()/167)
|
||||
end
|
||||
|
||||
function Screen:rescaleByDPI(px)
|
||||
|
||||
@@ -132,6 +132,12 @@ function DictQuickLookup:update()
|
||||
self:changeToPrevDict()
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Highlight"),
|
||||
callback = function()
|
||||
self.ui:handleEvent(Event:new("Highlight"))
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = ">>",
|
||||
enabled = self:isNextDictAvaiable(),
|
||||
@@ -142,17 +148,24 @@ function DictQuickLookup:update()
|
||||
},
|
||||
{
|
||||
{
|
||||
text = _("Highlight"),
|
||||
text = _("Wikipedia"),
|
||||
enabled = false,
|
||||
callback = function()
|
||||
self.ui:handleEvent(Event:new("Highlight"))
|
||||
self.ui:handleEvent(Event:new("HighlightWiki"))
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Add Note"),
|
||||
enabled = false,
|
||||
callback = function()
|
||||
self.ui:handleEvent(Event:new("AddNote"))
|
||||
self.ui:handleEvent(Event:new("HighlightAddNote"))
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("More"),
|
||||
enabled = false,
|
||||
callback = function()
|
||||
self.ui:handleEvent(Event:new("HighlightMore"))
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -100,7 +100,7 @@ if [ -f "${NEWUPDATE}" ] ; then
|
||||
if [ $? -eq 0 ] ; then
|
||||
rm "${NEWUPDATE}"
|
||||
logmsg "Update sucessful :)"
|
||||
eips_print_bottom_centered "Update sucessful :)" 1
|
||||
eips_print_bottom_centered "Update successful :)" 1
|
||||
else
|
||||
# Huh ho...
|
||||
logmsg "Update failed :("
|
||||
|
||||
Reference in New Issue
Block a user