filedialog

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 0 Imported by: 0

README

filedialog

Native open/save file panels, cgo-free.

path := filedialog.Open(filedialog.Options{
    Title:      "Open scene",
    Extensions: []string{"afoil"},
})
if path != "" {
    // user picked a file
}

out := filedialog.Save(filedialog.Options{
    Title:    "Save scene",
    Filename: "untitled.afoil",
})

Each call returns the chosen path, or "" when the user cancels.

Threading

The panels are platform UI and must be called on the main thread. This package deliberately does not impose a threading model; the caller arranges to be on the main thread. For an Ebitengine app:

var path string
ebiten.RunOnMainThread(func() {
    path = filedialog.Open(filedialog.Options{Extensions: []string{"afoil"}})
})

Platforms

  • macOS: NSOpenPanel / NSSavePanel via purego's Objective-C runtime.
  • Linux, Windows: not implemented yet (the calls return ""); GTK and Win32 backends can be ported in.

Documentation

Overview

Package filedialog shows the operating system's native open and save file panels, cgo-free.

Threading: the panels are platform UI (AppKit, GTK, Win32) and must be invoked on the program's main thread. This package does not impose a threading model — the caller is responsible for already being on the main thread. For example, an Ebitengine app wraps the call in ebiten.RunOnMainThread, and a webview host uses its own UI-thread dispatch.

Each function returns the chosen path, or "" when the user cancels (or on a platform without an implementation yet).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(_ Options) string

Open is the no-op stub; see the darwin build for the real implementation.

func Save

func Save(_ Options) string

Save is the no-op stub; see the darwin build for the real implementation.

Types

type Options

type Options struct {
	// Title is the prompt shown prominently above the file list.
	Title string

	// Directory is the initial directory, as a filesystem path. Empty uses the
	// platform default (usually the last-used directory).
	Directory string

	// Filename is the suggested file name. Used by Save and ignored by Open.
	Filename string

	// Extensions restricts selectable files to these extensions, given without
	// the leading dot (e.g. {"afoil", "dat"}). Empty, or any "*"/"" entry,
	// allows all files.
	Extensions []string
}

Options configures a file panel. The zero value is valid: a default panel rooted at the platform's default directory with no type filtering.

Jump to

Keyboard shortcuts

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