explorer

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2024 License: BSD-3-Clause, MIT Imports: 7 Imported by: 0

README

explorer

Go Reference

Opens the native file-dialog/file-picker.


Usage

Freestanding

  • exporer.NewExplorer:
    • Creates a instance of Explorer struct, given the config.
  • explorer.Configure:
    • Updates the current Explorer with the given config.
  • explorer.OpenFile:
    • Opens the native file dialog to open a single file.
  • explorer.SaveFile:
    • Opens the native file dialog to save a single file.

Gio

Non-Plugin:

If you want to use it without plugin, read the Freestanding instructions. We provide some helper functions, such as NewConfigFromViewEvent and such.

Plugin:

To open an single file, you can use explorer.OpenFileOp.

That will open native File Dialog/File Picker. Once the file is selected by the end-user, one explorer.OpenFileEvent will be sent to the given Tag.

gioexplorer.OpenFileOp{
    Tag: yourTag, 
    Mimetype: []mimetype.MimeType{
      {Extension: "png", Type: "image", Subtype: "png"},
      {Extension: "jpg", Type: "image", Subtype: "jpeg"},
      {Extension: "jpeg", Type: "image", Subtype: "jpeg"},
      {Extension: "gif", Type: "image", Subtype: "gif"},
      {Extension: "webp", Type: "image", Subtype: "webp"},
    },
}.Add(gtx.Ops)
Operations:

Operations must be added with .Add(gtx.Ops) method. The operation will be executed at the end of the frame.

  • gioexplorer.OpenFileOp:
    • Opens the native file dialog to open/import a single file.
  • gioexplorer.SaveFileOp:
    • Open the native file dialog to save/export a single file.

Events:

Events are response sent using the Tag and should be handled with gtx.Events().

  • gioexplorer.OpenFileEvent:
    • Sent to Tag when the user chooses the file to be read/open. That event contains one io.ReadCloser.
  • gioexplorer.SaveFileEvent:
    • Sent to Tag when the user chooses the file to save/replace. That event contains one io.WriteCloser.
  • gioexplorer.ErrorEvent:
    • Sent to Tag when some error occurs.
  • gioexplorer.CancelEvent:
    • Sent to Tag when the user closes the file-dialog or not select one valid file.

Features

Features Windows Android MacOS iOS WebAssembly FreeBSD Linux
Import File ✔*
Export File ✔*

On WASM it contains two implementations, one using File System Access API and another using the basic HTMLInputElement and such.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserDecline is returned when the user doesn't select the file.
	ErrUserDecline = errors.New("user exited the file selector without selecting a file")
	// ErrNotAvailable is return when the current OS isn't supported.
	ErrNotAvailable = errors.New("current OS not supported")
)

Functions

This section is empty.

Types

type Config

type Config struct{}

Config is the configuration for a Explorer.

type Explorer

type Explorer struct {
	// contains filtered or unexported fields
}

func NewExplorer

func NewExplorer(config Config) *Explorer

func (*Explorer) Configure

func (e *Explorer) Configure(config Config)

func (*Explorer) OpenFile

func (e *Explorer) OpenFile(mimes []mimetype.MimeType) (io.ReadCloser, error)

func (*Explorer) SaveFile

func (e *Explorer) SaveFile(name string, mime mimetype.MimeType) (io.WriteCloser, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL