Documentation
¶
Overview ¶
Package transfer describes data exchanged through the clipboard and native drag and drop. Values contain explicit representations, never Go object references. The immutable model is shared by both integrations.
Index ¶
- Variables
- type Data
- func (d Data) Files() ([]string, error)
- func (d Data) Formats() []Format
- func (d Data) Items() []Item
- func (d Data) Materialize(formats []Format) (Data, error)
- func (d Data) Preferred(formats ...Format) (Format, bool)
- func (d Data) Read(format Format) ([]byte, error)
- func (d Data) Snapshot() Data
- func (d Data) URLs() ([]string, error)
- type DragOptions
- type Drop
- type DropOptions
- type Format
- type Item
- type Offer
- type Operation
- type Representation
- type Result
Constants ¶
This section is empty.
Variables ¶
var ErrFormat = errors.New("transfer: representation unavailable")
ErrFormat means the requested item or representation is not available.
var ErrProviderPanic = errors.New("transfer: provider panicked")
ErrProviderPanic means a lazy provider panicked. The panic is contained at the data boundary, rather than escaping through a native callback.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data is an immutable collection of items. Its zero value is empty.
func FileData ¶
FileData offers existing file paths as file URLs, one item per path. Paths must be absolute. It neither reads nor deletes the files.
func (Data) Files ¶
Files returns local file paths only. Remote file authorities and other URL schemes are ignored, so a network URL never becomes a filesystem path.
func (Data) Materialize ¶
Materialize copies matching representations into data with no providers. A failed representation rejects the transfer; an empty match is ErrFormat.
func (Data) Preferred ¶
Preferred chooses the first preferred format advertised by the data, without invoking any provider. The caller supplies its own preference order (for example, custom JSON before HTML before plain text).
func (Data) Read ¶
Read reads a format for platforms with a single selection/data object. Text items are joined with newlines and URI lists with CRLF. Other formats use the first item offering them; macOS preserves separate items.
type DragOptions ¶
type DragOptions struct {
Operations Operation
// Preview is copied at drag start. Hotspot is in image pixels; the
// preview is displayed in DIPs (one pixel per DIP).
Preview image.Image
Hotspot image.Point
// Done runs on the main thread exactly once, including cancellation,
// startup failure and source-window destruction. Delete or remove the
// original only after a successful Move; Golet never deletes files.
Done func(Result)
}
DragOptions configures a native source. The default operation is copy.
type Drop ¶
Drop is a completed transfer. Its data is independent of the native session and can be read later, from any goroutine.
type DropOptions ¶
DropOptions describes a destination. At least one offered format must match Formats. Empty Formats accepts none; zero Operations permits copy.
type Format ¶
type Format string
Format names a representation. Use a MIME type for custom serialized data.
const ( Text Format = "text/plain" HTML Format = "text/html" URIList Format = "text/uri-list" // FileList is a URI list known to contain local files. Backends expose // it as the system's file-list format as well as text/uri-list. FileList Format = "application/x-golet-file-list" PNG Format = "image/png" // Markdown is Markdown's text (RFC 7763), net.daringfireball.markdown // on macOS. Markdown Format = "text/markdown" )
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item is a value with alternative representations, in preference order. For example, one item can offer HTML and plain text of the same content.
func NewItem ¶
func NewItem(reps ...Representation) Item
NewItem makes an item. Duplicate formats and zero representations panic.
type Operation ¶
type Operation uint8
Operation is a native drag effect, or a bitmask of allowed effects.
type Representation ¶
type Representation struct {
// contains filtered or unexported fields
}
Representation is one format of an item, made with Bytes or Lazy.
func Bytes ¶
func Bytes(format Format, b []byte) Representation
Bytes makes a representation, copying b. Empty data is valid.
func Lazy ¶
func Lazy(format Format, provider func() ([]byte, error)) Representation
Lazy advertises a format without producing its bytes. The provider runs at most once per snapshot, when a destination requests this format; failures are cached too. Native integrations call it on the main thread. It must return promptly and must not wait for another main-thread action. Prepare expensive data on a goroutine before offering it.
type Result ¶
type Result struct {
Operation Operation
// Canceled reports that the drag ended without a drop: let go over
// no target, or canceled.
Canceled bool
// Escaped reports that a canceled drag was given up (Escape,
// Window.CancelDataDrag, or the source window closing), rather than
// let go over no target.
Escaped bool
// Point is where the drag ended, in screen coordinates, as
// Screen.CursorScreenPoint reports them.
Point image.Point
Err error
}
Result reports the destination's final effect. None means no drop.