disable highlight in dict window if it's highlighted already

This should fix #1418.
pull/1448/head
chrox 9 years ago
parent 2ad21dcaa2
commit 90a5e09bdc

@ -297,6 +297,23 @@ function ReaderBookmark:addBookmark(item)
table.insert(self.bookmarks, _middle + direction, item) table.insert(self.bookmarks, _middle + direction, item)
end end
-- binary search of sorted bookmarks
function ReaderBookmark:isBookmarkAdded(item)
local _start, _middle, _end, direction = 1, 1, #self.bookmarks, 0
while _start <= _end do
local v = self.bookmarks[_middle]
_middle = math.floor((_start + _end)/2)
if self:isBookmarkSame(item, self.bookmarks[_middle]) then
return true
end
if self:isBookmarkInPageOrder(item, self.bookmarks[_middle]) then
_end, direction = _middle - 1, 0
else
_start, direction = _middle + 1, 1
end
end
end
-- binary search to remove bookmark -- binary search to remove bookmark
function ReaderBookmark:removeBookmark(item) function ReaderBookmark:removeBookmark(item)
local _start, _middle, _end = 1, 1, #self.bookmarks local _start, _middle, _end = 1, 1, #self.bookmarks

@ -385,10 +385,28 @@ function ReaderHighlight:highlightFromHoldPos()
end end
function ReaderHighlight:onHighlight() function ReaderHighlight:onHighlight()
self:highlightFromHoldPos()
self:saveHighlight() self:saveHighlight()
end end
function ReaderHighlight:getHighlightBookmarkItem()
if self.hold_pos and not self.selected_text then
self:highlightFromHoldPos()
end
if self.selected_text and self.selected_text.pos0 and self.selected_text.pos1 then
local datetime = os.date("%Y-%m-%d %H:%M:%S")
local page = self.ui.document.info.has_pages and
self.hold_pos.page or self.selected_text.pos0
return {
page = page,
pos0 = self.selected_text.pos0,
pos1 = self.selected_text.pos1,
datetime = datetime,
notes = self.selected_text.text,
highlighted = true,
}
end
end
function ReaderHighlight:saveHighlight() function ReaderHighlight:saveHighlight()
DEBUG("save highlight") DEBUG("save highlight")
local page = self.hold_pos.page local page = self.hold_pos.page
@ -407,14 +425,10 @@ function ReaderHighlight:saveHighlight()
drawer = self.view.highlight.saved_drawer, drawer = self.view.highlight.saved_drawer,
} }
table.insert(self.view.highlight.saved[page], hl_item) table.insert(self.view.highlight.saved[page], hl_item)
self.ui.bookmark:addBookmark({ local bookmark_item = self:getHighlightBookmarkItem()
page = self.ui.document.info.has_pages and page or self.selected_text.pos0, if bookmark_item then
pos0 = self.selected_text.pos0, self.ui.bookmark:addBookmark(bookmark_item)
pos1 = self.selected_text.pos1, end
datetime = datetime,
notes = self.selected_text.text,
highlighted = true,
})
--[[ --[[
-- disable exporting hightlights to My Clippings -- disable exporting hightlights to My Clippings
-- since it's not portable and there is a better Evernote plugin -- since it's not portable and there is a better Evernote plugin

@ -158,9 +158,11 @@ function DictQuickLookup:update()
end, end,
}, },
{ {
text = _("Highlight"), text = self:getHighlightText(),
enabled = select(2, self:getHighlightText()),
callback = function() callback = function()
self.ui:handleEvent(Event:new("Highlight")) self.ui:handleEvent(Event:new("Highlight"))
self:update()
end, end,
}, },
{ {
@ -279,6 +281,21 @@ function DictQuickLookup:onShow()
return true return true
end end
function DictQuickLookup:getHighlightedItem()
return self.ui.highlight:getHighlightBookmarkItem()
end
function DictQuickLookup:getHighlightText()
local item = self:getHighlightedItem()
if not item then
return _("Highlight"), false
elseif self.ui.bookmark:isBookmarkAdded(item) then
return _("Unhighlight"), false
else
return _("Highlight"), true
end
end
function DictQuickLookup:isPrevDictAvaiable() function DictQuickLookup:isPrevDictAvaiable()
return self.dict_index > 1 return self.dict_index > 1
end end

Loading…
Cancel
Save