pub struct Session<D: Document> { /* private fields */ }Expand description
The state commands run on: the document Store, the file it came from, view state and the
effects commands ask of the window. Commands are fn(&mut Session<D>, &Value).
Implementations§
Source§impl<D: Document> Session<D>
impl<D: Document> Session<D>
Sourcepub fn is_windowed(&self) -> bool
pub fn is_windowed(&self) -> bool
Whether a window can show dialogs (false in CLI / MCP sessions).
Sourcepub fn snapshot(&self) -> Arc<D> ⓘ
pub fn snapshot(&self) -> Arc<D> ⓘ
The current document as an Arc (for a job or another thread).
Sourcepub fn store(&self) -> &Store<D>
pub fn store(&self) -> &Store<D>
The store (history, revision, dirty state). Changing it directly from inside a command
drops the command’s own edits; use Session::edit there.
pub fn store_mut(&mut self) -> &mut Store<D>
pub fn revision(&self) -> Revision
pub fn is_dirty(&self) -> bool
pub fn format(&self) -> &Format<D>
Sourcepub fn edit<R>(&mut self, label: &str, f: impl FnOnce(&mut D) -> R) -> R
pub fn edit<R>(&mut self, label: &str, f: impl FnOnce(&mut D) -> R) -> R
Change the document. Inside a command the change joins the command’s single undo step;
outside (a view, a job’s apply) it is a step of its own called label.
Sourcepub fn edit_merged<R>(
&mut self,
label: &str,
merge_key: &str,
f: impl FnOnce(&mut D) -> R,
) -> R
pub fn edit_merged<R>( &mut self, label: &str, merge_key: &str, f: impl FnOnce(&mut D) -> R, ) -> R
Session::edit that folds into the previous step with the same label and merge key
(one undo step for a whole drag).
Sourcepub fn try_edit<R, E>(
&mut self,
label: &str,
f: impl FnOnce(&mut D) -> Result<R, E>,
) -> Result<R, E>
pub fn try_edit<R, E>( &mut self, label: &str, f: impl FnOnce(&mut D) -> Result<R, E>, ) -> Result<R, E>
A change that may fail: on error nothing changes.
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
Sourcepub fn display_name(&self) -> String
pub fn display_name(&self) -> String
The document’s display name: the file name, or “Untitled”.
Sourcepub fn migrated_from(&self) -> Option<u64>
pub fn migrated_from(&self) -> Option<u64>
The schema version the open file had before it was upgraded on load, if it was.
Sourcepub fn file_generation(&self) -> u64
pub fn file_generation(&self) -> u64
Changes when the file (path) changes; with the revision it keys caches of file state.
Sourcepub fn new_document(&mut self)
pub fn new_document(&mut self)
Start a new, empty document.
Sourcepub fn open(&mut self, path: &Path) -> Result<(), FormatError>
pub fn open(&mut self, path: &Path) -> Result<(), FormatError>
Open path (migrating older files). On error the current document stays.
Sourcepub fn replace(
&mut self,
doc: D,
path: Option<PathBuf>,
migrated_from: Option<u64>,
)
pub fn replace( &mut self, doc: D, path: Option<PathBuf>, migrated_from: Option<u64>, )
Replace the document with doc as if opened from path: clears the history, clean.
Sourcepub fn replace_as_edit(&mut self, label: &str, doc: D)
pub fn replace_as_edit(&mut self, label: &str, doc: D)
Replace the document with doc as an undoable, unsaved change (recovered work, an
import).
Sourcepub fn save(&mut self) -> Result<PathBuf, FormatError>
pub fn save(&mut self) -> Result<PathBuf, FormatError>
Save to the current file. Errors when the document has never been saved.
Sourcepub fn save_as(&mut self, path: &Path) -> Result<(), FormatError>
pub fn save_as(&mut self, path: &Path) -> Result<(), FormatError>
Save to path and make it the document’s file.
Sourcepub fn view_state(&self) -> &Map<String, Value>
pub fn view_state(&self) -> &Map<String, Value>
App-defined view state (ui.set merges into it; it is not part of the document).
pub fn view<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn view_or<T: DeserializeOwned>(&self, key: &str, default: T) -> T
pub fn set_view<T: Serialize + ?Sized>(&mut self, key: &str, value: &T)
pub fn set_view_value(&mut self, key: &str, value: Value)
Sourcepub fn view_generation(&self) -> u64
pub fn view_generation(&self) -> u64
Changes whenever the view state changes.
Sourcepub fn toast(&mut self, level: ToastLevel, text: impl Into<String>)
pub fn toast(&mut self, level: ToastLevel, text: impl Into<String>)
Show a message (headless: logged).
Trait Implementations§
Source§impl<D: Document> Host for Session<D>
impl<D: Document> Host for Session<D>
Source§type Error = CommandError
type Error = CommandError
CommandError itself, or the app’s own error with
From<AppError> for CommandError (leave the id empty: the chokepoint fills it in).Source§fn before(
&mut self,
_spec: &CommandSpec<Self>,
_params: &mut Value,
depth: usize,
) -> Result<(), CommandError>
fn before( &mut self, _spec: &CommandSpec<Self>, _params: &mut Value, depth: usize, ) -> Result<(), CommandError>
Err refuses the call: Host::rejected sees it converted, and
Registry::execute_host hands it back unchanged as ExecError::Host.Source§fn after(
&mut self,
spec: &CommandSpec<Self>,
_params: &Value,
result: &Result<Value, CommandError>,
depth: usize,
)
fn after( &mut self, spec: &CommandSpec<Self>, _params: &Value, result: &Result<Value, CommandError>, depth: usize, )
Source§fn rejected(&mut self, id: &str, error: &CommandError, depth: usize)
fn rejected(&mut self, id: &str, error: &CommandError, depth: usize)
Host::before.Source§fn validate(
&mut self,
_spec: &CommandSpec<Self>,
_params: &Value,
_depth: usize,
) -> Result<(), CommandError>
fn validate( &mut self, _spec: &CommandSpec<Self>, _params: &Value, _depth: usize, ) -> Result<(), CommandError>
Validation policy and before
Host::enabled_for (an Err is refused and goes to Host::rejected). With
Validation::Off this is where a host validates when it wants to, e.g. only at depth 0
or only for agent calls. Default: nothing.Source§fn enabled_for(
&mut self,
spec: &CommandSpec<Self>,
_params: &Value,
) -> Result<(), String>
fn enabled_for( &mut self, spec: &CommandSpec<Self>, _params: &Value, ) -> Result<(), String>
Auto Trait Implementations§
impl<D> !RefUnwindSafe for Session<D>
impl<D> !UnwindSafe for Session<D>
impl<D> Freeze for Session<D>
impl<D> Send for Session<D>
impl<D> Sync for Session<D>
impl<D> Unpin for Session<D>
impl<D> UnsafeUnpin for Session<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more