gdritter repos palladio / master src / model / mod.rs
master

Tree @master (Download .tar.gz)

mod.rs @masterraw · history · blame

pub mod document;
pub use self::document::*;
use failure::Error;
use crate::cfg;

pub struct State {
    pub document: Document,
    pub save_state: SaveState,
}

impl State {
    pub fn new(conf: cfg::Cfg) -> Result<State, Error> {
        Ok(match conf.file_path {
            None => State {
                document: Document::default(),
                save_state: SaveState::Unsaved,
            },
            Some(path) => {
                let mut f = ::std::fs::File::open(path)?;
                State {
                    document: Document::open_from_file(&mut f)?,
                    save_state: SaveState::Saved,
                }
            },
        })
    }
}

#[derive(Debug)]
pub enum SaveState {
    Unsaved,
    Modified,
    Saved,
}