[InputText, ReaderStyleTweak] Add copy/paste to NT devices (#14941)
Closes #12772.
This commit is contained in:
1 parent
3103627ff9
commit
642ec66d68
2 files changed
+150
-118
No files matched your search
@@ -13,7 +13,7 @@ local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local Geom = require("ui/geometry")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local FocusManager = require("ui/widget/focusmanager")
|
||||
local MovableContainer = require("ui/widget/container/movablecontainer")
|
||||
local Notification = require("ui/widget/notification")
|
||||
local Size = require("ui/size")
|
||||
@@ -31,7 +31,7 @@ local Screen = Device.screen
|
||||
local T = require("ffi/util").template
|
||||
|
||||
-- Simple widget for showing tweak info
|
||||
local TweakInfoWidget = InputContainer:extend{
|
||||
local TweakInfoWidget = FocusManager:extend{
|
||||
tweak = nil,
|
||||
is_global_default = nil,
|
||||
toggle_global_default_callback = function() end,
|
||||
@@ -95,6 +95,9 @@ function TweakInfoWidget:init()
|
||||
self.css_frame = FrameContainer:new{
|
||||
bordersize = Size.border.thin,
|
||||
padding = Size.padding.large,
|
||||
focusable = true,
|
||||
focus_border_size = Size.border.thick,
|
||||
focus_inner_border = true,
|
||||
TextBoxWidget:new{
|
||||
text = self.css_text,
|
||||
face = Font:getFace("infont", 16),
|
||||
@@ -158,6 +161,22 @@ function TweakInfoWidget:init()
|
||||
show_parent = self,
|
||||
}
|
||||
|
||||
-- Note: for devices with DPad but no clipboard, button_table is a FocusManager
|
||||
-- so the widget should work correctly nonetheless.
|
||||
if Device:hasDPad() and Device:hasClipboard() then
|
||||
self.css_frame.onPress = function()
|
||||
local item = self:getFocusItem()
|
||||
if item == self.css_frame then
|
||||
self:copyTextToClipboard(self.css_text)
|
||||
return true
|
||||
end
|
||||
end
|
||||
self.layout = {}
|
||||
table.insert(self.layout, 1, { self.css_frame })
|
||||
self:mergeLayoutInVertical(button_table)
|
||||
self:refocusWidget()
|
||||
end
|
||||
|
||||
self.movable = MovableContainer:new{
|
||||
FrameContainer:new{
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
@@ -206,11 +225,7 @@ function TweakInfoWidget:onTap(arg, ges)
|
||||
if ges.pos:intersectWith(self.css_frame.dimen) and Device:hasClipboard() then
|
||||
-- Tap inside CSS text copies it into clipboard (so it
|
||||
-- can be pasted into the book-specific tweak editor)
|
||||
-- (Add \n on both sides for easier pasting)
|
||||
Device.input.setClipboardText("\n"..self.css_text.."\n")
|
||||
UIManager:show(Notification:new{
|
||||
text = _("CSS text copied to clipboard"),
|
||||
})
|
||||
self:copyTextToClipboard(self.css_text)
|
||||
return true
|
||||
elseif ges.pos:notIntersectWith(self.movable.dimen) then
|
||||
-- Tap outside closes widget
|
||||
@@ -220,6 +235,15 @@ function TweakInfoWidget:onTap(arg, ges)
|
||||
return false
|
||||
end
|
||||
|
||||
function TweakInfoWidget:copyTextToClipboard(text)
|
||||
-- (Add \n on both sides for easier pasting)
|
||||
Device.input.setClipboardText("\n"..text.."\n")
|
||||
UIManager:show(Notification:new{
|
||||
text = _("CSS text copied to clipboard"),
|
||||
})
|
||||
return true
|
||||
end
|
||||
|
||||
function TweakInfoWidget:onSelect()
|
||||
if self.selected.x == 1 then
|
||||
self:toggle_global_default_callback()
|
||||
|
||||
Reference in new issue
Block a user