Mountain/IPC/WindServiceHandler/WorkingCopy.rs
1#![allow(non_snake_case)]
2
3//! WorkingCopy domain handlers for Wind IPC.
4
5use std::sync::Arc;
6
7use serde_json::{Value, json};
8
9use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
10
11/// Check whether a URI has unsaved changes.
12pub async fn handle_working_copy_is_dirty(Runtime:Arc<ApplicationRunTime>, Args:Vec<Value>) -> Result<Value, String> {
13 let Uri = Args
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
21/// Mark a URI as dirty (unsaved) or clean.
22pub async fn handle_working_copy_set_dirty(Runtime:Arc<ApplicationRunTime>, Args:Vec<Value>) -> Result<Value, String> {
23 let Uri = Args
24 .first()
25 .and_then(|V| V.as_str())
26 .ok_or("workingCopy:setDirty requires uri".to_string())?;
27 let Dirty = Args.get(1).and_then(|V| V.as_bool()).unwrap_or(true);
28 Runtime.Environment.ApplicationState.Feature.WorkingCopy.SetDirty(Uri, Dirty);
29 Ok(Value::Null)
30}
31
32/// Return all URIs that currently have unsaved changes.
33pub async fn handle_working_copy_get_all_dirty(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
34 let Dirty = Runtime.Environment.ApplicationState.Feature.WorkingCopy.GetAllDirty();
35 Ok(json!(Dirty))
36}
37
38/// Return the count of resources with unsaved changes.
39pub async fn handle_working_copy_get_dirty_count(Runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
40 let Count = Runtime.Environment.ApplicationState.Feature.WorkingCopy.GetDirtyCount();
41 Ok(json!(Count))
42}