forked from joejulian/gio
io/clipboard,app: add WriteOp, ReadOp
Previously, the only way to manipulate the clipboard (read or write) is using the `app.Window`. The new `clipboard.ReadOp` and `clipboard.WriteOp`makes possible to read/write from the widget. Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/clipboard"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
type Router struct {
|
||||
pqueue pointerQueue
|
||||
kqueue keyQueue
|
||||
cqueue clipboardQueue
|
||||
|
||||
handlers handlerEvents
|
||||
|
||||
@@ -88,6 +90,8 @@ func (q *Router) Add(events ...event.Event) bool {
|
||||
q.pqueue.Push(e, &q.handlers)
|
||||
case key.EditEvent, key.Event, key.FocusEvent:
|
||||
q.kqueue.Push(e, &q.handlers)
|
||||
case clipboard.Event:
|
||||
q.cqueue.Push(e, &q.handlers)
|
||||
}
|
||||
}
|
||||
return q.handlers.HadEvents()
|
||||
@@ -99,6 +103,18 @@ func (q *Router) TextInputState() TextInputState {
|
||||
return q.kqueue.InputState()
|
||||
}
|
||||
|
||||
// WriteClipboard returns the most recent text to be copied
|
||||
// to the clipboard, if any.
|
||||
func (q *Router) WriteClipboard() (string, bool) {
|
||||
return q.cqueue.WriteClipboard()
|
||||
}
|
||||
|
||||
// ReadClipboard reports if any new handler is waiting
|
||||
// to read the clipboard.
|
||||
func (q *Router) ReadClipboard() bool {
|
||||
return q.cqueue.ReadClipboard()
|
||||
}
|
||||
|
||||
func (q *Router) collect() {
|
||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||
switch opconst.OpType(encOp.Data[0]) {
|
||||
@@ -115,6 +131,10 @@ func (q *Router) collect() {
|
||||
}
|
||||
q.profiling = true
|
||||
q.profHandlers[op.Tag] = struct{}{}
|
||||
case opconst.TypeClipboardRead:
|
||||
q.cqueue.ProcessReadClipboard(encOp.Data, encOp.Refs)
|
||||
case opconst.TypeClipboardWrite:
|
||||
q.cqueue.ProcessWriteClipboard(encOp.Data, encOp.Refs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user