gexplorer

package module
v0.0.0-...-7fd9240 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 11 Imported by: 0

README

GODOC

gexplorer

gexplorer is a package that provides file dialog for several OSes. It aims to be not dependent of any GUI framework.

Supported operations:

  • CreateFile
  • ChooseFile
  • ChooseFiles

Supported OSes:

  • Linux
    • Fedora
  • macOS
    • Big Sur 11.6.8
  • Windows
    • 11

Supported GUI frameworks:

  • Gio UI using github.com/mdouchement/gexplorer/gioexplorer

This project is based on https://github.com/gioui/gio-x/tree/main/explorer work

License

MIT

Contributing

All PRs are welcome.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Overview

Package gexplorer is based on https://github.com/gioui/gio-x/blob/main/explorer This version only wants to work with filename/filepath which is more flexible than any other types.

Given the filename/filepath, the caller of this package is able to do whatever it want.

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 Explorer

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

Explorer facilitates opening OS-native dialogs to choose files and create files.

func NewExplorer

func NewExplorer(run RunHandler) (e *Explorer)

NewExplorer creates a new Explorer for the given RunHandler. The given RunHandler must be unique and you should call NewExplorer once per new RunHandler.

func (*Explorer) ChooseFile

func (e *Explorer) ChooseFile(extensions ...string) (string, error)

ChooseFile shows the file selector, allowing the user to select a single file. Optionally, it's possible to define which file extensions is supported to be selected (such as `.jpg`, `.png`).

Example: ChooseFile(".jpg", ".png") will only accept the selection of files with .jpg or .png extensions.

In most known browsers, when user clicks cancel then this function never returns.

It's a blocking call, you should call it on a separated goroutine. For most OSes, only one ChooseFile or CreateFile, can happen at the same time, for each Explorer.

func (*Explorer) ChooseFiles

func (e *Explorer) ChooseFiles(extensions ...string) ([]string, error)

ChooseFiles shows the files selector, allowing the user to select multiple files. Optionally, it's possible to define which file extensions is supported to be selected (such as `.jpg`, `.png`).

Example: ChooseFiles(".jpg", ".png") will only accept the selection of files with .jpg or .png extensions.

In most known browsers, when user clicks cancel then this function never returns.

It's a blocking call, you should call it on a separated goroutine. For most OSes, only one ChooseFile{,s} or CreateFile, can happen at the same time, for each Explorer.

func (*Explorer) CreateFile

func (e *Explorer) CreateFile(name string) (string, error)

CreateFile opens the file selector, and writes the given content into some file, which the use can choose the location.

It's a blocking call, you should call it on a separated goroutine. For most OSes, only one ChooseFile or CreateFile, can happen at the same time, for each Explorer.

func (*Explorer) SetView

func (e *Explorer) SetView(v uintptr)

SetView sets the view/window to the dialod interface.

type RunHandler

type RunHandler func(func())

RunHandler allows to run a function in the context of another thread. Mainly used for https://pkg.go.dev/gioui.org@v0.0.0-20230502183330-59695984e53c/app#Window.Run

Directories

Path Synopsis
_examples
gio

Jump to

Keyboard shortcuts

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