app

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 46 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package app holds ZPad's state and builds its window.

Index

Constants

View Source
const (
	LogName = "zpad.log"
)

The diagnostic log, next to the settings: what mygo says of the renderer it chose, and how long the app's frames and file operations take. A Windows build is a GUI program without a console, so what mygo prints there would otherwise be lost.

View Source
const MenuBarHeight = 32

MenuBarHeight is the height of the menu bar Windows draws as its title bar. main.go passes it as mygo.WindowOptions.TitleBarHeight, so the system's window buttons fill the same band.

Variables

View Source
var Version = "dev"

Version is the version the status bar and the About dialog show. main sets it from mygo.json, which mygo build links in: that file is the app's only version, so a release bumps one file. It is "dev" until then, as under go test or go run.

Functions

func CleanupPreviewCache added in v0.8.0

func CleanupPreviewCache()

CleanupPreviewCache removes any temporary directory created for remote Markdown preview images.

func NoteFrame added in v0.2.0

func NoteFrame(d time.Duration)

NoteFrame records how long a frame took to build and paint, and writes a summary when frames have been running slow. It times the app's own work on the main thread, not the GPU's present: a summary points at the editor, while a log quiet through a stuttering window points at the renderer.

func SetThemeSource

func SetThemeSource(id string)

SetThemeSource applies a theme's appearance to the native window chrome before App.Run and when the theme changes: a named theme keeps the light or dark title bar it is built on, "system" follows the desktop.

func SetVersion added in v0.2.0

func SetVersion(v string)

SetVersion records the version mygo build or mygo dev linked in; an empty one, as from a plain go build, keeps the default.

func SetupLogging added in v0.2.0

func SetupLogging(dir string) string

SetupLogging sends the standard logger to dir/zpad.log and to stderr, so that what mygo logs survives a build without a console, and returns the path it opened. It returns "" when logging is off (ZPAD_LOG=off) or the file cannot be written: logging never keeps the editor from starting. ZPAD_LOG names another file.

func TextExtensions

func TextExtensions() []string

TextExtensions returns the extensions the open dialog offers as text.

Types

type App

type App struct {
	Settings    settings.Settings
	SettingsDir string
	// LogPath is where SetupLogging writes, "" when logging is off.
	LogPath string
	// Dark reports whether the current theme is built on a dark palette.
	// Settings.Theme says which theme it is.
	Dark bool
	// contains filtered or unexported fields
}

App is the state the window shows.

func New

func New(s settings.Settings, settingsDir string) *App

New returns an app with saved settings and the directory to save them in.

func (*App) Attach

func (a *App) Attach(win *mygo.Window)

Attach remembers the window, installs the menu and takes dropped files.

func (*App) BeforeQuit

func (a *App) BeforeQuit(e *mygo.QuitEvent)

BeforeQuit asks to save before the application quits.

func (*App) CloseActiveTab

func (a *App) CloseActiveTab()

CloseActiveTab closes the active tab.

func (*App) CloseTab

func (a *App) CloseTab(paneIdx, i int)

CloseTab closes tab i of a pane, asking to save when it has changes.

func (*App) ConvertCase

func (a *App) ConvertCase(mode caseconv.Mode)

ConvertCase changes the case of the active tab's selections.

func (*App) HandleOpenFile

func (a *App) HandleOpenFile(path string)

HandleOpenFile opens a file the system asks the app to show. Before the window exists, it keeps the path for Attach.

func (*App) HandleSecondInstance

func (a *App) HandleSecondInstance(args []string, dir string)

HandleSecondInstance opens what a later launch was asked to open and brings this window forward. Windows and Linux start a process per file opened from the file manager, whose command line arrives here; that process exits at once.

func (*App) InstallMenu

func (a *App) InstallMenu()

InstallMenu builds the application menu.

func (*App) NewFile

func (a *App) NewFile()

NewFile adds an untitled document. The menu's CmdOrCtrl+N runs it with no frame of the view around it, so it asks for the frame that shows the tab.

func (*App) OpenActiveInBrowser added in v0.2.0

func (a *App) OpenActiveInBrowser()

OpenActiveInBrowser opens the active tab's file in the system browser. Unsaved changes are saved first, so the browser shows what the editor shows.

func (*App) OpenCommandLine

func (a *App) OpenCommandLine(args []string)

OpenCommandLine opens the files and folders this process was started with, skipping flags.

func (*App) OpenFileDialog

func (a *App) OpenFileDialog()

OpenFileDialog asks for files and opens them.

func (*App) OpenFolderDialog

func (a *App) OpenFolderDialog()

OpenFolderDialog asks for a workspace directory.

func (*App) OpenLog added in v0.2.0

func (a *App) OpenLog()

OpenLog opens the diagnostic log in a tab: what mygo said of the renderer, the files opened, and the frames that ran slow.

func (*App) OpenPaths

func (a *App) OpenPaths(paths []string)

OpenPaths opens files and directories. It reads files off the UI thread.

func (*App) Prepare

func (a *App) Prepare()

Prepare marks the app as running and resolves the system appearance. Call it on the main thread once the app is ready, before the window.

func (*App) Redo

func (a *App) Redo()

Redo makes the active buffer's last undone edit again.

func (*App) ReopenWithEncoding

func (a *App) ReopenWithEncoding(kind encoding.Kind)

ReopenWithEncoding reads the active file again as kind.

func (*App) RestoreSession

func (a *App) RestoreSession()

RestoreSession loads the workspace of the last launch, when the user asked for it, and the unsaved text kept for this launch, whether they asked to restore the session or not.

func (*App) SaveActive

func (a *App) SaveActive()

SaveActive saves the active tab.

func (*App) SaveAsActive

func (a *App) SaveAsActive()

SaveAsActive saves the active tab under another name.

func (*App) SaveWithEncoding

func (a *App) SaveWithEncoding(kind encoding.Kind)

SaveWithEncoding saves the active tab in kind.

func (*App) SelectLanguage added in v0.5.1

func (a *App) SelectLanguage(lang *editor.Language)

SelectLanguage gives the active untitled document the language chosen in the status bar, which changes its highlight, the name its save starts from, and whether it can be previewed as Markdown. A file that already has a path takes its language from that path, so renaming it is how its highlight changes.

func (*App) SetAppIcon added in v0.2.0

func (a *App) SetAppIcon(data []byte)

SetAppIcon gives the About dialog the icon the app embeds. mygo build reads the same PNG for the app's own icon, and mygo.json's resourcesExclude keeps it out of the app, so that no file beside the app carries it: the binary does.

func (*App) SetError

func (a *App) SetError(msg string)

SetError shows an error in the status bar, for a failure that has no better home: one the user must act on while its document is open.

Actions that end, as opening a file does, tell with SetErrorToast instead, so that a message the user cannot act on does not stay.

func (*App) SetErrorToast added in v0.2.0

func (a *App) SetErrorToast(title, detail string)

SetErrorToast tells near the bottom of the window that something the user asked for did not happen: title says what, detail why, and it goes away on its own.

func (*App) SetLineEnding

func (a *App) SetLineEnding(eol string)

SetLineEnding converts every line of the active tab to eol.

func (*App) SetToast

func (a *App) SetToast(msg string)

SetToast shows a message near the bottom of the window once.

func (*App) ShowActiveInFileManager

func (a *App) ShowActiveInFileManager()

ShowActiveInFileManager reveals the active file in the system file manager.

func (*App) ToggleMarkdownPreview added in v0.2.0

func (a *App) ToggleMarkdownPreview()

ToggleMarkdownPreview shows the active Markdown tab as rendered Markdown, or returns it to the editor.

func (*App) Undo

func (a *App) Undo()

Undo takes back the active buffer's last edit.

func (*App) View

func (a *App) View(c *ui.Context)

View builds the window: toolbar, sidebar and content, status bar.

type Document

type Document struct {
	ID       string
	Path     string
	Buffer   *editor.Buffer
	Encoding encoding.Kind
	// Language is the file's language, shown in the status bar; the buffer
	// gets it only when the file is short enough to highlight.
	Language *editor.Language
	Size     int64
	ModTime  time.Time
	ReadOnly bool
	// UntitledSeq is the number the document was created with, for the name
	// its save dialog starts from; 0 for a document with a path.
	UntitledSeq int

	// DraftID names the recovery copy of the document's unsaved text. It
	// stays the same across renames and saves, so that a copy is dropped or
	// rewritten rather than looked for by path.
	DraftID string
	// contains filtered or unexported fields
}

Document is an open file and the text the editor edits.

func (*Document) DisplayPath

func (d *Document) DisplayPath(root string) string

DisplayPath is the path relative to root when it is inside it.

func (*Document) Name

func (d *Document) Name() string

name is what the tab, the title and the prompts call the document: a saved file by its file name, an untitled one by the number it was created with. The number stays as the other tabs close, so that a prompt naming one points at it rather than at whichever tab moved into its place.

func (*Document) PreviewText added in v0.2.0

func (d *Document) PreviewText() string

PreviewText returns the buffer's text, copied only when it has changed.

type Pane

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

Pane is one side of the window: its tabs and the one chosen.

type Tab

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

Tab is one open document and the editor state showing it.

Jump to

Keyboard shortcuts

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