[feat] Add Device:hasClipboard() (#3465)

References https://github.com/koreader/koreader/issues/3441
This commit is contained in:
Frans de Jonge
2017-11-14 19:20:58 +01:00
committed by GitHub
parent aa7d4f9751
commit 06dfe4fb78
3 changed files with 18 additions and 2 deletions

View File

@@ -383,8 +383,11 @@ function ReaderHighlight:onHoldRelease()
},
{
{
text = "-",
enabled = false,
text = "Copy",
enabled = Device:hasClipboard(),
callback = function()
Device.input.setClipboardText(self.selected_text.text)
end,
},
{
text = _("Translate"),

View File

@@ -24,6 +24,7 @@ local Device = {
isTouchDevice = no,
hasFrontlight = no,
needsTouchScreenProbe = no,
hasClipboard = no,
hasColorScreen = no,
-- use these only as a last resort. We should abstract the functionality

View File

@@ -34,10 +34,22 @@ function Device:init()
end
if util.haveSDL2() then
self.hasClipboard = yes
self.screen = require("ffi/framebuffer_SDL2_0"):new{device = self, debug = logger.dbg}
local input = require("ffi/input")
self.input = require("device/input"):new{
device = self,
event_map = require("device/sdl/event_map_sdl2"),
hasClipboardText = function()
return input.hasClipboardText()
end,
getClipboardText = function()
return input.getClipboardText()
end,
setClipboardText = function(text)
return input.setClipboardText(text)
end,
}
else
self.screen = require("ffi/framebuffer_SDL1_2"):new{device = self, debug = logger.dbg}