Documentation
¶
Overview ¶
Package transfer contains operations and events for brokering data transfers.
The transfer protocol is as follows:
- Data sources use SourceFilter to receive a RequestEvent when data is requested. Sources respond to requests with OfferCmd.
- Data targets use TargetFilter to receive data through a DataEvent. The target must close the reader returned by DataEvent.Open after use.
When a user initiates a pointer-guided drag and drop transfer, the potential targets receive an InitiateEvent. Potential targets are targets with at least one MIME type in common with the source. When a drag gesture completes, a CancelEvent is sent to the source and all potential targets.
The RequestEvent is sent to the source upon drop.
Files dropped from another application use the MIME type "text/uri-list". DataEvent.Open returns file URIs separated by CRLF, not file contents. The platform supplies the data.
File drops are currently supported on Windows and macOS. These implementations report the drop after the files are released. Targets receive InitiateEvent and CancelEvent at that point; the selected target also receives DataEvent.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CancelEvent ¶
type CancelEvent struct{}
CancelEvent is sent to data sources and targets to cancel the effects of an InitiateEvent.
func (CancelEvent) ImplementsEvent ¶
func (CancelEvent) ImplementsEvent()
type DataEvent ¶
type DataEvent struct {
// Type is the MIME type of Data.
Type string
// Open returns the transfer data. It is only valid to call Open in the frame
// the DataEvent is received. The caller must close the return value after use.
Open func() io.ReadCloser
}
DataEvent is sent to the target receiving the transfer.
func (DataEvent) ImplementsEvent ¶
func (DataEvent) ImplementsEvent()
type InitiateEvent ¶
type InitiateEvent struct{}
InitiateEvent is sent to potential data targets when a drag-and-drop transfer gesture is initiated.
func (InitiateEvent) ImplementsEvent ¶
func (InitiateEvent) ImplementsEvent()
type OfferCmd ¶
type OfferCmd struct {
Tag event.Tag
// Type is the MIME type of Data.
// It must be the Type from the corresponding RequestEvent.
Type string
// Data contains the offered data. It is closed when the
// transfer is complete or cancelled.
// Data must be kept valid until closed, and it may be used from
// a goroutine separate from the one processing the frame.
Data io.ReadCloser
}
OfferCmd is used by data sources as a response to a RequestEvent.
func (OfferCmd) ImplementsCommand ¶
func (OfferCmd) ImplementsCommand()
type RequestEvent ¶
type RequestEvent struct {
// Type is the first matched type between the source and the target.
Type string
}
RequestEvent requests data from a data source. The source must respond with an OfferCmd.
func (RequestEvent) ImplementsEvent ¶
func (RequestEvent) ImplementsEvent()
type SourceFilter ¶
type SourceFilter struct {
// Target is a tag included in a previous event.Op.
Target event.Tag
// Type is the MIME type supported by this source.
Type string
}
SourceFilter filters for any RequestEvent that match a MIME type as well as InitiateEvent and CancelEvent. Use multiple filters to offer multiple types.
func (SourceFilter) ImplementsFilter ¶
func (SourceFilter) ImplementsFilter()
type TargetFilter ¶
type TargetFilter struct {
// Target is a tag included in a previous event.Op.
Target event.Tag
// Type is the MIME type accepted by this target.
Type string
}
TargetFilter filters for any DataEvent whose type matches a MIME type as well as InitiateEvent and CancelEvent. Use multiple filters to accept multiple types.
func (TargetFilter) ImplementsFilter ¶
func (TargetFilter) ImplementsFilter()