Rationalize Links> menu items

- Remove duplicated "Show footnote popup". Have the same setting
  applied for Tap or 'Swipe to follow nearest link'.
- Make some menu items enabled or disabled depending on if they would
  have some effect with the current state of other menu items, as
  some kind of visual self-documentation of these dependancies.
- Add menu item to set the footnote popup font size, relative to
  the book font size.
- SpinWidget: allow for showing some informative text
pull/4487/head
poire-z 5 years ago
parent df28b90419
commit 4d67dd59ca

@ -33,6 +33,13 @@ function ReaderLink:init()
-- For relative local file links -- For relative local file links
local directory, filename = util.splitFilePathName(self.ui.document.file) -- luacheck: no unused local directory, filename = util.splitFilePathName(self.ui.document.file) -- luacheck: no unused
self.document_dir = directory self.document_dir = directory
-- Migrate these old settings to the new common one
if G_reader_settings:isTrue("tap_link_footnote_popup")
or G_reader_settings:isTrue("swipe_link_footnote_popup") then
G_reader_settings:saveSetting("tap_link_footnote_popup", nil)
G_reader_settings:saveSetting("swipe_link_footnote_popup", nil)
G_reader_settings:saveSetting("footnote_link_in_popup", true)
end
end end
function ReaderLink:onReadSettings(config) function ReaderLink:onReadSettings(config)
@ -79,8 +86,8 @@ local function isTapIgnoreExternalLinksEnabled()
return G_reader_settings:isTrue("tap_ignore_external_links") return G_reader_settings:isTrue("tap_ignore_external_links")
end end
local function isTapLinkFootnotePopupEnabled() local function isFootnoteLinkInPopupEnabled()
return G_reader_settings:isTrue("tap_link_footnote_popup") return G_reader_settings:isTrue("footnote_link_in_popup")
end end
local function isPreferFootnoteEnabled() local function isPreferFootnoteEnabled()
@ -99,10 +106,6 @@ local function isSwipeToFollowNearestLinkEnabled()
return G_reader_settings:isTrue("swipe_to_follow_nearest_link") return G_reader_settings:isTrue("swipe_to_follow_nearest_link")
end end
local function isSwipeLinkFootnotePopupEnabled()
return G_reader_settings:isTrue("swipe_link_footnote_popup")
end
local function isSwipeToJumpToLatestBookmarkEnabled() local function isSwipeToJumpToLatestBookmarkEnabled()
return G_reader_settings:isTrue("swipe_to_jump_to_latest_bookmark") return G_reader_settings:isTrue("swipe_to_jump_to_latest_bookmark")
end end
@ -176,17 +179,11 @@ If any of the other Swipe to follow link options is enabled, this will work only
-- followed a link, than on EPUB, it's safer to not use them on PDF documents -- followed a link, than on EPUB, it's safer to not use them on PDF documents
-- even if the user enabled these features for EPUB documents). -- even if the user enabled these features for EPUB documents).
if not self.ui.document.info.has_pages then if not self.ui.document.info.has_pages then
local footnote_popup_help_text = _([[
Show internal link target content in a footnote popup when it looks like it might be a footnote, instead of following the link.
Note that depending on the book quality, footnote detection may not always work correctly.
The footnote content may be empty, truncated, or include other footnotes.
From the footnote popup, you can jump to the footnote location in the book by swiping to the left.]])
-- Tap section -- Tap section
menu_items.follow_links.sub_item_table[1].separator = nil menu_items.follow_links.sub_item_table[1].separator = nil
table.insert(menu_items.follow_links.sub_item_table, 2, { table.insert(menu_items.follow_links.sub_item_table, 2, {
text = _("Allow larger tap area around links"), text = _("Allow larger tap area around links"),
enabled_func = isTapToFollowLinksOn,
checked_func = isLargerTapAreaToFollowLinksEnabled, checked_func = isLargerTapAreaToFollowLinksEnabled,
callback = function() callback = function()
G_reader_settings:saveSetting("larger_tap_area_to_follow_links", G_reader_settings:saveSetting("larger_tap_area_to_follow_links",
@ -196,6 +193,7 @@ From the footnote popup, you can jump to the footnote location in the book by sw
}) })
table.insert(menu_items.follow_links.sub_item_table, 3, { table.insert(menu_items.follow_links.sub_item_table, 3, {
text = _("Ignore external links"), text = _("Ignore external links"),
enabled_func = isTapToFollowLinksOn,
checked_func = isTapIgnoreExternalLinksEnabled, checked_func = isTapIgnoreExternalLinksEnabled,
callback = function() callback = function()
G_reader_settings:saveSetting("tap_ignore_external_links", G_reader_settings:saveSetting("tap_ignore_external_links",
@ -203,38 +201,69 @@ From the footnote popup, you can jump to the footnote location in the book by sw
end, end,
help_text = _([[Ignore taps on external links. Useful with Wikipedia EPUBs to make page turning easier. help_text = _([[Ignore taps on external links. Useful with Wikipedia EPUBs to make page turning easier.
You can still follow them from the dictionary window or the selection menu after holding on them.]]), You can still follow them from the dictionary window or the selection menu after holding on them.]]),
separator = true,
}) })
table.insert(menu_items.follow_links.sub_item_table, 4, { table.insert(menu_items.follow_links.sub_item_table, 4, {
text = _("Show footnotes in popup"), text = _("Show footnotes in popup"),
checked_func = isTapLinkFootnotePopupEnabled, enabled_func = function()
return isTapToFollowLinksOn() or isSwipeToFollowNearestLinkEnabled()
end,
checked_func = isFootnoteLinkInPopupEnabled,
callback = function() callback = function()
G_reader_settings:saveSetting("tap_link_footnote_popup", G_reader_settings:saveSetting("footnote_link_in_popup",
not isTapLinkFootnotePopupEnabled()) not isFootnoteLinkInPopupEnabled())
end, end,
help_text = footnote_popup_help_text, help_text = _([[
separator = true, Show internal link target content in a footnote popup when it looks like it might be a footnote, instead of following the link.
Note that depending on the book quality, footnote detection may not always work correctly.
The footnote content may be empty, truncated, or include other footnotes.
From the footnote popup, you can jump to the footnote location in the book by swiping to the left.]]),
}) })
table.insert(menu_items.follow_links.sub_item_table, 5, { table.insert(menu_items.follow_links.sub_item_table, 5, {
text = _("Show more links as footnotes"), text = _("Show more links as footnotes"),
enabled_func = function()
return isFootnoteLinkInPopupEnabled() and
(isTapToFollowLinksOn() or isSwipeToFollowNearestLinkEnabled())
end,
checked_func = isPreferFootnoteEnabled, checked_func = isPreferFootnoteEnabled,
callback = function() callback = function()
G_reader_settings:saveSetting("link_prefer_footnote", G_reader_settings:saveSetting("link_prefer_footnote",
not isPreferFootnoteEnabled()) not isPreferFootnoteEnabled())
end, end,
help_text = _([[Loosen footnote detection rules to show more links as footnotes.]]), help_text = _([[Loosen footnote detection rules to show more links as footnotes.]]),
separator = true,
}) })
-- Swipe section table.insert(menu_items.follow_links.sub_item_table, 6, {
menu_items.follow_links.sub_item_table[8].separator = nil text = _("Set footnote popup font size"),
table.insert(menu_items.follow_links.sub_item_table, 9, { enabled_func = function()
text = _("Swipe to show footnotes in popup"), return isFootnoteLinkInPopupEnabled() and
checked_func = isSwipeLinkFootnotePopupEnabled, (isTapToFollowLinksOn() or isSwipeToFollowNearestLinkEnabled())
enabled_func = isSwipeToFollowNearestLinkEnabled, end,
keep_menu_open = true,
callback = function() callback = function()
G_reader_settings:saveSetting("swipe_link_footnote_popup", local SpinWidget = require("ui/widget/spinwidget")
not isSwipeLinkFootnotePopupEnabled()) UIManager:show(SpinWidget:new{
width = Screen:getWidth() * 0.75,
value = G_reader_settings:readSetting("footnote_popup_relative_font_size") or -2,
value_min = -10,
value_max = 5,
precision = "%+d",
ok_text = _("Set font size"),
title_text = _("Set footnote popup font size"),
text = _([[
The footnote popup font adjusts to the font size you've set for the document.
You can specify here how much smaller or larger it should be relative to the document font size.
A negative value will make it smaller, while a positive one will make it larger.
The recommended value is -2.]]),
callback = function(spin)
G_reader_settings:saveSetting("footnote_popup_relative_font_size", spin.value)
end,
})
end, end,
help_text = footnote_popup_help_text, help_text = _([[
The footnote popup font adjusts to the font size you've set for the document.
This allows you to specify how much smaller or larger it should be relative to the document font size.]]),
separator = true, separator = true,
}) })
end end
@ -376,7 +405,7 @@ function ReaderLink:onTap(_, ges)
end end
return return
end end
local allow_footnote_popup = isTapLinkFootnotePopupEnabled() local allow_footnote_popup = isFootnoteLinkInPopupEnabled()
-- If tap_ignore_external_links, skip precise tap detection to really -- If tap_ignore_external_links, skip precise tap detection to really
-- ignore a tap on an external link, and allow using onGoToPageLink() -- ignore a tap on an external link, and allow using onGoToPageLink()
-- to find the nearest internal link -- to find the nearest internal link
@ -627,7 +656,7 @@ function ReaderLink:onSwipe(arg, ges)
-- no sense allowing footnote popup if first link -- no sense allowing footnote popup if first link
ret = self:onGoToPageLink(ges, true) ret = self:onGoToPageLink(ges, true)
elseif isSwipeToFollowNearestLinkEnabled() then elseif isSwipeToFollowNearestLinkEnabled() then
local allow_footnote_popup = isSwipeLinkFootnotePopupEnabled() local allow_footnote_popup = isFootnoteLinkInPopupEnabled()
ret = self:onGoToPageLink(ges, false, allow_footnote_popup) ret = self:onGoToPageLink(ges, false, allow_footnote_popup)
end end
-- If no link found, or no follow link option enabled, -- If no link found, or no follow link option enabled,

@ -178,7 +178,7 @@ function FootnoteWidget:init()
-- We may use a font size a bit smaller than the document one (because -- We may use a font size a bit smaller than the document one (because
-- footnotes are usually smaller, and because NotoSans is a bit on the -- footnotes are usually smaller, and because NotoSans is a bit on the
-- larger size when compared to other fonts at the same size) -- larger size when compared to other fonts at the same size)
local font_size = self.doc_font_size - 2 local font_size = self.doc_font_size + (G_reader_settings:readSetting("footnote_popup_relative_font_size") or -2)
-- We want to display the footnote text with the same margins as -- We want to display the footnote text with the same margins as
-- the document, but keep the scrollbar in the right margin, so -- the document, but keep the scrollbar in the right margin, so

@ -13,6 +13,7 @@ local LineWidget = require("ui/widget/linewidget")
local OverlapGroup = require("ui/widget/overlapgroup") local OverlapGroup = require("ui/widget/overlapgroup")
local NumberPickerWidget = require("ui/widget/numberpickerwidget") local NumberPickerWidget = require("ui/widget/numberpickerwidget")
local Size = require("ui/size") local Size = require("ui/size")
local TextBoxWidget = require("ui/widget/textboxwidget")
local TextWidget = require("ui/widget/textwidget") local TextWidget = require("ui/widget/textwidget")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
@ -22,6 +23,7 @@ local Screen = Device.screen
local SpinWidget = InputContainer:new{ local SpinWidget = InputContainer:new{
title_face = Font:getFace("x_smalltfont"), title_face = Font:getFace("x_smalltfont"),
text = nil,
width = Screen:getWidth() * 0.95, width = Screen:getWidth() * 0.95,
height = Screen:getHeight(), height = Screen:getHeight(),
value = 1, value = 1,
@ -68,6 +70,7 @@ function SpinWidget:update()
value_max = self.value_max, value_max = self.value_max,
value_step = self.value_step, value_step = self.value_step,
value_hold_step = self.value_hold_step, value_hold_step = self.value_hold_step,
precision = self.precision,
} }
local value_group = HorizontalGroup:new{ local value_group = HorizontalGroup:new{
align = "center", align = "center",
@ -127,30 +130,43 @@ function SpinWidget:update()
show_parent = self, show_parent = self,
} }
local vgroup = VerticalGroup:new{
align = "left",
value_bar,
value_line,
}
if self.text then
table.insert(vgroup, FrameContainer:new{
padding = Size.padding.default,
margin = Size.margin.small,
bordersize = 0,
TextBoxWidget:new{
text = self.text,
face = Font:getFace("x_smallinfofont"),
width = self.width * 0.9,
}
})
end
table.insert(vgroup, CenterContainer:new{
dimen = Geom:new{
w = self.width,
h = value_group:getSize().h + self.screen_height * 0.1,
},
value_group
})
table.insert(vgroup, CenterContainer:new{
dimen = Geom:new{
w = self.width,
h = ok_cancel_buttons:getSize().h,
},
ok_cancel_buttons
})
self.spin_frame = FrameContainer:new{ self.spin_frame = FrameContainer:new{
radius = Size.radius.window, radius = Size.radius.window,
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
VerticalGroup:new{ vgroup,
align = "left",
value_bar,
value_line,
CenterContainer:new{
dimen = Geom:new{
w = self.width,
h = value_group:getSize().h + self.screen_height * 0.1,
},
value_group
},
CenterContainer:new{
dimen = Geom:new{
w = self.width,
h = ok_cancel_buttons:getSize().h,
},
ok_cancel_buttons
}
}
} }
self[1] = WidgetContainer:new{ self[1] = WidgetContainer:new{
align = "center", align = "center",

Loading…
Cancel
Save