2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local Geom = require("ui/geometry")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
|
|
|
local Device = require("device")
|
2013-10-22 15:11:31 +00:00
|
|
|
local Event = require("ui/event")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2014-01-22 18:03:44 +00:00
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
2013-10-22 18:51:29 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2013-04-23 22:59:52 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderHighlight = InputContainer:new{}
|
2013-04-23 22:59:52 +00:00
|
|
|
|
|
|
|
function ReaderHighlight:init()
|
2014-10-09 09:41:23 +00:00
|
|
|
self.ui:registerPostInitCallback(function()
|
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end)
|
2013-04-23 22:59:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:initGesListener()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ges_events = {
|
|
|
|
Tap = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Hold = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
HoldRelease = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold_release",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
HoldPan = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold_pan",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight()
|
|
|
|
},
|
|
|
|
rate = 2.0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2013-04-23 22:59:52 +00:00
|
|
|
end
|
|
|
|
|
2014-01-17 19:05:17 +00:00
|
|
|
function ReaderHighlight:addToMainMenu(tab_item_table)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- insert table to main reader menu
|
|
|
|
table.insert(tab_item_table.typeset, {
|
2014-11-06 03:07:48 +00:00
|
|
|
text = _("Highlight"),
|
2014-03-13 13:52:43 +00:00
|
|
|
sub_item_table = self:genHighlightDrawerMenu(),
|
|
|
|
})
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
2014-11-06 03:07:48 +00:00
|
|
|
local highlight_style = {
|
|
|
|
lighten = _("Lighten"),
|
|
|
|
underscore = _("Underscore"),
|
|
|
|
invert = _("Invert"),
|
|
|
|
}
|
|
|
|
|
2014-01-17 19:05:17 +00:00
|
|
|
function ReaderHighlight:genHighlightDrawerMenu()
|
2014-11-06 03:07:48 +00:00
|
|
|
local get_highlight_style = function(style)
|
|
|
|
return {
|
|
|
|
text = highlight_style[style],
|
2014-06-08 06:02:22 +00:00
|
|
|
checked_func = function()
|
2014-11-06 03:07:48 +00:00
|
|
|
return self.view.highlight.saved_drawer == style
|
2014-05-28 11:45:01 +00:00
|
|
|
end,
|
2014-11-06 03:07:48 +00:00
|
|
|
enabled_func = function()
|
|
|
|
return not self.view.highlight.disabled
|
2014-05-28 11:45:01 +00:00
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2014-11-06 03:07:48 +00:00
|
|
|
self.view.highlight.saved_drawer = style
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-11-06 03:07:48 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
return {
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
2014-11-06 03:07:48 +00:00
|
|
|
text_func = function()
|
|
|
|
return self.view.highlight.disabled and _("Enable") or _("Disable")
|
2014-05-28 11:45:01 +00:00
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2014-11-06 03:07:48 +00:00
|
|
|
self.view.highlight.disabled = not self.view.highlight.disabled
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
},
|
2014-11-06 03:07:48 +00:00
|
|
|
get_highlight_style("lighten"),
|
|
|
|
get_highlight_style("underscore"),
|
|
|
|
get_highlight_style("invert"),
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
2013-04-23 22:59:52 +00:00
|
|
|
function ReaderHighlight:onSetDimensions(dimen)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- update listening according to new screen dimen
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self:initGesListener()
|
|
|
|
end
|
2013-04-23 22:59:52 +00:00
|
|
|
end
|
|
|
|
|
2014-08-26 12:29:53 +00:00
|
|
|
function ReaderHighlight:clear()
|
2014-11-05 04:28:11 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
self.view.highlight.temp = {}
|
|
|
|
else
|
|
|
|
self.ui.document:clearSelection()
|
|
|
|
end
|
2014-11-12 14:49:01 +00:00
|
|
|
UIManager:setDirty(self.dialog, "full")
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.hold_pos then
|
|
|
|
self.hold_pos = nil
|
2014-07-02 09:46:17 +00:00
|
|
|
self.selected_text = nil
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
|
|
|
end
|
2014-08-26 12:29:53 +00:00
|
|
|
end
|
|
|
|
|
2014-11-05 04:28:11 +00:00
|
|
|
function ReaderHighlight:onClearHighlight()
|
|
|
|
self:clear()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-08-26 12:29:53 +00:00
|
|
|
function ReaderHighlight:onTap(arg, ges)
|
|
|
|
if not self:clear() then
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
return self:onTapPageSavedHighlight(ges)
|
|
|
|
else
|
|
|
|
return self:onTapXPointerSavedHighlight(ges)
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function inside_box(pos, box)
|
2014-03-13 13:52:43 +00:00
|
|
|
if pos then
|
|
|
|
local x, y = pos.x, pos.y
|
2014-05-28 11:45:01 +00:00
|
|
|
if box.x <= x and box.y <= y
|
|
|
|
and box.x + box.w >= x
|
2014-03-13 13:52:43 +00:00
|
|
|
and box.y + box.h >= y then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:onTapPageSavedHighlight(ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
local pages = self.view:getCurrentPageList()
|
|
|
|
local pos = self.view:screenToPageTransform(ges.pos)
|
|
|
|
for key, page in pairs(pages) do
|
|
|
|
local items = self.view.highlight.saved[page]
|
|
|
|
if not items then items = {} end
|
|
|
|
for i = 1, #items do
|
|
|
|
local pos0, pos1 = items[i].pos0, items[i].pos1
|
|
|
|
local boxes = self.ui.document:getPageBoxesFromPositions(page, pos0, pos1)
|
|
|
|
if boxes then
|
|
|
|
for index, box in pairs(boxes) do
|
|
|
|
if inside_box(pos, box) then
|
|
|
|
DEBUG("Tap on hightlight")
|
|
|
|
return self:onShowHighlightDialog(page, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:onTapXPointerSavedHighlight(ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
local pos = self.view:screenToPageTransform(ges.pos)
|
|
|
|
for page, _ in pairs(self.view.highlight.saved) do
|
|
|
|
local items = self.view.highlight.saved[page]
|
|
|
|
if not items then items = {} end
|
|
|
|
for i = 1, #items do
|
|
|
|
local pos0, pos1 = items[i].pos0, items[i].pos1
|
|
|
|
local boxes = self.ui.document:getScreenBoxesFromPositions(pos0, pos1)
|
|
|
|
if boxes then
|
|
|
|
for index, box in pairs(boxes) do
|
|
|
|
if inside_box(pos, box) then
|
|
|
|
DEBUG("Tap on hightlight")
|
|
|
|
return self:onShowHighlightDialog(page, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-04-23 22:59:52 +00:00
|
|
|
end
|
|
|
|
|
2014-01-17 19:05:17 +00:00
|
|
|
function ReaderHighlight:onShowHighlightDialog(page, index)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.edit_highlight_dialog = ButtonDialog:new{
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Delete"),
|
|
|
|
callback = function()
|
|
|
|
self:deleteHighlight(page, index)
|
|
|
|
UIManager:close(self.edit_highlight_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Edit"),
|
|
|
|
enabled = false,
|
|
|
|
callback = function()
|
|
|
|
self:editHighlight()
|
|
|
|
UIManager:close(self.edit_highlight_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(self.edit_highlight_dialog)
|
|
|
|
return true
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
2013-04-23 22:59:52 +00:00
|
|
|
function ReaderHighlight:onHold(arg, ges)
|
2014-11-06 03:07:48 +00:00
|
|
|
-- disable hold gesture if highlighting is disabled
|
|
|
|
if self.view.highlight.disabled then return true end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.hold_pos = self.view:screenToPageTransform(ges.pos)
|
|
|
|
DEBUG("hold position in page", self.hold_pos)
|
|
|
|
if not self.hold_pos then
|
|
|
|
DEBUG("not inside page area")
|
|
|
|
return true
|
|
|
|
end
|
2013-10-12 15:07:13 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
local ok, word = pcall(self.ui.document.getWordFromPosition, self.ui.document, self.hold_pos)
|
|
|
|
if ok and word then
|
|
|
|
DEBUG("selected word:", word)
|
|
|
|
self.selected_word = word
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
local boxes = {}
|
|
|
|
table.insert(boxes, self.selected_word.sbox)
|
|
|
|
self.view.highlight.temp[self.hold_pos.page] = boxes
|
|
|
|
end
|
2014-11-11 01:15:08 +00:00
|
|
|
--[[
|
|
|
|
UIManager.update_regions_func = function()
|
|
|
|
DEBUG("update ReaderHighlight onHold region", self.selected_word.sbox)
|
|
|
|
return {self.selected_word.sbox}
|
|
|
|
end
|
|
|
|
--]]
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:setDirty(self.dialog, "partial")
|
|
|
|
end
|
|
|
|
return true
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:onHoldPan(arg, ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.hold_pos == nil then
|
|
|
|
DEBUG("no previous hold position")
|
|
|
|
return true
|
|
|
|
end
|
2014-07-02 08:38:09 +00:00
|
|
|
local page_area = self.view:getScreenPageArea(self.hold_pos.page)
|
|
|
|
DEBUG("current page area", page_area)
|
|
|
|
if ges.pos:notIntersectWith(page_area) then
|
|
|
|
DEBUG("not inside page area")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.holdpan_pos = self.view:screenToPageTransform(ges.pos)
|
|
|
|
DEBUG("holdpan position in page", self.holdpan_pos)
|
|
|
|
self.selected_text = self.ui.document:getTextFromPositions(self.hold_pos, self.holdpan_pos)
|
|
|
|
DEBUG("selected text:", self.selected_text)
|
|
|
|
if self.selected_text then
|
|
|
|
self.view.highlight.temp[self.hold_pos.page] = self.selected_text.sboxes
|
|
|
|
-- remove selected word if hold moves out of word box
|
|
|
|
if not self.selected_text.sboxes or #self.selected_text.sboxes == 0 then
|
|
|
|
self.selected_word = nil
|
|
|
|
elseif self.selected_word and not self.selected_word.sbox:contains(self.selected_text.sboxes[1]) or
|
|
|
|
#self.selected_text.sboxes > 1 then
|
|
|
|
self.selected_word = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
UIManager:setDirty(self.dialog, "partial")
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
|
|
|
|
2013-07-19 18:49:03 +00:00
|
|
|
function ReaderHighlight:lookup(selected_word)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- if we extracted text directly
|
|
|
|
if selected_word.word then
|
|
|
|
local word_box = self.view:pageToScreenTransform(self.hold_pos.page, selected_word.sbox)
|
2014-08-17 16:32:09 +00:00
|
|
|
self.ui:handleEvent(Event:new("LookupWord", selected_word.word, word_box, self))
|
2014-03-13 13:52:43 +00:00
|
|
|
-- or we will do OCR
|
|
|
|
elseif selected_word.sbox and self.hold_pos then
|
|
|
|
local word = self.ui.document:getOCRWord(self.hold_pos.page, selected_word)
|
|
|
|
DEBUG("OCRed word:", word)
|
|
|
|
local word_box = self.view:pageToScreenTransform(self.hold_pos.page, selected_word.sbox)
|
2014-08-17 16:32:09 +00:00
|
|
|
self.ui:handleEvent(Event:new("LookupWord", word, word_box, self))
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-07-19 18:49:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:translate(selected_text)
|
2014-03-13 13:52:43 +00:00
|
|
|
if selected_text.text ~= "" then
|
|
|
|
self.ui:handleEvent(Event:new("TranslateText", self, selected_text.text))
|
|
|
|
-- or we will do OCR
|
|
|
|
else
|
|
|
|
local text = self.ui.document:getOCRText(self.hold_pos.page, selected_text)
|
|
|
|
DEBUG("OCRed text:", text)
|
|
|
|
self.ui:handleEvent(Event:new("TranslateText", self, text))
|
|
|
|
end
|
2013-07-19 18:49:03 +00:00
|
|
|
end
|
|
|
|
|
2014-08-11 13:49:42 +00:00
|
|
|
function ReaderHighlight:onHoldRelease()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.selected_word then
|
|
|
|
self:lookup(self.selected_word)
|
|
|
|
self.selected_word = nil
|
|
|
|
elseif self.selected_text then
|
|
|
|
DEBUG("show highlight dialog")
|
|
|
|
self.highlight_dialog = ButtonDialog:new{
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Highlight"),
|
|
|
|
callback = function()
|
|
|
|
self:saveHighlight()
|
2014-08-20 06:41:45 +00:00
|
|
|
self:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Add Note"),
|
|
|
|
enabled = false,
|
|
|
|
callback = function()
|
|
|
|
self:addNote()
|
2014-08-20 06:41:45 +00:00
|
|
|
self:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2014-08-20 06:41:45 +00:00
|
|
|
{
|
|
|
|
text = _("Wikipedia"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
self:lookupWikipedia()
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
|
|
|
text = _("Translate"),
|
2014-06-10 07:57:10 +00:00
|
|
|
enabled = false,
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
|
|
|
self:translate(self.selected_text)
|
2014-08-20 06:41:45 +00:00
|
|
|
self:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
2014-08-20 06:41:45 +00:00
|
|
|
},
|
|
|
|
{
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
2014-11-05 04:28:11 +00:00
|
|
|
text = _("Search"),
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2014-11-05 04:28:11 +00:00
|
|
|
self:onHighlightSearch()
|
|
|
|
UIManager:close(self.highlight_dialog)
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("More"),
|
|
|
|
enabled = false,
|
|
|
|
callback = function()
|
|
|
|
self:moreAction()
|
2014-08-20 06:41:45 +00:00
|
|
|
self:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tap_close_callback = function() self:handleEvent(Event:new("Tap")) end,
|
|
|
|
}
|
|
|
|
UIManager:show(self.highlight_dialog)
|
|
|
|
end
|
|
|
|
return true
|
2013-04-23 22:59:52 +00:00
|
|
|
end
|
|
|
|
|
2014-11-05 04:28:11 +00:00
|
|
|
function ReaderHighlight:highlightFromHoldPos()
|
2014-08-11 13:49:42 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-05 04:28:11 +00:00
|
|
|
function ReaderHighlight:onHighlight()
|
|
|
|
self:highlightFromHoldPos()
|
|
|
|
self:saveHighlight()
|
|
|
|
end
|
|
|
|
|
2013-06-15 15:13:19 +00:00
|
|
|
function ReaderHighlight:saveHighlight()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("save highlight")
|
|
|
|
local page = self.hold_pos.page
|
|
|
|
if self.hold_pos and self.selected_text then
|
|
|
|
if not self.view.highlight.saved[page] then
|
|
|
|
self.view.highlight.saved[page] = {}
|
|
|
|
end
|
|
|
|
local hl_item = {}
|
|
|
|
hl_item["text"] = self.selected_text.text
|
|
|
|
hl_item["pos0"] = self.selected_text.pos0
|
|
|
|
hl_item["pos1"] = self.selected_text.pos1
|
|
|
|
hl_item["pboxes"] = self.selected_text.pboxes
|
|
|
|
hl_item["datetime"] = os.date("%Y-%m-%d %H:%M:%S")
|
|
|
|
hl_item["drawer"] = self.view.highlight.saved_drawer
|
|
|
|
table.insert(self.view.highlight.saved[page], hl_item)
|
2014-11-21 10:32:43 +00:00
|
|
|
--[[
|
|
|
|
-- disable exporting hightlights to My Clippings
|
|
|
|
-- since it's not portable and there is a better Evernote plugin
|
|
|
|
-- to do the same thing
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.selected_text.text ~= "" then
|
2014-11-21 10:32:43 +00:00
|
|
|
self:exportToClippings(page, hl_item)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-11-21 10:32:43 +00:00
|
|
|
--]]
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.selected_text.pboxes then
|
|
|
|
self:exportToDocument(page, hl_item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--DEBUG("saved hightlights", self.view.highlight.saved[page])
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
|
|
|
|
2014-11-21 10:32:43 +00:00
|
|
|
--[[
|
2013-06-16 11:00:15 +00:00
|
|
|
function ReaderHighlight:exportToClippings(page, item)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("export highlight to clippings", item)
|
|
|
|
local clippings = io.open("/mnt/us/documents/My Clippings.txt", "a+")
|
|
|
|
if clippings and item.text then
|
|
|
|
local current_locale = os.setlocale()
|
|
|
|
os.setlocale("C")
|
|
|
|
clippings:write(self.document.file:gsub("(.*/)(.*)", "%2").."\n")
|
|
|
|
clippings:write("- Koreader Highlight Page "..page.." ")
|
|
|
|
clippings:write("| Added on "..os.date("%A, %b %d, %Y %I:%M:%S %p\n\n"))
|
2014-05-12 12:32:17 +00:00
|
|
|
-- My Clippings only holds one line of highlight
|
|
|
|
clippings:write(item["text"]:gsub("\n", " ").."\n")
|
2014-03-13 13:52:43 +00:00
|
|
|
clippings:write("==========\n")
|
|
|
|
clippings:close()
|
|
|
|
os.setlocale(current_locale)
|
|
|
|
end
|
2013-06-16 11:00:15 +00:00
|
|
|
end
|
2014-11-21 10:32:43 +00:00
|
|
|
--]]
|
2013-06-16 11:00:15 +00:00
|
|
|
|
2014-02-01 16:16:51 +00:00
|
|
|
function ReaderHighlight:exportToDocument(page, item)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("export highlight to document", item)
|
|
|
|
self.ui.document:saveHighlight(page, item)
|
2014-02-01 16:16:51 +00:00
|
|
|
end
|
|
|
|
|
2013-06-15 15:13:19 +00:00
|
|
|
function ReaderHighlight:addNote()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("add Note")
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
|
|
|
|
2014-08-20 06:41:45 +00:00
|
|
|
function ReaderHighlight:lookupWikipedia()
|
|
|
|
if self.selected_text then
|
|
|
|
self.ui:handleEvent(Event:new("LookupWikipedia", self.selected_text.text))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-05 04:28:11 +00:00
|
|
|
function ReaderHighlight:onHighlightSearch()
|
|
|
|
DEBUG("search highlight")
|
|
|
|
self:highlightFromHoldPos()
|
|
|
|
if self.selected_text then
|
|
|
|
self.ui:handleEvent(Event:new("ShowSearchDialog", self.selected_text.text))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-15 15:13:19 +00:00
|
|
|
function ReaderHighlight:shareHighlight()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("share highlight")
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:moreAction()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("more action")
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:deleteHighlight(page, i)
|
2014-05-28 11:45:01 +00:00
|
|
|
DEBUG("delete highlight")
|
2014-03-13 13:52:43 +00:00
|
|
|
table.remove(self.view.highlight.saved[page], i)
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:editHighlight()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("edit highlight")
|
2013-06-15 15:13:19 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2014-01-17 19:05:17 +00:00
|
|
|
function ReaderHighlight:onReadSettings(config)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.highlight.saved_drawer = config:readSetting("highlight_drawer") or self.view.highlight.saved_drawer
|
2014-11-06 03:07:48 +00:00
|
|
|
self.view.highlight.disabled = config:readSetting("highlight_disabled") or false
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderHighlight:onSaveSettings()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer)
|
2014-11-06 03:07:48 +00:00
|
|
|
self.ui.doc_settings:saveSetting("highlight_disabled", self.view.highlight.disabled)
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
2014-08-20 06:41:45 +00:00
|
|
|
function ReaderHighlight:onClose()
|
|
|
|
UIManager:close(self.highlight_dialog)
|
|
|
|
-- clear highlighted text
|
2014-08-26 12:29:53 +00:00
|
|
|
self:clear()
|
2014-08-20 06:41:45 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderHighlight
|