From 2a566d1d517713dd8d16ed934c28037ebdcfcbf4 Mon Sep 17 00:00:00 2001 From: daa84 Date: Wed, 4 May 2016 11:52:57 +0300 Subject: [PATCH] Quit nvim --- src/ui.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 579a858..41f0a0a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -12,7 +12,7 @@ use cairo::enums::{FontWeight, FontSlant}; use gtk; use gtk::prelude::*; use gtk::{Window, WindowType, DrawingArea, Grid, ToolButton, ButtonBox, Orientation, Image}; -use gdk::{EventKey, EventConfigure}; +use gdk::{Event, EventKey, EventConfigure}; use glib; use glib_sys; use neovim_lib::{Neovim, NeovimApi}; @@ -114,14 +114,22 @@ impl Ui { self.window.add(&grid); self.window.show_all(); self.window.connect_key_press_event(gtk_key_press); - self.window.connect_delete_event(|_, _| { - gtk::main_quit(); - Inhibit(false) - }); + self.window.connect_delete_event(gtk_delete); self.drawing_area.connect_configure_event(gtk_configure_event); } } +fn gtk_delete(_: &Window, _: &Event) -> Inhibit { + UI.with(|ui_cell| { + let mut ui = ui_cell.borrow_mut(); + let nvim = ui.nvim(); + nvim.ui_detach().expect("Error in ui_detach"); + nvim.quit_no_save().expect("Can't stop nvim instance"); + }); + gtk::main_quit(); + Inhibit(false) +} + fn gtk_key_press(_: &Window, ev: &EventKey) -> Inhibit { if let Some(input) = convert_key(ev) { UI.with(|ui_cell| {