Seleton for plug manager

This commit is contained in:
daa 2017-10-15 22:50:59 +03:00
parent 35d9592b9b
commit 86e18562b5
4 changed files with 73 additions and 13 deletions

View File

@ -0,0 +1,17 @@
use std::rc::Rc;
use std::cell::RefCell;
use nvim::NeovimClient;
pub struct Manager {
}
impl Manager {
pub fn new() -> Self {
Manager { }
}
pub fn initialize(&mut self, nvim: Rc<RefCell<NeovimClient>>) {
}
}

View File

@ -1,3 +1,5 @@
mod ui; mod ui;
mod manager;
pub use self::ui::Ui; pub use self::ui::Ui;
pub use self::manager::Manager;

View File

@ -79,6 +79,7 @@ pub struct State {
options: ShellOptions, options: ShellOptions,
detach_cb: Option<Box<RefCell<FnMut() + Send + 'static>>>, detach_cb: Option<Box<RefCell<FnMut() + Send + 'static>>>,
nvim_started_cb: Option<Box<RefCell<FnMut() + Send + 'static>>>,
} }
impl State { impl State {
@ -112,6 +113,7 @@ impl State {
options, options,
detach_cb: None, detach_cb: None,
nvim_started_cb: None,
} }
} }
@ -156,6 +158,17 @@ impl State {
} }
} }
pub fn set_nvim_started_cb<F>(&mut self, cb: Option<F>)
where
F: FnMut() + Send + 'static,
{
if cb.is_some() {
self.nvim_started_cb = Some(Box::new(RefCell::new(cb.unwrap())));
} else {
self.nvim_started_cb = None;
}
}
pub fn get_font_desc(&self) -> &FontDescription { pub fn get_font_desc(&self) -> &FontDescription {
self.font_ctx.font_description() self.font_ctx.font_description()
} }
@ -581,6 +594,14 @@ impl Shell {
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
state.set_detach_cb(cb); state.set_detach_cb(cb);
} }
pub fn set_nvim_started_cb<F>(&self, cb: Option<F>)
where
F: FnMut() + Send + 'static,
{
let mut state = self.state.borrow_mut();
state.set_nvim_started_cb(cb);
}
} }
impl Deref for Shell { impl Deref for Shell {
@ -766,6 +787,11 @@ fn init_nvim_async(
}); });
// attach ui // attach ui
let state_ref = state_arc.clone();
let mut nvim = Some(nvim);
glib::idle_add(move || {
let mut nvim = nvim.take().unwrap();
if let Err(err) = nvim::post_start_init( if let Err(err) = nvim::post_start_init(
&mut nvim, &mut nvim,
options.open_path.as_ref(), options.open_path.as_ref(),
@ -773,12 +799,18 @@ fn init_nvim_async(
rows as u64, rows as u64,
) )
{ {
show_nvim_init_error(&err, state_arc.clone()); show_nvim_init_error(&err, state_ref.clone());
} else { } else {
let mut state = state_arc.borrow_mut(); let mut state = state_ref.borrow_mut();
state.nvim.borrow_mut().set_initialized(nvim); state.nvim.borrow_mut().set_initialized(nvim);
state.cursor.as_mut().unwrap().start(); state.cursor.as_mut().unwrap().start();
} }
Continue(false)
});
idle_cb_call!(state_arc.nvim_started_cb());
} }
fn draw_initializing(state: &State, ctx: &cairo::Context) { fn draw_initializing(state: &State, ctx: &cairo::Context) {

View File

@ -22,6 +22,7 @@ pub struct Ui {
settings: Rc<RefCell<Settings>>, settings: Rc<RefCell<Settings>>,
shell: Rc<RefCell<Shell>>, shell: Rc<RefCell<Shell>>,
projects: Rc<RefCell<Projects>>, projects: Rc<RefCell<Projects>>,
plug_manager: Arc<UiMutex<plug_manager::Manager>>,
} }
pub struct Components { pub struct Components {
@ -57,6 +58,7 @@ impl Ui {
settings.borrow_mut().set_shell(Rc::downgrade(&shell)); settings.borrow_mut().set_shell(Rc::downgrade(&shell));
let projects = Projects::new(&comps.borrow().open_btn, shell.clone()); let projects = Projects::new(&comps.borrow().open_btn, shell.clone());
let plug_manager = Arc::new(UiMutex::new(plug_manager::Manager::new()));
Ui { Ui {
initialized: false, initialized: false,
@ -64,6 +66,7 @@ impl Ui {
shell, shell,
settings, settings,
projects, projects,
plug_manager,
} }
} }
@ -159,6 +162,12 @@ impl Ui {
Continue(false) Continue(false)
}); });
})); }));
let state_ref = self.shell.borrow().state.clone();
let plug_manager_ref = self.plug_manager.clone();
shell.set_nvim_started_cb(Some(move || {
plug_manager_ref.borrow_mut().initialize(state_ref.borrow().nvim_clone());
}));
} }
fn create_main_menu(&self, app: &gtk::Application) { fn create_main_menu(&self, app: &gtk::Application) {