Fix two time run

This commit is contained in:
daa 2017-03-14 23:12:31 +03:00
parent 10afc750e8
commit e719535d2a
3 changed files with 23 additions and 12 deletions

View File

@ -40,14 +40,17 @@ fn main() {
fn activate(app: &gtk::Application) {
ui::UI.with(|ui_cell| {
let mut ui = ui_cell.borrow_mut();
ui.init(app);
if !ui.initialized {
ui.init(app);
let path = nvim_bin_path(std::env::args());
let open_arg = open_arg();
nvim::initialize(&mut *ui, path.as_ref(), open_arg.as_ref())
.expect("Can't start nvim instance");
let path = nvim_bin_path(std::env::args());
nvim::initialize(&mut *ui, path.as_ref())
.expect("Can't start nvim instance");
guard_dispatch_thread(&mut *ui);
guard_dispatch_thread(&mut *ui);
}
nvim::open_file(ui.nvim(), open_arg().as_ref());
});
}

View File

@ -65,8 +65,7 @@ macro_rules! try_uint {
}
pub fn initialize(ui: &mut Ui,
nvim_bin_path: Option<&String>,
open_arg: Option<&String>)
nvim_bin_path: Option<&String>)
-> Result<()> {
let session = if let Some(path) = nvim_bin_path {
Session::new_child_path(path)?
@ -84,13 +83,15 @@ pub fn initialize(ui: &mut Ui,
nvim.ui_attach(80, 24, UiAttachOptions::new()).map_err(|e| Error::new(ErrorKind::Other, e))?;
nvim.command("runtime! ginit.vim").map_err(|e| Error::new(ErrorKind::Other, e))?;
if let Some(ref file) = open_arg {
nvim.command(&format!("e {}", file)).report_err(nvim);
}
Ok(())
}
pub fn open_file(nvim: &mut NeovimApi, file: Option<&String>) {
if let Some(file_name) = file {
nvim.command(&format!("e {}", file_name)).report_err(nvim);
}
}
fn nvim_cb(method: &str, params: Vec<Value>) {
match method {
"redraw" => {

View File

@ -46,6 +46,7 @@ enum NvimMode {
pub struct Ui {
pub model: UiModel,
pub initialized: bool,
nvim: Option<Neovim>,
drawing_area: DrawingArea,
window: Option<ApplicationWindow>,
@ -82,6 +83,7 @@ impl Ui {
mouse_enabled: false,
mouse_pressed: false,
font_desc: FontDescription::from_string(FONT_NAME),
initialized: false,
}
}
@ -98,6 +100,11 @@ impl Ui {
}
pub fn init(&mut self, app: &gtk::Application) {
if self.initialized {
return
}
self.initialized = true;
SET.with(|settings| {
let mut settings = settings.borrow_mut();
settings.init(self);