2017-04-29 08:38:09 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local Button = require("ui/widget/button")
|
|
|
|
local ButtonTable = require("ui/widget/buttontable")
|
2013-10-18 20:38:07 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2013-12-26 14:40:40 +00:00
|
|
|
local CloseButton = require("ui/widget/closebutton")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2014-08-17 16:32:09 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local Font = require("ui/font")
|
2017-04-29 08:38:09 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local LeftContainer = require("ui/widget/container/leftcontainer")
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
2018-01-29 20:27:24 +00:00
|
|
|
local MovableContainer = require("ui/widget/container/movablecontainer")
|
2017-04-29 08:38:09 +00:00
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
2018-01-07 19:24:15 +00:00
|
|
|
local ScrollHtmlWidget = require("ui/widget/scrollhtmlwidget")
|
2017-04-29 08:38:09 +00:00
|
|
|
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-04-29 08:38:09 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2017-04-29 08:38:09 +00:00
|
|
|
local util = require("util")
|
2013-10-22 15:11:31 +00:00
|
|
|
local _ = require("gettext")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Screen = Device.screen
|
2016-12-06 21:15:52 +00:00
|
|
|
local T = require("ffi/util").template
|
2013-04-24 14:57:03 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
Display quick lookup word definition
|
|
|
|
]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local DictQuickLookup = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
results = nil,
|
|
|
|
lookupword = nil,
|
|
|
|
dictionary = nil,
|
|
|
|
definition = nil,
|
2016-12-06 21:15:52 +00:00
|
|
|
displayword = nil,
|
2018-01-16 11:32:49 +00:00
|
|
|
images = nil,
|
2016-12-06 21:15:52 +00:00
|
|
|
is_wiki = false,
|
|
|
|
is_fullpage = false,
|
2018-01-07 19:24:15 +00:00
|
|
|
is_html = false,
|
2014-03-13 13:52:43 +00:00
|
|
|
dict_index = 1,
|
2017-04-29 08:38:09 +00:00
|
|
|
title_face = Font:getFace("x_smalltfont"),
|
2014-03-13 13:52:43 +00:00
|
|
|
content_face = Font:getFace("cfont", DDICT_FONT_SIZE),
|
2018-01-16 11:32:49 +00:00
|
|
|
image_alt_face = Font:getFace("cfont", DDICT_FONT_SIZE-4),
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
2014-08-20 06:41:45 +00:00
|
|
|
-- box of highlighted word, quick lookup window tries to not hide the word
|
|
|
|
word_box = nil,
|
2014-05-01 10:37:12 +00:00
|
|
|
|
2017-09-13 14:56:20 +00:00
|
|
|
title_padding = Size.padding.default,
|
|
|
|
title_margin = Size.margin.title,
|
|
|
|
word_padding = Size.padding.default,
|
|
|
|
word_margin = Size.margin.default,
|
2016-12-06 21:15:52 +00:00
|
|
|
-- alt padding/margin for wiki to compensate for reduced font size
|
|
|
|
wiki_word_padding = Screen:scaleBySize(7),
|
|
|
|
wiki_word_margin = Screen:scaleBySize(3),
|
2014-11-20 22:07:39 +00:00
|
|
|
definition_padding = Screen:scaleBySize(2),
|
|
|
|
definition_margin = Screen:scaleBySize(2),
|
|
|
|
button_padding = Screen:scaleBySize(14),
|
2017-03-24 07:20:37 +00:00
|
|
|
-- refresh_callback will be called before we trigger full refresh in onSwipe
|
|
|
|
refresh_callback = nil,
|
2018-01-15 22:51:43 +00:00
|
|
|
html_dictionary_link_tapped_callback = nil,
|
2013-04-24 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 21:17:35 +00:00
|
|
|
local highlight_strings = {
|
|
|
|
highlight =_("Highlight"),
|
|
|
|
unhighlight = _("Unhighlight"),
|
|
|
|
}
|
|
|
|
|
2013-04-24 14:57:03 +00:00
|
|
|
function DictQuickLookup:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self:changeToDefaultDict()
|
2014-06-10 07:57:10 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events = {
|
|
|
|
Close = { {"Back"}, doc = "close quick lookup" }
|
|
|
|
}
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
if Device:isTouchDevice() then
|
2018-03-05 20:27:55 +00:00
|
|
|
local range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ges_events = {
|
|
|
|
TapCloseDict = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Swipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
-- This was for selection of a single word with simple hold
|
|
|
|
-- HoldWord = {
|
|
|
|
-- GestureRange:new{
|
|
|
|
-- ges = "hold",
|
|
|
|
-- range = function()
|
|
|
|
-- return self.region
|
|
|
|
-- end,
|
|
|
|
-- },
|
|
|
|
-- -- callback function when HoldWord is handled as args
|
|
|
|
-- args = function(word)
|
|
|
|
-- self.ui:handleEvent(
|
|
|
|
-- -- don't pass self.highlight to subsequent lookup, we want
|
|
|
|
-- -- the first to be the only one to unhighlight selection
|
|
|
|
-- -- when closed
|
|
|
|
-- Event:new("LookupWord", word, self.word_box))
|
|
|
|
-- end
|
|
|
|
-- },
|
|
|
|
-- Allow selection of one or more words (see textboxwidget.lua) :
|
|
|
|
HoldStartText = {
|
2015-10-18 12:46:22 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2015-10-18 12:46:22 +00:00
|
|
|
},
|
2018-03-07 14:59:59 +00:00
|
|
|
},
|
|
|
|
HoldPanText = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = range,
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
},
|
|
|
|
HoldReleaseText = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold_release",
|
2018-03-05 20:27:55 +00:00
|
|
|
range = range,
|
2016-12-06 21:15:52 +00:00
|
|
|
},
|
|
|
|
-- callback function when HoldReleaseText is handled as args
|
|
|
|
args = function(text, hold_duration)
|
|
|
|
local lookup_target
|
2018-03-05 20:27:55 +00:00
|
|
|
if hold_duration < 3.0 then
|
2016-12-06 21:15:52 +00:00
|
|
|
-- do this lookup in the same domain (dict/wikipedia)
|
|
|
|
lookup_target = self.is_wiki and "LookupWikipedia" or "LookupWord"
|
|
|
|
else
|
|
|
|
-- but allow switching domain with a long hold
|
|
|
|
lookup_target = self.is_wiki and "LookupWord" or "LookupWikipedia"
|
|
|
|
end
|
2017-01-01 09:34:21 +00:00
|
|
|
if lookup_target == "LookupWikipedia" then
|
|
|
|
self:resyncWikiLanguages()
|
|
|
|
end
|
2016-06-05 07:08:23 +00:00
|
|
|
self.ui:handleEvent(
|
2016-12-06 21:15:52 +00:00
|
|
|
-- don't pass self.highlight to subsequent lookup, we want
|
|
|
|
-- the first to be the only one to unhighlight selection
|
|
|
|
-- when closed
|
|
|
|
Event:new(lookup_target, text)
|
|
|
|
)
|
2015-10-18 12:46:22 +00:00
|
|
|
end
|
|
|
|
},
|
2018-03-07 14:59:59 +00:00
|
|
|
-- These will be forwarded to MovableContainer after some checks
|
2018-03-05 20:27:55 +00:00
|
|
|
ForwardingTouch = { GestureRange:new{ ges = "touch", range = range, }, },
|
|
|
|
ForwardingPan = { GestureRange:new{ ges = "pan", range = range, }, },
|
|
|
|
ForwardingPanRelease = { GestureRange:new{ ges = "pan_release", range = range, }, },
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
2017-01-02 18:12:34 +00:00
|
|
|
-- Whether currently DictQuickLookup is working without a document.
|
|
|
|
function DictQuickLookup:isDocless()
|
|
|
|
return self.ui == nil or self.ui.highlight == nil
|
|
|
|
end
|
|
|
|
|
2018-01-07 19:24:15 +00:00
|
|
|
function DictQuickLookup:getHtmlDictionaryCss()
|
|
|
|
-- Using Noto Sans because Nimbus doesn't contain the IPA symbols.
|
2018-01-08 15:16:39 +00:00
|
|
|
-- 'line-height: 1.3' to have it similar to textboxwidget,
|
|
|
|
-- and follow user's choice on justification
|
|
|
|
local css_justify = G_reader_settings:nilOrTrue("dict_justify") and "text-align: justify;" or ""
|
2018-01-07 19:24:15 +00:00
|
|
|
local css = [[
|
|
|
|
@page {
|
|
|
|
margin: 0;
|
|
|
|
font-family: 'Noto Sans';
|
|
|
|
}
|
|
|
|
|
|
|
|
body {
|
|
|
|
margin: 0;
|
2018-01-08 15:16:39 +00:00
|
|
|
line-height: 1.3;
|
|
|
|
]]..css_justify..[[
|
2018-01-07 19:24:15 +00:00
|
|
|
}
|
|
|
|
]]
|
|
|
|
|
|
|
|
if self.css then
|
|
|
|
return css .. self.css
|
|
|
|
end
|
|
|
|
return css
|
|
|
|
end
|
|
|
|
|
2013-07-21 06:23:54 +00:00
|
|
|
function DictQuickLookup:update()
|
2014-11-30 17:57:41 +00:00
|
|
|
local orig_dimen = self.dict_frame and self.dict_frame.dimen or Geom:new{}
|
2018-01-29 20:27:24 +00:00
|
|
|
local orig_moved_offset = self.movable and self.movable:getMovedOffset()
|
2018-01-16 11:32:49 +00:00
|
|
|
-- Free our previous widget and subwidgets' resources (especially
|
|
|
|
-- definitions' TextBoxWidget bb, HtmlBoxWidget bb and MuPDF instance,
|
|
|
|
-- and scheduled image_update_action)
|
|
|
|
if self[1] then
|
|
|
|
self[1]:free()
|
|
|
|
end
|
2016-12-06 21:15:52 +00:00
|
|
|
-- calculate window dimension
|
2014-08-20 06:41:45 +00:00
|
|
|
self.align = "center"
|
|
|
|
self.region = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
2017-11-20 08:40:00 +00:00
|
|
|
if self.is_fullpage or G_reader_settings:isTrue("dict_largewindow") then
|
2016-12-06 21:15:52 +00:00
|
|
|
-- bigger window if fullpage being shown - this will let
|
|
|
|
-- some room anyway for footer display (time, battery...)
|
|
|
|
self.height = Screen:getHeight()
|
|
|
|
self.width = Screen:getWidth() - Screen:scaleBySize(40)
|
|
|
|
else
|
|
|
|
-- smaller window otherwise
|
|
|
|
-- try to not hide highlighted word
|
|
|
|
if self.word_box then
|
|
|
|
local box = self.word_box
|
|
|
|
if box.y + box.h/2 < Screen:getHeight()*0.3 then
|
|
|
|
self.region.y = box.y + box.h
|
|
|
|
self.region.h = Screen:getHeight() - box.y - box.h
|
|
|
|
self.align = "top"
|
|
|
|
elseif box.y + box.h/2 > Screen:getHeight()*0.7 then
|
|
|
|
self.region.y = 0
|
|
|
|
self.region.h = box.y
|
|
|
|
self.align = "bottom"
|
|
|
|
end
|
2014-08-20 06:41:45 +00:00
|
|
|
end
|
2016-12-06 21:15:52 +00:00
|
|
|
self.height = math.min(self.region.h*0.7, Screen:getHeight()*0.5)
|
2014-08-20 06:41:45 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
-- dictionary title
|
2017-10-23 21:17:52 +00:00
|
|
|
local close_button = CloseButton:new{ window = self, padding_top = self.title_margin, }
|
2016-12-06 21:15:52 +00:00
|
|
|
local dict_title_text = TextWidget:new{
|
|
|
|
text = self.dictionary,
|
|
|
|
face = self.title_face,
|
|
|
|
bold = true,
|
|
|
|
width = self.width,
|
|
|
|
}
|
|
|
|
-- Some different UI tweaks for dict or wiki
|
|
|
|
local lookup_word_font_size, lookup_word_padding, lookup_word_margin
|
|
|
|
if self.is_wiki then
|
|
|
|
-- visual hint : dictionary title left adjusted, Wikipedia title centered
|
|
|
|
dict_title_text = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = dict_title_text:getSize().h,
|
|
|
|
},
|
|
|
|
dict_title_text
|
|
|
|
}
|
|
|
|
-- Wikipedia has longer titles, so use a smaller font
|
|
|
|
lookup_word_font_size = 18
|
|
|
|
lookup_word_padding = self.wiki_word_padding
|
|
|
|
lookup_word_margin = self.wiki_word_margin
|
2017-01-01 09:34:21 +00:00
|
|
|
-- Keep a copy of self.wiki_languages for use
|
|
|
|
-- by DictQuickLookup:resyncWikiLanguages()
|
|
|
|
self.wiki_languages_copy = self.wiki_languages and {unpack(self.wiki_languages)} or nil
|
2016-12-06 21:15:52 +00:00
|
|
|
else
|
|
|
|
-- Usual font size for dictionary
|
|
|
|
lookup_word_font_size = 22
|
|
|
|
lookup_word_padding = self.word_padding
|
|
|
|
lookup_word_margin = self.word_margin
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_title = FrameContainer:new{
|
|
|
|
padding = self.title_padding,
|
|
|
|
margin = self.title_margin,
|
|
|
|
bordersize = 0,
|
2016-12-06 21:15:52 +00:00
|
|
|
dict_title_text
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
-- lookup word
|
2014-08-17 16:32:09 +00:00
|
|
|
local lookup_word = Button:new{
|
2016-12-06 21:15:52 +00:00
|
|
|
padding = lookup_word_padding,
|
|
|
|
margin = lookup_word_margin,
|
2014-03-13 13:52:43 +00:00
|
|
|
bordersize = 0,
|
2017-08-19 10:48:51 +00:00
|
|
|
max_width = self.width,
|
2016-12-06 21:15:52 +00:00
|
|
|
text = self.displayword,
|
2014-08-17 16:32:09 +00:00
|
|
|
text_font_face = "tfont",
|
2016-12-06 21:15:52 +00:00
|
|
|
text_font_size = lookup_word_font_size,
|
2014-08-17 16:32:09 +00:00
|
|
|
hold_callback = function() self:lookupInputWord(self.lookupword) end,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2018-01-07 19:24:15 +00:00
|
|
|
|
|
|
|
local text_widget
|
|
|
|
|
|
|
|
if self.is_html then
|
|
|
|
text_widget = ScrollHtmlWidget:new{
|
|
|
|
html_body = self.definition,
|
|
|
|
css = self:getHtmlDictionaryCss(),
|
2018-01-08 11:23:37 +00:00
|
|
|
default_font_size = Screen:scaleBySize(DDICT_FONT_SIZE),
|
2018-01-07 19:24:15 +00:00
|
|
|
width = self.width,
|
|
|
|
height = self.is_fullpage and self.height*0.75 or self.height*0.7,
|
|
|
|
dialog = self,
|
2018-01-15 22:51:43 +00:00
|
|
|
html_link_tapped_callback = function(link)
|
|
|
|
self.html_dictionary_link_tapped_callback(self.dictionary, link)
|
|
|
|
end,
|
2018-01-07 19:24:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
text_widget = ScrollTextWidget:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
text = self.definition,
|
|
|
|
face = self.content_face,
|
|
|
|
width = self.width,
|
2016-12-06 21:15:52 +00:00
|
|
|
-- get a bit more height for definition as wiki has one less button raw
|
|
|
|
height = self.is_fullpage and self.height*0.75 or self.height*0.7,
|
2014-03-13 13:52:43 +00:00
|
|
|
dialog = self,
|
2017-08-22 15:24:31 +00:00
|
|
|
-- allow for disabling justification
|
|
|
|
justified = G_reader_settings:nilOrTrue("dict_justify"),
|
2018-01-16 11:32:49 +00:00
|
|
|
image_alt_face = self.image_alt_face,
|
|
|
|
images = self.images,
|
2018-01-07 19:24:15 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- word definition
|
2018-01-29 20:27:24 +00:00
|
|
|
self.definition_widget = FrameContainer:new{
|
2018-01-07 19:24:15 +00:00
|
|
|
padding = self.definition_padding,
|
|
|
|
margin = self.definition_margin,
|
|
|
|
bordersize = 0,
|
|
|
|
text_widget,
|
2014-05-01 10:37:12 +00:00
|
|
|
}
|
2016-12-06 21:15:52 +00:00
|
|
|
-- Different sets of buttons if fullpage or not
|
|
|
|
local buttons
|
|
|
|
if self.is_fullpage then
|
2017-01-21 18:23:13 +00:00
|
|
|
-- A save and a close button
|
2016-12-06 21:15:52 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
2017-01-21 18:23:13 +00:00
|
|
|
{
|
2017-05-08 16:14:29 +00:00
|
|
|
text = _("Save as EPUB"),
|
2017-01-21 18:23:13 +00:00
|
|
|
callback = function()
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
-- if forced_lang was specified, it may not be in our wiki_languages,
|
|
|
|
-- but ReaderWikipedia will have put it in result.lang
|
|
|
|
local lang = self.lang or self.wiki_languages_copy[1]
|
|
|
|
-- Just to be safe (none of the invalid chars, except ':' for uninteresting
|
|
|
|
-- Portal: or File: wikipedia pages, should be in lookup_word)
|
2018-04-06 19:13:25 +00:00
|
|
|
local cleaned_lookupword = util.replaceInvalidChars(self.lookupword:gsub("_", " "))
|
2017-01-21 18:23:13 +00:00
|
|
|
local filename = cleaned_lookupword .. "."..string.upper(lang)..".epub"
|
|
|
|
-- Find a directory to save file into
|
2018-03-16 19:47:51 +00:00
|
|
|
local dir
|
|
|
|
if G_reader_settings:isTrue("wikipedia_save_in_book_dir") and not self:isDocless() then
|
|
|
|
local last_file = G_reader_settings:readSetting("lastfile")
|
|
|
|
if last_file then
|
|
|
|
dir = last_file:match("(.*)/")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not dir then dir = G_reader_settings:readSetting("wikipedia_save_dir") end
|
2017-01-21 18:23:13 +00:00
|
|
|
if not dir then dir = G_reader_settings:readSetting("home_dir") end
|
2017-08-22 15:24:31 +00:00
|
|
|
if not dir then dir = require("apps/filemanager/filemanagerutil").getDefaultDir() end
|
2018-03-16 19:47:51 +00:00
|
|
|
if not dir or not util.pathExists(dir) then
|
2017-01-21 18:23:13 +00:00
|
|
|
UIManager:show(InfoMessage:new{
|
2018-03-16 19:47:51 +00:00
|
|
|
text = _("No directory to save article to could be found."),
|
2017-01-21 18:23:13 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local epub_path = dir .. "/" .. filename
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2017-01-31 12:53:20 +00:00
|
|
|
text = T(_("Save as %1?"), filename),
|
2017-01-21 18:23:13 +00:00
|
|
|
ok_callback = function()
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
local Wikipedia = require("ui/wikipedia")
|
|
|
|
Wikipedia:createEpubWithUI(epub_path, self.lookupword, lang, function(success)
|
|
|
|
if success then
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2018-01-16 11:32:49 +00:00
|
|
|
text = T(_("Article saved to:\n%1\n\nWould you like to read the downloaded article now?"), epub_path),
|
2017-01-21 18:23:13 +00:00
|
|
|
ok_callback = function()
|
|
|
|
-- close all dict/wiki windows, without scheduleIn(highlight.clear())
|
|
|
|
self:onHoldClose(true)
|
|
|
|
-- close current ReaderUI in 1 sec, and create a new one
|
|
|
|
UIManager:scheduleIn(1.0, function()
|
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
|
|
local reader = ReaderUI:_getRunningInstance()
|
|
|
|
if reader then
|
2017-10-24 13:22:10 +00:00
|
|
|
-- close Highlight menu if any still shown
|
|
|
|
if reader.highlight then
|
|
|
|
reader.highlight:onClose()
|
|
|
|
end
|
2017-01-21 18:23:13 +00:00
|
|
|
reader:onClose()
|
|
|
|
end
|
|
|
|
ReaderUI:showReader(epub_path)
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
2018-01-16 11:32:49 +00:00
|
|
|
text = _("Saving Wikipedia article failed or canceled."),
|
2017-01-21 18:23:13 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
{
|
2017-05-08 16:14:29 +00:00
|
|
|
text = _("Close"),
|
2016-12-06 21:15:52 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:close(self)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
else
|
2014-03-13 13:52:43 +00:00
|
|
|
buttons = {
|
2014-05-01 10:37:12 +00:00
|
|
|
{
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
2017-09-13 14:56:20 +00:00
|
|
|
text = "◁◁",
|
2014-03-13 13:52:43 +00:00
|
|
|
enabled = self:isPrevDictAvaiable(),
|
|
|
|
callback = function()
|
|
|
|
self:changeToPrevDict()
|
|
|
|
end,
|
|
|
|
},
|
2014-08-11 13:49:42 +00:00
|
|
|
{
|
2015-03-12 10:50:57 +00:00
|
|
|
text = self:getHighlightText(),
|
2017-11-01 14:50:53 +00:00
|
|
|
enabled = self.highlight ~= nil,
|
2014-08-11 13:49:42 +00:00
|
|
|
callback = function()
|
2017-09-01 21:17:35 +00:00
|
|
|
if self:getHighlightText() == highlight_strings.highlight then
|
2017-07-28 20:39:54 +00:00
|
|
|
self.ui:handleEvent(Event:new("Highlight"))
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("Unhighlight"))
|
|
|
|
end
|
2015-03-12 10:50:57 +00:00
|
|
|
self:update()
|
2014-08-11 13:49:42 +00:00
|
|
|
end,
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
2017-09-13 14:56:20 +00:00
|
|
|
text = "▷▷",
|
2014-03-13 13:52:43 +00:00
|
|
|
enabled = self:isNextDictAvaiable(),
|
|
|
|
callback = function()
|
|
|
|
self:changeToNextDict()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
2016-12-06 21:15:52 +00:00
|
|
|
-- if dictionary result, do the same search on wikipedia
|
|
|
|
-- if already wiki, get the full page for the current result
|
|
|
|
text = self.is_wiki and _("Wikipedia full") or _("Wikipedia"),
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2014-08-20 06:41:45 +00:00
|
|
|
UIManager:scheduleIn(0.1, function()
|
2016-12-06 21:15:52 +00:00
|
|
|
self:lookupWikipedia(self.is_wiki) -- will get_fullpage if is_wiki
|
2014-08-20 06:41:45 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
-- Rotate thru available wikipedia languages (disabled if dictionary window)
|
|
|
|
-- (replace previous unimplemented "Add Note")
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
2016-12-06 21:15:52 +00:00
|
|
|
-- if more than one language, enable it and display "current lang > next lang"
|
|
|
|
-- otherwise, just display current lang
|
2017-09-10 12:26:49 +00:00
|
|
|
text = self.is_wiki and ( #self.wiki_languages > 1 and self.wiki_languages[1].." > "..self.wiki_languages[2] or self.wiki_languages[1] ) or _("Follow Link"),
|
2017-09-09 16:30:00 +00:00
|
|
|
enabled = (self.is_wiki and #self.wiki_languages > 1) or self.selected_link ~= nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2017-09-09 16:30:00 +00:00
|
|
|
if self.is_wiki then
|
|
|
|
self:resyncWikiLanguages(true) -- rotate & resync them
|
|
|
|
UIManager:close(self)
|
|
|
|
self:lookupWikipedia()
|
|
|
|
else
|
2017-09-10 12:26:49 +00:00
|
|
|
self:onClose()
|
|
|
|
self.ui.link:onGotoLink(self.selected_link)
|
2017-09-09 16:30:00 +00:00
|
|
|
end
|
2014-08-11 13:49:42 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2017-01-02 18:12:34 +00:00
|
|
|
text = (self.is_wiki or self:isDocless()) and _("Close") or _("Search"),
|
2014-08-11 13:49:42 +00:00
|
|
|
callback = function()
|
2016-12-06 21:15:52 +00:00
|
|
|
if not self.is_wiki then
|
|
|
|
self.ui:handleEvent(Event:new("HighlightSearch"))
|
|
|
|
end
|
2014-11-05 04:28:11 +00:00
|
|
|
UIManager:close(self)
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2016-12-06 21:15:52 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local button_table = ButtonTable:new{
|
2018-01-29 20:27:24 +00:00
|
|
|
width = math.max(self.width, self.definition_widget:getSize().w),
|
2016-12-06 21:15:52 +00:00
|
|
|
button_font_face = "cfont",
|
|
|
|
button_font_size = 20,
|
|
|
|
buttons = buttons,
|
2014-03-13 13:52:43 +00:00
|
|
|
zero_sep = true,
|
2014-05-01 10:37:12 +00:00
|
|
|
show_parent = self,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
local title_bar = LineWidget:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = button_table:getSize().w + self.button_padding,
|
2017-09-13 14:56:20 +00:00
|
|
|
h = Size.line.thick,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-01 10:37:12 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_bar = OverlapGroup:new{
|
2016-03-07 06:41:17 +00:00
|
|
|
dimen = {
|
|
|
|
w = button_table:getSize().w + self.button_padding,
|
|
|
|
h = self.dict_title:getSize().h
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_title,
|
2017-10-23 21:17:52 +00:00
|
|
|
close_button,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2017-10-23 21:17:52 +00:00
|
|
|
-- Fix dict title max width now that we know the final width
|
|
|
|
dict_title_text.width = self.dict_bar.dimen.w - close_button:getSize().w
|
2014-05-01 10:37:12 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
|
|
|
bordersize = Size.border.window,
|
2014-03-13 13:52:43 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
self.dict_bar,
|
|
|
|
title_bar,
|
|
|
|
-- word
|
2014-08-17 16:32:09 +00:00
|
|
|
LeftContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = title_bar:getSize().w,
|
|
|
|
h = lookup_word:getSize().h,
|
|
|
|
},
|
|
|
|
lookup_word,
|
|
|
|
},
|
|
|
|
-- definition
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = title_bar:getSize().w,
|
2018-01-29 20:27:24 +00:00
|
|
|
h = self.definition_widget:getSize().h,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2018-01-29 20:27:24 +00:00
|
|
|
self.definition_widget,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
-- buttons
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = title_bar:getSize().w,
|
|
|
|
h = button_table:getSize().h,
|
|
|
|
},
|
|
|
|
button_table,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-29 20:27:24 +00:00
|
|
|
|
|
|
|
self.movable = MovableContainer:new{
|
|
|
|
-- We'll handle these events ourselves, and call appropriate
|
|
|
|
-- MovableContainer's methods when we didn't process the event
|
2018-03-05 20:27:55 +00:00
|
|
|
ignore_events = {
|
|
|
|
-- These have effects over the definition widget, and may
|
|
|
|
-- or may not be processed by it
|
2018-03-07 14:59:59 +00:00
|
|
|
"swipe", "hold", "hold_release", "hold_pan",
|
2018-03-05 20:27:55 +00:00
|
|
|
-- These do not have direct effect over the definition widget,
|
|
|
|
-- but may happen while selecting text: we need to check
|
2018-03-07 14:59:59 +00:00
|
|
|
-- a few things before forwarding them
|
|
|
|
"touch", "pan", "pan_release",
|
2018-03-05 20:27:55 +00:00
|
|
|
},
|
2018-01-29 20:27:24 +00:00
|
|
|
self.dict_frame,
|
|
|
|
}
|
|
|
|
self.movable:setMovedOffset(orig_moved_offset)
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
align = self.align,
|
2014-08-20 06:41:45 +00:00
|
|
|
dimen = self.region,
|
2018-01-29 20:27:24 +00:00
|
|
|
self.movable,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
UIManager:setDirty(self, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
local update_region = self.dict_frame and self.dict_frame.dimen and self.dict_frame.dimen:combine(orig_dimen) or orig_dimen
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("update dict region", update_region)
|
2018-06-02 16:10:55 +00:00
|
|
|
return "partial", update_region
|
2014-11-30 17:57:41 +00:00
|
|
|
end)
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function DictQuickLookup:onCloseWidget()
|
2018-01-16 11:32:49 +00:00
|
|
|
-- Free our widget and subwidgets' resources (especially
|
|
|
|
-- definitions' TextBoxWidget bb, HtmlBoxWidget bb and MuPDF instance,
|
|
|
|
-- and scheduled image_update_action)
|
|
|
|
if self[1] then
|
|
|
|
self[1]:free()
|
|
|
|
end
|
|
|
|
if self.images_cleanup_needed then
|
|
|
|
logger.dbg("freeing lookup results images blitbuffers")
|
|
|
|
for _, r in ipairs(self.results) do
|
|
|
|
if r.images and #r.images > 0 then
|
|
|
|
for _, im in ipairs(r.images) do
|
|
|
|
if im.bb then im.bb:free() end
|
|
|
|
if im.hi_bb then im.hi_bb:free() end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-06-02 16:10:55 +00:00
|
|
|
-- NOTE: Drop region to make it a full-screen flash
|
2014-12-01 14:39:41 +00:00
|
|
|
UIManager:setDirty(nil, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "flashui", nil
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "flashui", self.dict_frame.dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-03-12 10:50:57 +00:00
|
|
|
function DictQuickLookup:getHighlightedItem()
|
2017-01-02 18:12:34 +00:00
|
|
|
if self:isDocless() then return end
|
2015-03-12 10:50:57 +00:00
|
|
|
return self.ui.highlight:getHighlightBookmarkItem()
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:getHighlightText()
|
|
|
|
local item = self:getHighlightedItem()
|
|
|
|
if not item then
|
2017-09-01 21:17:35 +00:00
|
|
|
return highlight_strings.highlight, false
|
2015-03-12 10:50:57 +00:00
|
|
|
elseif self.ui.bookmark:isBookmarkAdded(item) then
|
2017-09-01 21:17:35 +00:00
|
|
|
return highlight_strings.unhighlight, false
|
2015-03-12 10:50:57 +00:00
|
|
|
else
|
2017-09-01 21:17:35 +00:00
|
|
|
return highlight_strings.highlight, true
|
2015-03-12 10:50:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-21 06:23:54 +00:00
|
|
|
function DictQuickLookup:isPrevDictAvaiable()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.dict_index > 1
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:isNextDictAvaiable()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.dict_index < #self.results
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:changeToPrevDict()
|
2016-12-06 21:15:52 +00:00
|
|
|
if self:isPrevDictAvaiable() then
|
|
|
|
self:changeDictionary(self.dict_index - 1)
|
|
|
|
elseif #self.results > 1 then -- restart at end if first reached
|
|
|
|
self:changeDictionary(#self.results)
|
|
|
|
end
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:changeToNextDict()
|
2016-12-06 21:15:52 +00:00
|
|
|
if self:isNextDictAvaiable() then
|
|
|
|
self:changeDictionary(self.dict_index + 1)
|
|
|
|
elseif #self.results > 1 then -- restart at first if end reached
|
|
|
|
self:changeDictionary(1)
|
|
|
|
end
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:changeDictionary(index)
|
2014-07-24 14:10:28 +00:00
|
|
|
if not self.results[index] then return end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dict_index = index
|
|
|
|
self.dictionary = self.results[index].dict
|
|
|
|
self.lookupword = self.results[index].word
|
|
|
|
self.definition = self.results[index].definition
|
2016-12-06 21:15:52 +00:00
|
|
|
self.is_fullpage = self.results[index].is_fullpage
|
2018-01-07 19:24:15 +00:00
|
|
|
self.is_html = self.results[index].is_html
|
|
|
|
self.css = self.results[index].css
|
2017-01-21 18:23:13 +00:00
|
|
|
self.lang = self.results[index].lang
|
2018-01-16 11:32:49 +00:00
|
|
|
self.images = self.results[index].images
|
|
|
|
if self.images and #self.images > 0 then
|
|
|
|
-- We'll be giving some images to textboxwidget that will
|
|
|
|
-- load and display them. We'll need to free these blitbuffers
|
|
|
|
-- when we're done.
|
|
|
|
self.images_cleanup_needed = true
|
|
|
|
end
|
2016-12-06 21:15:52 +00:00
|
|
|
if self.is_fullpage then
|
|
|
|
self.displayword = self.lookupword
|
|
|
|
else
|
|
|
|
-- add "dict_index / nbresults" to displayword, so we know where
|
|
|
|
-- we're at and what's yet to see
|
|
|
|
self.displayword = self.lookupword.." "..index.." / "..#self.results
|
|
|
|
-- add queried word to 1st result's definition, so we can see
|
|
|
|
-- what was the selected text and if we selected wrong
|
|
|
|
if index == 1 then
|
2018-01-08 11:23:37 +00:00
|
|
|
if self.is_html then
|
|
|
|
self.definition = self.definition.."<br/>_______<br/>"
|
|
|
|
else
|
|
|
|
self.definition = self.definition.."\n_______\n"
|
|
|
|
end
|
|
|
|
self.definition = self.definition..T(_("(query : %1)"), self.word)
|
2016-12-06 21:15:52 +00:00
|
|
|
end
|
|
|
|
end
|
2014-05-01 10:37:12 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self:update()
|
2013-07-21 06:23:54 +00:00
|
|
|
end
|
|
|
|
|
2014-05-01 10:37:12 +00:00
|
|
|
function DictQuickLookup:changeToDefaultDict()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.dictionary then
|
|
|
|
-- dictionaries that have definition of the first word(accurate word)
|
|
|
|
-- excluding Fuzzy queries.
|
|
|
|
local n_accurate_dicts = nil
|
|
|
|
local default_word = self.results[1].word
|
|
|
|
for i=1, #self.results do
|
|
|
|
if self.results[i].word == default_word then
|
|
|
|
n_accurate_dicts = i
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- change to dictionary specified by self.dictionary
|
|
|
|
for i=1, n_accurate_dicts do
|
|
|
|
if self.results[i].dict == self.dictionary then
|
|
|
|
self:changeDictionary(i)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
-- cannot find definition in default dictionary
|
|
|
|
if i == n_accurate_dicts then
|
|
|
|
self:changeDictionary(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self:changeDictionary(1)
|
|
|
|
end
|
2013-04-24 14:57:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onAnyKeyPressed()
|
2014-03-13 13:52:43 +00:00
|
|
|
-- triggered by our defined key events
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
2013-04-24 14:57:03 +00:00
|
|
|
end
|
|
|
|
|
2013-07-21 06:23:54 +00:00
|
|
|
function DictQuickLookup:onTapCloseDict(arg, ges_ev)
|
2014-03-13 13:52:43 +00:00
|
|
|
if ges_ev.pos:notIntersectWith(self.dict_frame.dimen) then
|
|
|
|
self:onClose()
|
|
|
|
return true
|
2016-12-06 21:15:52 +00:00
|
|
|
elseif not ges_ev.pos:notIntersectWith(self.dict_title.dimen) and not self.is_wiki then
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("UpdateDefaultDict", self.dictionary))
|
|
|
|
return true
|
|
|
|
end
|
2016-12-06 21:15:52 +00:00
|
|
|
-- Allow for changing dict with tap (tap event will be first
|
|
|
|
-- processed for scrolling definition by ScrollTextWidget, which
|
|
|
|
-- will pop it up for us here when it can't scroll anymore).
|
|
|
|
-- This allow for continuous reading of results' definitions with tap.
|
|
|
|
if ges_ev.pos.x < Screen:getWidth()/2 then
|
2018-01-31 08:16:34 +00:00
|
|
|
local prev_index = self.dict_index
|
2016-12-06 21:15:52 +00:00
|
|
|
self:changeToPrevDict()
|
2018-01-31 08:16:34 +00:00
|
|
|
if self.dict_index ~= prev_index then
|
|
|
|
-- Jump directly to bottom of previous dict definition
|
|
|
|
-- to keep "continuous reading with tap" consistent
|
|
|
|
self.definition_widget[1]:scrollToRatio(1) -- 1 = 100% = bottom
|
|
|
|
end
|
2016-12-06 21:15:52 +00:00
|
|
|
else
|
|
|
|
self:changeToNextDict()
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-04-24 14:57:03 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2013-12-26 14:40:40 +00:00
|
|
|
function DictQuickLookup:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:close(self)
|
2016-06-28 16:35:00 +00:00
|
|
|
for i = #self.window_list, 1, -1 do
|
|
|
|
local window = self.window_list[i]
|
|
|
|
if window == self then
|
|
|
|
table.remove(self.window_list, i)
|
|
|
|
end
|
|
|
|
end
|
2014-08-17 16:32:09 +00:00
|
|
|
if self.highlight then
|
2016-12-06 21:15:52 +00:00
|
|
|
-- delay unhighlight of selection, so we can see where we stopped when
|
|
|
|
-- back from our journey into dictionary or wikipedia
|
2017-09-20 15:35:30 +00:00
|
|
|
local clear_id = self.highlight:getClearId()
|
2017-09-19 20:48:30 +00:00
|
|
|
UIManager:scheduleIn(0.5, function()
|
2017-09-20 15:35:30 +00:00
|
|
|
self.highlight:clear(clear_id)
|
2016-12-06 21:15:52 +00:00
|
|
|
end)
|
2016-06-28 16:35:00 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-01-21 18:23:13 +00:00
|
|
|
function DictQuickLookup:onHoldClose(no_clear)
|
2016-06-28 16:35:00 +00:00
|
|
|
self:onClose()
|
|
|
|
for i = #self.window_list, 1, -1 do
|
|
|
|
local window = self.window_list[i]
|
2016-12-06 21:15:52 +00:00
|
|
|
-- if one holds a highlight, let's clear it like in onClose()
|
2017-01-21 18:23:13 +00:00
|
|
|
if window.highlight and not no_clear then
|
2017-09-20 15:35:30 +00:00
|
|
|
local clear_id = window.highlight:getClearId()
|
|
|
|
UIManager:scheduleIn(0.5, function()
|
|
|
|
window.highlight:clear(clear_id)
|
2016-12-06 21:15:52 +00:00
|
|
|
end)
|
|
|
|
end
|
2016-06-28 16:35:00 +00:00
|
|
|
UIManager:close(window)
|
|
|
|
table.remove(self.window_list, i)
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-12-26 14:40:40 +00:00
|
|
|
end
|
|
|
|
|
2014-07-24 14:10:28 +00:00
|
|
|
function DictQuickLookup:onSwipe(arg, ges)
|
2018-01-29 20:27:24 +00:00
|
|
|
if ges.pos:intersectWith(self.definition_widget.dimen) then
|
|
|
|
-- if we want changeDict to still work with swipe outside window :
|
|
|
|
-- or not ges.pos:intersectWith(self.dict_frame.dimen) then
|
|
|
|
if ges.direction == "west" then
|
|
|
|
self:changeToNextDict()
|
|
|
|
elseif ges.direction == "east" then
|
|
|
|
self:changeToPrevDict()
|
|
|
|
else
|
|
|
|
if self.refresh_callback then self.refresh_callback() end
|
2018-06-02 16:10:55 +00:00
|
|
|
-- trigger a full-screen HQ flashing refresh
|
2018-01-29 20:27:24 +00:00
|
|
|
UIManager:setDirty(nil, "full")
|
|
|
|
-- a long diagonal swipe may also be used for taking a screenshot,
|
|
|
|
-- so let it propagate
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
2014-07-24 14:10:28 +00:00
|
|
|
end
|
2018-01-29 20:27:24 +00:00
|
|
|
-- Let our MovableContainer handle swipe outside of definition
|
|
|
|
return self.movable:onMovableSwipe(arg, ges)
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onHoldStartText(_, ges)
|
|
|
|
-- Forward Hold events not processed by TextBoxWidget event handler
|
|
|
|
-- to our MovableContainer
|
|
|
|
return self.movable:onMovableHold(_, ges)
|
|
|
|
end
|
|
|
|
|
2018-03-07 14:59:59 +00:00
|
|
|
function DictQuickLookup:onHoldPanText(_, ges)
|
|
|
|
-- Forward Hold events not processed by TextBoxWidget event handler
|
|
|
|
-- to our MovableContainer
|
|
|
|
-- We only forward it if we did forward the Touch
|
|
|
|
if self.movable._touch_pre_pan_was_inside then
|
|
|
|
return self.movable:onMovableHoldPan(arg, ges)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-29 20:27:24 +00:00
|
|
|
function DictQuickLookup:onHoldReleaseText(_, ges)
|
|
|
|
-- Forward Hold events not processed by TextBoxWidget event handler
|
|
|
|
-- to our MovableContainer
|
|
|
|
return self.movable:onMovableHoldRelease(_, ges)
|
2014-07-24 14:10:28 +00:00
|
|
|
end
|
|
|
|
|
2018-03-07 14:59:59 +00:00
|
|
|
-- These 3 event processors are just used to forward these events
|
2018-03-05 20:27:55 +00:00
|
|
|
-- to our MovableContainer, under certain conditions, to avoid
|
|
|
|
-- unwanted moves of the window while we are selecting text in
|
|
|
|
-- the definition widget.
|
|
|
|
function DictQuickLookup:onForwardingTouch(arg, ges)
|
|
|
|
-- This Touch may be used as the Hold we don't get (for example,
|
|
|
|
-- when we start our Hold on the bottom buttons)
|
|
|
|
if not ges.pos:intersectWith(self.definition_widget.dimen) then
|
|
|
|
return self.movable:onMovableTouch(arg, ges)
|
|
|
|
else
|
|
|
|
-- Ensure this is unset, so we can use it to not forward HoldPan
|
|
|
|
self.movable._touch_pre_pan_was_inside = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onForwardingPan(arg, ges)
|
2018-03-07 14:59:59 +00:00
|
|
|
-- We only forward it if we did forward the Touch or are currently moving
|
|
|
|
if self.movable._touch_pre_pan_was_inside or self.movable._moving then
|
|
|
|
return self.movable:onMovablePan(arg, ges)
|
2018-03-05 20:27:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:onForwardingPanRelease(arg, ges)
|
2018-03-07 14:59:59 +00:00
|
|
|
-- We can forward onMovablePanRelease() does enough checks
|
|
|
|
return self.movable:onMovablePanRelease(arg, ges)
|
2018-03-05 20:27:55 +00:00
|
|
|
end
|
|
|
|
|
2014-08-17 16:32:09 +00:00
|
|
|
function DictQuickLookup:lookupInputWord(hint)
|
|
|
|
self:onClose()
|
|
|
|
self.input_dialog = InputDialog:new{
|
|
|
|
title = _("Input lookup word"),
|
2014-08-20 06:41:45 +00:00
|
|
|
input = hint,
|
2014-08-17 16:32:09 +00:00
|
|
|
input_hint = hint or "",
|
|
|
|
input_type = "text",
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
|
|
|
callback = function()
|
|
|
|
self:closeInputDialog()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Lookup"),
|
2016-05-26 06:09:49 +00:00
|
|
|
is_enter_default = true,
|
2014-08-17 16:32:09 +00:00
|
|
|
callback = function()
|
|
|
|
self:closeInputDialog()
|
|
|
|
self:inputLookup()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(self.input_dialog)
|
2018-03-30 10:46:36 +00:00
|
|
|
self.input_dialog:onShowKeyboard()
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:inputLookup()
|
|
|
|
local word = self.input_dialog:getInputText()
|
|
|
|
if word and word ~= "" then
|
2017-01-01 09:34:21 +00:00
|
|
|
local event
|
|
|
|
if self.is_wiki then
|
|
|
|
event = "LookupWikipedia"
|
|
|
|
self:resyncWikiLanguages()
|
|
|
|
else
|
|
|
|
event = "LookupWord"
|
|
|
|
end
|
2014-08-20 06:41:45 +00:00
|
|
|
self.ui:handleEvent(Event:new(event, word))
|
2014-08-17 16:32:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DictQuickLookup:closeInputDialog()
|
|
|
|
UIManager:close(self.input_dialog)
|
|
|
|
end
|
|
|
|
|
2017-01-01 09:34:21 +00:00
|
|
|
function DictQuickLookup:resyncWikiLanguages(rotate)
|
|
|
|
-- Resync the current language or rotate it from its state when
|
|
|
|
-- this window was created (we may have rotated it later in other
|
|
|
|
-- wikipedia windows that we closed and went back here, and its
|
|
|
|
-- state would not be what the wikipedia language button is showing.
|
|
|
|
if not self.wiki_languages_copy then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if rotate then
|
|
|
|
-- rotate our saved wiki_languages copy
|
|
|
|
local current_lang = table.remove(self.wiki_languages_copy, 1)
|
|
|
|
table.insert(self.wiki_languages_copy, current_lang)
|
|
|
|
end
|
|
|
|
-- re-set self.wiki_languages with original (possibly rotated) items
|
|
|
|
for i, lang in ipairs(self.wiki_languages_copy) do
|
|
|
|
self.wiki_languages[i] = lang
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-06 21:15:52 +00:00
|
|
|
function DictQuickLookup:lookupWikipedia(get_fullpage)
|
|
|
|
local word
|
|
|
|
if get_fullpage then
|
|
|
|
-- we use the word of the displayed result's definition, which
|
|
|
|
-- is the exact title of the full wikipedia page
|
|
|
|
word = self.lookupword
|
|
|
|
else
|
|
|
|
-- we use the original word that was querried
|
|
|
|
word = self.word
|
|
|
|
end
|
2017-01-01 09:34:21 +00:00
|
|
|
self:resyncWikiLanguages()
|
2016-12-06 21:15:52 +00:00
|
|
|
-- strange : we need to pass false instead of nil if word_box is nil,
|
|
|
|
-- otherwise get_fullpage is not passed
|
|
|
|
self.ui:handleEvent(Event:new("LookupWikipedia", word, self.word_box and self.word_box or false, get_fullpage))
|
2014-08-20 06:41:45 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return DictQuickLookup
|