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) { fn activate(app: &gtk::Application) {
ui::UI.with(|ui_cell| { ui::UI.with(|ui_cell| {
let mut ui = ui_cell.borrow_mut(); 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 path = nvim_bin_path(std::env::args());
let open_arg = open_arg(); nvim::initialize(&mut *ui, path.as_ref())
nvim::initialize(&mut *ui, path.as_ref(), open_arg.as_ref()) .expect("Can't start nvim instance");
.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, pub fn initialize(ui: &mut Ui,
nvim_bin_path: Option<&String>, nvim_bin_path: Option<&String>)
open_arg: Option<&String>)
-> Result<()> { -> Result<()> {
let session = if let Some(path) = nvim_bin_path { let session = if let Some(path) = nvim_bin_path {
Session::new_child_path(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.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))?; 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(()) 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>) { fn nvim_cb(method: &str, params: Vec<Value>) {
match method { match method {
"redraw" => { "redraw" => {

View File

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