morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::ui::WorkspaceModel Class Reference

The workspace's tabs with no widgets: which screens are open, in which order, which is active, and how they open, close and are recorded (spec 6 §7, §15). More...

#include <workspace_model.hpp>

Public Member Functions

 WorkspaceModel (reactive::Runtime &runtime, DocumentScreenHost &host, WorkspaceModelOptions options)
 An empty workspace.
 ~WorkspaceModel ()
 Unmounts every screen without asking, newest first.
 WorkspaceModel (WorkspaceModel const &)=delete
WorkspaceModel & operator= (WorkspaceModel const &)=delete
 WorkspaceModel (WorkspaceModel &&)=delete
WorkspaceModel & operator= (WorkspaceModel &&)=delete
std::expected< WorkspaceTabId, MountError > open (std::string_view screenId, ParamMap const &params)
 Opens a screen, or focuses the tab that already shows it; the tab opened or focused is the active one.
std::size_t start (WorkspaceStart const &how)
 Opens the start screens: with resume, every recorded route whose screen is known and available, in order, and the fallback when none of them opened; otherwise the start screen. The first tab opened is the active one.
void activate (WorkspaceTabId tab)
 Shows a tab and makes it the most recently used.
void next ()
 Shows the next tab in most-recently-used order (Ctrl+Tab). Repeated calls walk the order as it was at the first of them; any other activation starts a new walk.
void previous ()
 Shows the previous tab in most-recently-used order (Ctrl+Shift+Tab).
void close (WorkspaceTabId tab, std::function< void(bool)> done)
 Closes a tab through its screen's close protocol.
void closeOthers (WorkspaceTabId tab, std::function< void(bool)> done)
 Closes every tab but one, one at a time, stopping at the first veto.
void closeAll (std::function< void(bool)> done)
 Closes every tab, one at a time, stopping at the first veto.
void closeSaved (std::function< void(bool)> done)
 Closes every tab without unsaved changes, one at a time, stopping at the first veto.
void forceCloseAll ()
 Closes every tab without asking, newest first: what signing out does, since no close guard may keep a screen of the principal who is leaving.
void flushRecord ()
 Writes the record now, cancelling a pending debounced write: what sign-out does before the session is cleared.
std::vector< std::string > record () const
 The record as it would be written now: the routes of the open tabs, in order.
reactive::Computed< std::vector< WorkspaceTabState > > const & tabs () const
 The open tabs, in order, each with its screen, identity, title and unsaved state. A tab's values follow its handle.
reactive::Computed< std::optional< WorkspaceTabId > > const & active () const
 The active tab.
std::vector< WorkspaceTabId > order () const
 The open tabs' ids, in order, read without tracking: the order tabs() lists them in.
ScreenHandle * handleOf (WorkspaceTabId tab) const noexcept
 A tab's screen handle: what a client remounts for development reload and inspects.

Detailed Description

The workspace's tabs with no widgets: which screens are open, in which order, which is active, and how they open, close and are recorded (spec 6 §7, §15).

Opening a screen whose identity an open tab already has focuses that tab, a singleton screen has one tab, and a reuseEmpty screen opened with an identity replaces its tab with no identity and no unsaved changes. Closing runs each screen's close protocol (spec 6 §3), one tab at a time, and a walk over several tabs stops at the first veto. next and previous walk the most recently used order. The page each tab shows is the application's: mountPage makes it and mounts the screen there, unmountPage is told when it goes. Neither copyable nor movable; owned by the owner thread of its runtime.

Definition at line 126 of file workspace_model.hpp.

Constructor & Destructor Documentation

◆ WorkspaceModel()

morph::ui::WorkspaceModel::WorkspaceModel ( reactive::Runtime & runtime,
DocumentScreenHost & host,
WorkspaceModelOptions options )
inline

An empty workspace.

Parameters
runtimeThe runtime the screens' reactive nodes belong to. Borrowed.
hostAnswers identities and routes. Borrowed; it outlives the model.
optionsThe screens' catalog facts, the record, and the page callbacks.
Exceptions
std::invalid_argumentwhen mountPage is empty.

Definition at line 133 of file workspace_model.hpp.

◆ ~WorkspaceModel()

morph::ui::WorkspaceModel::~WorkspaceModel ( )
inline

Unmounts every screen without asking, newest first.

Definition at line 148 of file workspace_model.hpp.

Member Function Documentation

◆ open()

std::expected< WorkspaceTabId, MountError > morph::ui::WorkspaceModel::open ( std::string_view screenId,
ParamMap const & params )
inline

Opens a screen, or focuses the tab that already shows it; the tab opened or focused is the active one.

Parameters
screenIdThe screen id.
paramsIts params.
Returns
The tab, or why the screen could not be mounted; a refused mount, or a mountPage that throws, opens nothing.

Definition at line 164 of file workspace_model.hpp.

◆ start()

std::size_t morph::ui::WorkspaceModel::start ( WorkspaceStart const & how)
inline

Opens the start screens: with resume, every recorded route whose screen is known and available, in order, and the fallback when none of them opened; otherwise the start screen. The first tab opened is the active one.

Parameters
howThe start screen, the fallback and the record.
Returns
The number of tabs opened.

Definition at line 201 of file workspace_model.hpp.

◆ activate()

void morph::ui::WorkspaceModel::activate ( WorkspaceTabId tab)
inline

Shows a tab and makes it the most recently used.

Parameters
tabThe tab.
Exceptions
std::out_of_rangefor a tab the model does not hold.

Definition at line 234 of file workspace_model.hpp.

◆ next()

void morph::ui::WorkspaceModel::next ( )
inline

Shows the next tab in most-recently-used order (Ctrl+Tab). Repeated calls walk the order as it was at the first of them; any other activation starts a new walk.

Definition at line 238 of file workspace_model.hpp.

◆ previous()

void morph::ui::WorkspaceModel::previous ( )
inline

Shows the previous tab in most-recently-used order (Ctrl+Shift+Tab).

Definition at line 241 of file workspace_model.hpp.

◆ close()

void morph::ui::WorkspaceModel::close ( WorkspaceTabId tab,
std::function< void(bool)> done )
inline

Closes a tab through its screen's close protocol.

Parameters
tabThe tab.
doneCalled once with whether it closed; may be empty.
Exceptions
std::out_of_rangefor a tab the model does not hold.

Definition at line 247 of file workspace_model.hpp.

◆ closeOthers()

void morph::ui::WorkspaceModel::closeOthers ( WorkspaceTabId tab,
std::function< void(bool)> done )
inline

Closes every tab but one, one at a time, stopping at the first veto.

Parameters
tabThe tab kept.
doneCalled once with whether every other tab closed; may be empty.
Exceptions
std::out_of_rangefor a tab the model does not hold.

Definition at line 253 of file workspace_model.hpp.

◆ closeAll()

void morph::ui::WorkspaceModel::closeAll ( std::function< void(bool)> done)
inline

Closes every tab, one at a time, stopping at the first veto.

Parameters
doneCalled once with whether every tab closed; may be empty.

Definition at line 267 of file workspace_model.hpp.

◆ closeSaved()

void morph::ui::WorkspaceModel::closeSaved ( std::function< void(bool)> done)
inline

Closes every tab without unsaved changes, one at a time, stopping at the first veto.

Parameters
doneCalled once with whether each of them closed; may be empty.

Definition at line 271 of file workspace_model.hpp.

◆ forceCloseAll()

void morph::ui::WorkspaceModel::forceCloseAll ( )
inline

Closes every tab without asking, newest first: what signing out does, since no close guard may keep a screen of the principal who is leaving.

Definition at line 284 of file workspace_model.hpp.

◆ flushRecord()

void morph::ui::WorkspaceModel::flushRecord ( )
inline

Writes the record now, cancelling a pending debounced write: what sign-out does before the session is cleared.

Definition at line 292 of file workspace_model.hpp.

◆ record()

std::vector< std::string > morph::ui::WorkspaceModel::record ( ) const
inlinenodiscard

The record as it would be written now: the routes of the open tabs, in order.

Returns
The routes.

Definition at line 301 of file workspace_model.hpp.

◆ tabs()

reactive::Computed< std::vector< WorkspaceTabState > > const & morph::ui::WorkspaceModel::tabs ( ) const
inlinenodiscard

The open tabs, in order, each with its screen, identity, title and unsaved state. A tab's values follow its handle.

Returns
The tabs, equality-gated: an Effect over it runs once per change.

Definition at line 315 of file workspace_model.hpp.

◆ active()

reactive::Computed< std::optional< WorkspaceTabId > > const & morph::ui::WorkspaceModel::active ( ) const
inlinenodiscard

The active tab.

Returns
It, or std::nullopt while no tab is open.

Definition at line 319 of file workspace_model.hpp.

◆ order()

std::vector< WorkspaceTabId > morph::ui::WorkspaceModel::order ( ) const
inlinenodiscard

The open tabs' ids, in order, read without tracking: the order tabs() lists them in.

Returns
The ids.

Definition at line 323 of file workspace_model.hpp.

◆ handleOf()

ScreenHandle * morph::ui::WorkspaceModel::handleOf ( WorkspaceTabId tab) const
inlinenodiscardnoexcept

A tab's screen handle: what a client remounts for development reload and inspects.

Parameters
tabThe tab.
Returns
Its handle, valid while the tab is open; null for a tab the model does not hold.

Definition at line 335 of file workspace_model.hpp.


The documentation for this class was generated from the following file: