From 86e18562b5f20819c5f05524d61f88e888d0208d Mon Sep 17 00:00:00 2001 From: daa Date: Sun, 15 Oct 2017 22:50:59 +0300 Subject: [PATCH] Seleton for plug manager --- src/plug_manager/manager.rs | 17 +++++++++++ src/plug_manager/mod.rs | 2 ++ src/shell.rs | 58 ++++++++++++++++++++++++++++--------- src/ui.rs | 9 ++++++ 4 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 src/plug_manager/manager.rs diff --git a/src/plug_manager/manager.rs b/src/plug_manager/manager.rs new file mode 100644 index 0000000..2f275ff --- /dev/null +++ b/src/plug_manager/manager.rs @@ -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>) { + } +} diff --git a/src/plug_manager/mod.rs b/src/plug_manager/mod.rs index 8f153c6..d20f8e8 100644 --- a/src/plug_manager/mod.rs +++ b/src/plug_manager/mod.rs @@ -1,3 +1,5 @@ mod ui; +mod manager; pub use self::ui::Ui; +pub use self::manager::Manager; diff --git a/src/shell.rs b/src/shell.rs index 8d2cce9..10facfb 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -79,6 +79,7 @@ pub struct State { options: ShellOptions, detach_cb: Option>>, + nvim_started_cb: Option>>, } impl State { @@ -112,6 +113,7 @@ impl State { options, detach_cb: None, + nvim_started_cb: None, } } @@ -156,6 +158,17 @@ impl State { } } + pub fn set_nvim_started_cb(&mut self, cb: Option) + 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 { self.font_ctx.font_description() } @@ -581,6 +594,14 @@ impl Shell { let mut state = self.state.borrow_mut(); state.set_detach_cb(cb); } + + pub fn set_nvim_started_cb(&self, cb: Option) + where + F: FnMut() + Send + 'static, + { + let mut state = self.state.borrow_mut(); + state.set_nvim_started_cb(cb); + } } impl Deref for Shell { @@ -766,19 +787,30 @@ fn init_nvim_async( }); // attach ui - if let Err(err) = nvim::post_start_init( - &mut nvim, - options.open_path.as_ref(), - cols as u64, - rows as u64, - ) - { - show_nvim_init_error(&err, state_arc.clone()); - } else { - let mut state = state_arc.borrow_mut(); - state.nvim.borrow_mut().set_initialized(nvim); - state.cursor.as_mut().unwrap().start(); - } + 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( + &mut nvim, + options.open_path.as_ref(), + cols as u64, + rows as u64, + ) + { + show_nvim_init_error(&err, state_ref.clone()); + } else { + let mut state = state_ref.borrow_mut(); + state.nvim.borrow_mut().set_initialized(nvim); + state.cursor.as_mut().unwrap().start(); + } + + Continue(false) + }); + + + idle_cb_call!(state_arc.nvim_started_cb()); } fn draw_initializing(state: &State, ctx: &cairo::Context) { diff --git a/src/ui.rs b/src/ui.rs index e20a852..f71fdf8 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -22,6 +22,7 @@ pub struct Ui { settings: Rc>, shell: Rc>, projects: Rc>, + plug_manager: Arc>, } pub struct Components { @@ -57,6 +58,7 @@ impl Ui { settings.borrow_mut().set_shell(Rc::downgrade(&shell)); let projects = Projects::new(&comps.borrow().open_btn, shell.clone()); + let plug_manager = Arc::new(UiMutex::new(plug_manager::Manager::new())); Ui { initialized: false, @@ -64,6 +66,7 @@ impl Ui { shell, settings, projects, + plug_manager, } } @@ -159,6 +162,12 @@ impl Ui { 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: >k::Application) {