Check loaded state

This commit is contained in:
daa84 2017-10-16 18:34:26 +03:00
parent 86e18562b5
commit a3eba12b24
3 changed files with 46 additions and 9 deletions

View File

@ -1,17 +1,44 @@
use std::rc::Rc;
use std::cell::RefCell;
use std::cell::{RefCell, RefMut};
use neovim_lib::{Neovim, NeovimApi, Value};
use nvim::NeovimClient;
pub struct Manager {
nvim: Option<Rc<RefCell<NeovimClient>>>,
}
impl Manager {
pub fn new() -> Self {
Manager { }
Manager {
nvim: None,
}
}
pub fn initialize(&mut self, nvim: Rc<RefCell<NeovimClient>>) {
self.nvim = Some(nvim);
}
fn nvim(&self) -> Option<RefMut<Neovim>> {
let nvim_client = self.nvim.as_ref().unwrap();
if nvim_client.borrow().is_initialized() {
Some(RefMut::map(nvim_client.borrow_mut(), |n| n.nvim_mut()))
} else {
None
}
}
pub fn get_state(&self) -> State {
if let Some(mut nvim) = self.nvim() {
nvim.command("exists('g:loaded_plug')");
}
State::Unknown
}
}
pub enum State {
Unknown,
AlreadyLoaded,
}

View File

@ -1,11 +1,17 @@
use gtk;
use gtk::prelude::*;
pub struct Ui {}
use super::manager;
impl Ui {
pub fn new() -> Self {
Ui {}
pub struct Ui <'a> {
manager: &'a manager::Manager,
}
impl <'a> Ui <'a> {
pub fn new(manager: &'a manager::Manager) -> Ui<'a> {
Ui {
manager,
}
}
pub fn show<T: IsA<gtk::Window>>(&self, parent: &T) {

View File

@ -130,8 +130,10 @@ impl Ui {
let plug_btn = ToolButton::new(Some(&plug_image), "Plug");
let comps_ref = self.comps.clone();
let plug_manager_ref = self.plug_manager.clone();
plug_btn.connect_clicked(move |_| {
plug_manager::Ui::new().show(comps_ref.borrow().window.as_ref().unwrap())
plug_manager::Ui::new(&mut *plug_manager_ref.borrow_mut())
.show(comps_ref.borrow().window.as_ref().unwrap())
});
header_bar.pack_start(&plug_btn);
@ -166,7 +168,9 @@ impl Ui {
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());
plug_manager_ref.borrow_mut().initialize(
state_ref.borrow().nvim_clone(),
);
}));
}