diff options
Diffstat (limited to 'src/gui/state.rs')
| -rw-r--r-- | src/gui/state.rs | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/gui/state.rs b/src/gui/state.rs index 7b9542a..be41f86 100644 --- a/src/gui/state.rs +++ b/src/gui/state.rs @@ -1,27 +1,31 @@ use gtk::prelude::*; use std::collections::HashMap; -use std::rc::Rc; use std::sync::Mutex; +use crate::index::Index; +use std::rc::Rc; +use std::sync::Arc; pub trait View { fn name(&self) -> &str; fn set_vm(&mut self, vm : Rc<ViewManager>); - fn make_current(&self) -> gtk::Box; + fn make_current(&self) -> Option<gtk::Box>; } #[derive(Default)] pub struct ViewManager { views : HashMap<String, Rc<Mutex<dyn View>>>, - pub current : String, - pub window : Option<gtk::ApplicationWindow> + pub current : Mutex<String>, + pub window : Option<gtk::ApplicationWindow>, + index : Arc<Mutex<Index>> } impl ViewManager { pub fn new(window : gtk::ApplicationWindow) -> Self { Self { views : HashMap::new(), - current : String::new(), + current : Mutex::new(String::new()), window : Some(window), + index : Arc::new(Mutex::new(Index::default())) } } @@ -41,11 +45,31 @@ impl ViewManager { for child in window.children() { window.remove(&child) } - window.add(&b); - window.show_all() + { + *(self.current.lock().unwrap()) = name.to_string(); + } + if let Some(b) = b { + window.add(&b); + window.show_all(); + } else { + window.hide(); + } + } + + pub fn get_current_view(&self) -> String { + self.current.lock().unwrap().to_string() } pub fn get_window(&self) -> >k::ApplicationWindow { self.window.as_ref().unwrap() } + + pub fn get_index(&self) -> Arc<Mutex<Index>> { + Arc::clone(&self.index) + } + + pub fn set_index(&self, index : Index) { + let mut idx = self.index.lock().unwrap(); + *idx = index; + } } |