Documentation
¶
Overview ¶
Package workspace is the desktop app's workspace model (docs/design/app.md#workspace, plan 0009): a tree of splits and tab groups, two sidebars of panes, the tabs closed lately, the files opened lately and the Files pane's sort and open folders. It ports app/src/workspace's model and operations, which the web app keeps; here the operations change a workspace in place on the UI thread, and the store keeps one per vault in a versioned JSON file (ADR-0021).
Index ¶
- Constants
- Variables
- func WhereFor(ctrl, alt bool, button int) string
- type ClosedTab
- type FilesPane
- type MergeSide
- type Node
- type Sidebar
- type Store
- type Tab
- type View
- type Workspace
- func (w *Workspace) Activate(tabID string)
- func (w *Workspace) ActiveGroup() *Node
- func (w *Workspace) ActiveTab() *Tab
- func (w *Workspace) ApplyDelete(p string)
- func (w *Workspace) ApplyMove(from, to string)
- func (w *Workspace) Back()
- func (w *Workspace) Clone() *Workspace
- func (w *Workspace) Close(tabID string)
- func (w *Workspace) CloseAll(groupID string)
- func (w *Workspace) CloseOthers(tabID string)
- func (w *Workspace) CloseToTheRight(tabID string)
- func (w *Workspace) Cycle(delta int)
- func (w *Workspace) FindGroup(id string) *Node
- func (w *Workspace) FindTab(id string) (*Node, int)
- func (w *Workspace) Forward()
- func (w *Workspace) GotoLastTab()
- func (w *Workspace) GotoTab(n int)
- func (w *Workspace) MoveTab(tabID, groupID string, index int, edge string)
- func (w *Workspace) Open(v View, where string)
- func (w *Workspace) Pin(tabID string, pinned bool)
- func (w *Workspace) ReopenClosed()
- func (w *Workspace) Resize(splitID string, sizes []float64)
- func (w *Workspace) RevealPath(p string)
- func (w *Workspace) SelectPane(side, pane string)
- func (w *Workspace) SetFolderOpen(folder string, open bool)
- func (w *Workspace) SetSidebarWidth(side string, width float64)
- func (w *Workspace) SetView(tabID string, v View)
- func (w *Workspace) Split(tabID, where string)
- func (w *Workspace) ToggleSidebar(side string)
Constants ¶
const ( MaxHistory = 50 MaxClosed = 20 MaxRecent = 50 MaxExpanded = 1000 // Sidebar widths (docs/specs/ui.md#layout). SidebarMin = 200 SidebarMax = 600 LeftWidth = 260 RightWidth = 300 )
The workspace's limits, as the web app's.
const ( ViewEmpty = "empty" ViewNote = "note" ViewHistory = "history" ViewMerge = "merge" ViewFile = "file" )
The kinds of view.
const ( ModeEdit = "edit" ModeRead = "read" )
The modes of a note view.
const ( KindSplit = "split" KindTabs = "tabs" )
The kinds of node.
const ( Row = "row" Column = "column" )
The directions of a split: side by side, or stacked.
const ( SideLeft = "left" SideRight = "right" )
The sidebars and their panes (docs/specs/ui.md#sidebars-and-panes).
const ( Here = "here" NewTab = "tab" ToRight = "right" Below = "down" )
Where a view opens: in the active tab, a new tab, or a new group to the right or below.
const ( EdgeLeft = "left" EdgeRight = "right" EdgeTop = "top" EdgeBottom = "bottom" )
The edges of a tab group, where a dropped tab makes a new split.
const ( // SaveDelay is how long after the last change the workspace is written. SaveDelay = 500 * time.Millisecond // SaveRetry is how long after a failed write it is tried again. SaveRetry = 5 * time.Second )
const Version = 1
Version is the stored workspace's version.
Variables ¶
var Panes = map[string][]string{ SideLeft: {"files", "search"}, SideRight: {"backlinks", "outgoing", "tags", "properties", "outline", "tasks"}, }
Panes are each sidebar's panes, in order.
Functions ¶
Types ¶
type MergeSide ¶
type MergeSide struct {
Kind string `json:"kind"` // version, revision or held
Version int64 `json:"version,omitzero"`
Seq int64 `json:"seq,omitzero"`
}
MergeSide is the other side of a merge view: a version of the file, a hub revision, or the text the editor held when notesd refused its base (in memory only: a stored workspace drops it).
type Node ¶
type Node struct {
Kind string `json:"kind"`
ID string `json:"id"`
Direction string `json:"direction,omitzero"`
Children []*Node `json:"children,omitzero"`
Sizes []float64 `json:"sizes,omitzero"`
Tabs []Tab `json:"tabs,omitzero"`
Active int `json:"active"`
}
Node is a split or a tab group. A split lays out at least two children with sizes that sum to 1; a group holds at least one tab and its active one.
type Sidebar ¶
type Sidebar struct {
Panes []string `json:"panes"`
Active int `json:"active"`
Width float64 `json:"width"`
Open bool `json:"open"`
}
Sidebar is a sidebar: its panes, the selected one, its width and whether it is open.
type Store ¶
type Store struct {
// Err is the last write's failure, nil when it worked.
Err error
// OnError is told of a new failure.
OnError func(error)
// contains filtered or unexported fields
}
Store is the window's vault's workspace, kept in a file per vault and written SaveDelay after the last change (ADR-0021). UI thread only.
func (*Store) Follow ¶
Follow applies a move or delete to the workspace of the vault it happened in: the window's when that vault is shown, else the stored one, so tabs follow what happened while another vault was shown.
func (*Store) Reset ¶
func (s *Store) Reset()
Reset forgets the window's vault's layout (Reset workspace layout).
type Tab ¶
type Tab struct {
ID string `json:"id"`
View View `json:"view"`
// Back and Forward are the views to go back and forward to, the
// nearest last; at most MaxHistory.
Back []View `json:"back"`
Forward []View `json:"forward"`
Pinned bool `json:"pinned"`
}
Tab is a tab: its view and the views before and after it.
type View ¶
type View struct {
Type string `json:"type"`
Path string `json:"path,omitzero"`
Mode string `json:"mode,omitzero"`
Scroll float64 `json:"scroll,omitzero"`
Cursor int `json:"cursor,omitzero"`
Other *MergeSide `json:"other,omitzero"`
}
View is what a tab shows.
type Workspace ¶
type Workspace struct {
Version int `json:"version"`
Root *Node `json:"root"`
ActiveID string `json:"activeGroup"` // the group holding the active tab
Left Sidebar `json:"left"`
Right Sidebar `json:"right"`
Closed []ClosedTab `json:"closed"`
Recent []string `json:"recent"`
Files FilesPane `json:"files"`
NextID int `json:"nextId"`
}
Workspace is one vault's layout.
func New ¶
func New() *Workspace
New is a vault's first layout: one empty tab, both sidebars open on their first pane.
func Validate ¶
Validate reads a stored workspace, keeping what it understands and dropping the rest, so a stored layout never wedges the window; it returns a new workspace when nothing is left.
func (*Workspace) Activate ¶
Activate makes a tab its group's active tab and its group the active group.
func (*Workspace) ActiveGroup ¶
ActiveGroup is the group holding the window's active tab.
func (*Workspace) ApplyDelete ¶
ApplyDelete forgets a deleted file in history and the recent files; a tab showing it stays, saying so, until it is closed or the file comes back.
func (*Workspace) ApplyMove ¶
ApplyMove follows a file or folder moved from one path to another, in every view, history and list.
func (*Workspace) CloseOthers ¶
CloseOthers closes a group's unpinned tabs but one.
func (*Workspace) CloseToTheRight ¶
CloseToTheRight closes a group's unpinned tabs after one.
func (*Workspace) Cycle ¶
Cycle activates the next (1) or previous (-1) tab of the active group, wrapping.
func (*Workspace) GotoLastTab ¶
func (w *Workspace) GotoLastTab()
GotoLastTab activates the active group's last tab.
func (*Workspace) GotoTab ¶
GotoTab activates the active group's nth tab, counting from 1; past the end, nothing.
func (*Workspace) MoveTab ¶
MoveTab moves a tab into a group at an index, or, with an edge, to that edge of the group as a new group.
func (*Workspace) Open ¶
Open shows v: in the active tab, which keeps its old view to go back to, unless it is pinned; in a new tab after the active one; or in a new group to the right of or below the active group.
func (*Workspace) ReopenClosed ¶
func (w *Workspace) ReopenClosed()
ReopenClosed reopens the tab closed last where it was, or after the active tab when its group is gone.
func (*Workspace) RevealPath ¶
RevealPath opens every folder holding p, so its row shows.
func (*Workspace) SelectPane ¶
SelectPane shows a pane in its sidebar, opening the sidebar.
func (*Workspace) SetFolderOpen ¶
SetFolderOpen opens or closes a folder in the Files pane.
func (*Workspace) SetSidebarWidth ¶
SetSidebarWidth sets a sidebar's width, between SidebarMin and SidebarMax.
func (*Workspace) SetView ¶
SetView changes a tab's view without history: its scroll, cursor or mode.
func (*Workspace) Split ¶
Split opens a copy of a tab's view in a new group to its right or below its group.
func (*Workspace) ToggleSidebar ¶
ToggleSidebar opens or closes a sidebar.