texteditor

package
v0.0.0-...-239b239 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package texteditor provides widgets and helpers shared by the text-editing example applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hotkey

func Hotkey(context *guigui.Context, key string) string

Hotkey returns the display label of a shortcut with the shortcut modifier.

func HotkeyShift

func HotkeyShift(context *guigui.Context, key string) string

HotkeyShift returns the display label of a shortcut with the Shift and the shortcut modifier.

func OpenFileAsync

func OpenFileAsync(filter *FileFilter) <-chan FileResult

OpenFileAsync shows a native open dialog on a new goroutine and delivers the result on the returned channel. A nil filter offers all files.

func SaveFileAsync

func SaveFileAsync(suggested string) <-chan FileResult

SaveFileAsync shows a native save dialog on a new goroutine and delivers the result on the returned channel. A non-empty suggested is the pre-filled file name.

func ShortcutModifierPressed

func ShortcutModifierPressed(context *guigui.Context) bool

ShortcutModifierPressed reports whether the modifier key that carries application shortcuts is pressed.

Types

type ConfirmDialog

type ConfirmDialog struct {
	guigui.DefaultWidget
	// contains filtered or unexported fields
}

ConfirmDialog is the in-app modal "you have unsaved changes" prompt with the standard Save / Don't save / Cancel triad. Using Guigui widgets keeps everything on the main goroutine, sidestepping the macOS dispatch-queue timing issue that affects native dialogs called from a non-main goroutine.

func (*ConfirmDialog) Build

func (c *ConfirmDialog) Build(context *guigui.Context, adder *guigui.ChildAdder) error

func (*ConfirmDialog) IsOpen

func (c *ConfirmDialog) IsOpen() bool

IsOpen reports whether the dialog is currently shown.

func (*ConfirmDialog) Layout

func (c *ConfirmDialog) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)

func (*ConfirmDialog) OnClose

func (c *ConfirmDialog) OnClose(fn func(context *guigui.Context, result ConfirmResult))

OnClose registers the handler that fires whenever the dialog closes, reporting which button the user picked.

func (*ConfirmDialog) SetMessage

func (c *ConfirmDialog) SetMessage(message string)

SetMessage sets the prompt text shown above the buttons.

func (*ConfirmDialog) SetOpen

func (c *ConfirmDialog) SetOpen(open bool)

SetOpen shows or hides the dialog. Opening also resets the pending result to Cancel so a previous selection that didn't get dispatched can't leak.

func (*ConfirmDialog) SetSaveEnabled

func (c *ConfirmDialog) SetSaveEnabled(enabled bool)

SetSaveEnabled sets whether the save choice can be chosen.

type ConfirmResult

type ConfirmResult int

ConfirmResult identifies how the user dismissed a ConfirmDialog. The zero value is ConfirmResultCancel so that an outside click or any close path that doesn't go through a button reports as cancellation.

const (
	ConfirmResultCancel ConfirmResult = iota
	ConfirmResultSave
	ConfirmResultDontSave
)

type Document

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

Document tracks the file path and the dirty state of an edited file.

func (*Document) DisplayName

func (d *Document) DisplayName() string

DisplayName returns the file name, or "Untitled" for an untitled document.

func (*Document) IsDirty

func (d *Document) IsDirty() bool

IsDirty reports whether the document has unsaved changes.

func (*Document) LoadInto

func (d *Document) LoadInto(path string, dst io.ReaderFrom) error

LoadInto opens the file at path and streams its contents into dst. On success the document's path is updated and dirty is cleared.

func (*Document) MarkDirty

func (d *Document) MarkDirty()

MarkDirty marks the document as having unsaved changes.

func (*Document) New

func (d *Document) New()

New resets the document to an untitled clean state.

func (*Document) Path

func (d *Document) Path() string

Path returns the file path, or an empty string for an untitled document.

func (*Document) Save

func (d *Document) Save(src io.WriterTo) error

Save streams src to the document's current path. On success dirty is cleared.

func (*Document) SaveAs

func (d *Document) SaveAs(path string, src io.WriterTo) error

SaveAs sets the path and streams src to it.

type Editor

type Editor struct {
	basicwidget.TextInput
}

Editor wraps basicwidget.TextInput so that *Editor satisfies io.WriterTo and io.ReaderFrom. The document layer can then stream through stdlib interfaces without basicwidget itself having to use those names.

func (*Editor) ReadFrom

func (e *Editor) ReadFrom(r io.Reader) (int64, error)

func (*Editor) WriteTo

func (e *Editor) WriteTo(w io.Writer) (int64, error)

type ExtraMenu

type ExtraMenu struct {
	// Text is the menu's title in the menubar.
	Text string

	// Items are the menu's popup items. Their values are reported as-is by
	// the handler set by [Menubar.OnExtraItemSelected].
	Items []basicwidget.PopupMenuItem[string]

	// ReservesCheckmarkSpace indents the items so that toggling a checkmark
	// does not shift their texts.
	ReservesCheckmarkSpace bool
}

ExtraMenu is an application-specific menu shown after the built-in menus.

type FileFilter

type FileFilter struct {
	// Description is the human-readable name of the filter.
	Description string

	// Extensions is the list of file extensions without the leading dot.
	Extensions []string
}

FileFilter restricts the files an open dialog offers.

type FileResult

type FileResult struct {
	// Path is the selected file path when the dialog was confirmed.
	Path string

	// Cancelled reports whether the user dismissed the dialog.
	Cancelled bool

	// Err is the error the dialog failed with, if any.
	Err error
}

FileResult is the outcome of an asynchronous file dialog.

type FindDialog

type FindDialog struct {
	guigui.DefaultWidget
	// contains filtered or unexported fields
}

FindDialog is the non-modal find popup docked to the top-end corner, with a query input, a match-count display, previous/next buttons, and a close button.

func (*FindDialog) Build

func (f *FindDialog) Build(context *guigui.Context, adder *guigui.ChildAdder) error

func (*FindDialog) FindNext

func (f *FindDialog) FindNext(e *Editor, query string)

FindNext selects the occurrence of query in e that follows the current selection, wrapping around to the first occurrence, and updates the count display.

func (*FindDialog) FindPrev

func (f *FindDialog) FindPrev(e *Editor, query string)

FindPrev selects the occurrence of query in e that precedes the current selection, wrapping around to the last occurrence, and updates the count display.

func (*FindDialog) IsOpen

func (f *FindDialog) IsOpen() bool

IsOpen reports whether the dialog is currently shown.

func (*FindDialog) Layout

func (f *FindDialog) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)

func (*FindDialog) OnClose

func (f *FindDialog) OnClose(fn func(context *guigui.Context))

OnClose registers the handler that fires after the popup closes.

func (*FindDialog) OnFindNext

func (f *FindDialog) OnFindNext(fn func(context *guigui.Context, query string))

OnFindNext registers the handler for the down-arrow button (and Enter on the query input). The handler receives the current query string.

func (*FindDialog) OnFindPrev

func (f *FindDialog) OnFindPrev(fn func(context *guigui.Context, query string))

OnFindPrev registers the handler for the up-arrow button (and Shift+Enter on the query input).

func (*FindDialog) OnQueryChanged

func (f *FindDialog) OnQueryChanged(fn func(context *guigui.Context, query string))

OnQueryChanged registers the handler that fires whenever the query input changes value, even mid-typing.

func (*FindDialog) Query

func (f *FindDialog) Query() string

Query returns the current query string.

func (*FindDialog) SetCount

func (f *FindDialog) SetCount(current, total int)

SetCount displays the current match index (1-based) and the total number of matches. Pass total = 0 to clear the count display.

func (*FindDialog) SetOpen

func (f *FindDialog) SetOpen(open bool)

SetOpen shows or hides the dialog. Showing it also moves the focus to the query input.

func (*FindDialog) UpdateCount

func (f *FindDialog) UpdateCount(e *Editor)

UpdateCount recomputes the "n of total" display from the dialog's current query and e's current selection.

type Menubar struct {
	guigui.DefaultWidget
	// contains filtered or unexported fields
}

Menubar is an editor application's menubar widget. It wraps basicwidget.Menubar with the File and Edit menus common to the editor examples and exposes typed event handlers (OnNew, OnOpen, ...) so that an application can register actions without dealing with menu/item indices.

func (m *Menubar) Build(context *guigui.Context, adder *guigui.ChildAdder) error
func (m *Menubar) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)
func (m *Menubar) Measure(context *guigui.Context, constraints guigui.Constraints) image.Point
func (m *Menubar) OnCopy(fn func(context *guigui.Context))

OnCopy sets the event handler invoked when the Copy item is selected.

func (m *Menubar) OnCut(fn func(context *guigui.Context))

OnCut sets the event handler invoked when the Cut item is selected.

func (m *Menubar) OnExtraItemSelected(fn func(context *guigui.Context, value string))

OnExtraItemSelected sets the event handler invoked when an item of a menu set by Menubar.SetExtraMenus is selected. value is the selected item's value.

func (m *Menubar) OnFind(fn func(context *guigui.Context))

OnFind sets the event handler invoked when the Find item is selected.

func (m *Menubar) OnNew(fn func(context *guigui.Context))

OnNew sets the event handler invoked when the New item is selected.

func (m *Menubar) OnOpen(fn func(context *guigui.Context))

OnOpen sets the event handler invoked when the Open item is selected.

func (m *Menubar) OnPaste(fn func(context *guigui.Context))

OnPaste sets the event handler invoked when the Paste item is selected.

func (m *Menubar) OnPasteWithoutStyles(fn func(context *guigui.Context))

OnPasteWithoutStyles sets the event handler invoked when the Paste Without Styles item is selected.

func (m *Menubar) OnRedo(fn func(context *guigui.Context))

OnRedo sets the event handler invoked when the Redo item is selected.

func (m *Menubar) OnSave(fn func(context *guigui.Context))

OnSave sets the event handler invoked when the Save item is selected.

func (m *Menubar) OnSaveAs(fn func(context *guigui.Context))

OnSaveAs sets the event handler invoked when the Save As item is selected.

func (m *Menubar) OnSelectAll(fn func(context *guigui.Context))

OnSelectAll sets the event handler invoked when the Select All item is selected.

func (m *Menubar) OnUndo(fn func(context *guigui.Context))

OnUndo sets the event handler invoked when the Undo item is selected.

func (m *Menubar) SetCanCopy(b bool)

SetCanCopy enables or disables the Copy item.

func (m *Menubar) SetCanCut(b bool)

SetCanCut enables or disables the Cut item.

func (m *Menubar) SetCanPaste(b bool)

SetCanPaste enables or disables the Paste item.

func (m *Menubar) SetCanRedo(b bool)

SetCanRedo enables or disables the Redo item.

func (m *Menubar) SetCanSave(b bool)

SetCanSave enables or disables the Save item.

func (m *Menubar) SetCanSaveAs(b bool)

SetCanSaveAs enables or disables the Save As item.

func (m *Menubar) SetCanUndo(b bool)

SetCanUndo enables or disables the Undo item.

func (m *Menubar) SetExtraMenus(menus []ExtraMenu)

SetExtraMenus sets the application-specific menus shown after the built-in menus.

func (m *Menubar) SetPasteWithoutStylesVisible(visible bool)

SetPasteWithoutStylesVisible sets whether the Edit menu has a Paste Without Styles item. The item is absent by default.

type StatusBar

type StatusBar struct {
	guigui.DefaultWidget
	// contains filtered or unexported fields
}

StatusBar displays the caret position of an editor.

func (*StatusBar) Build

func (s *StatusBar) Build(context *guigui.Context, adder *guigui.ChildAdder) error

func (*StatusBar) Layout

func (s *StatusBar) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)

func (*StatusBar) SetPosition

func (s *StatusBar) SetPosition(line, column int)

SetPosition sets the displayed caret position. line and column are 1-based display values; the column unit is the caller's choice.

Jump to

Keyboard shortcuts

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