Mountain/IPC/WindServiceHandlers/UI/WorkingCopy.rs
1#![allow(non_snake_case, unused_variables)]
2//! Working-copy (dirty-state) handlers. Tracks whether an open URI has
3//! unsaved changes; Sky queries this to paint the tab's dot-indicator,
4//! gate exit dialogs, and drive "Save All" affordances.
5
6use std::sync::Arc;
7
8use serde_json::{Value, json};
9
10use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
11
12pub async fn WorkingCopyIsDirty(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
13 let Uri = Arguments
14 .first()
15 .and_then(|V| V.as_str())
16 .ok_or("workingCopy:isDirty requires uri".to_string())?;
17 let IsDirty = RunTime.Environment.ApplicationState.Feature.WorkingCopy.IsDirty(Uri);
18 Ok(json!(IsDirty))
19}
20
21pub async fn WorkingCopySetDirty(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
22 let Uri = Arguments
23 .first()
24 .and_then(|V| V.as_str())
25 .ok_or("workingCopy:setDirty requires uri".to_string())?;
26 let Dirty = Arguments.get(1).and_then(|V| V.as_bool()).unwrap_or(true);
27 RunTime.Environment.ApplicationState.Feature.WorkingCopy.SetDirty(Uri, Dirty);
28 Ok(Value::Null)
29}
30
31pub async fn WorkingCopyGetAllDirty(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
32 let Dirty = RunTime.Environment.ApplicationState.Feature.WorkingCopy.GetAllDirty();
33 Ok(json!(Dirty))
34}
35
36pub async fn WorkingCopyGetDirtyCount(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
37 let Count = RunTime.Environment.ApplicationState.Feature.WorkingCopy.GetDirtyCount();
38 Ok(json!(Count))
39}