use rs_teststand_sys::{Dispatch, Value};
use crate::Error;
use crate::dispids::property_object_file;
use crate::types::TypeUsageList;
#[derive(Debug)]
pub struct PropertyObjectFile {
dispatch: Box<dyn Dispatch>,
}
impl PropertyObjectFile {
pub(crate) fn new(dispatch: Box<dyn Dispatch>) -> Self {
Self { dispatch }
}
pub fn save_file_if_modified(&self, prompt: bool) -> Result<bool, Error> {
Ok(self
.dispatch
.call(
property_object_file::SAVE_FILE_IF_MODIFIED,
&[Value::Bool(prompt)],
)?
.as_bool()?)
}
pub fn type_usage_list(&self) -> Result<TypeUsageList, Error> {
Ok(TypeUsageList::new(
self.dispatch
.get(property_object_file::TYPE_USAGE_LIST)?
.into_object()?,
))
}
pub fn inc_change_count(&self) -> Result<(), Error> {
self.dispatch
.call(property_object_file::INC_CHANGE_COUNT, &[])?;
Ok(())
}
pub fn data(&self) -> Result<crate::property::PropertyObject, Error> {
Ok(crate::property::PropertyObject::new(
self.dispatch
.get(property_object_file::DATA)?
.into_object()?,
))
}
pub fn path(&self) -> Result<String, Error> {
Ok(self
.dispatch
.get(property_object_file::PATH)?
.into_string()?)
}
pub fn set_path(&self, path: &str) -> Result<(), Error> {
self.dispatch
.put(property_object_file::PATH, Value::Str(path.to_owned()))?;
Ok(())
}
}