Finish migration to shell.rs

This commit is contained in:
daa84 2017-03-16 13:18:13 +03:00
parent 61a429d2f1
commit b1507a0334
3 changed files with 23 additions and 21 deletions

View File

@ -21,6 +21,8 @@ use std::thread;
use std::env;
use gio::ApplicationExt;
use shell::Shell;
const BIN_PATH_ARG: &'static str = "--nvim-bin-path";
fn main() {
@ -45,13 +47,13 @@ fn activate(app: &gtk::Application) {
ui.init(app);
let path = nvim_bin_path(std::env::args());
nvim::initialize(&mut *ui, path.as_ref())
nvim::initialize(&mut ui.shell, path.as_ref())
.expect("Can't start nvim instance");
guard_dispatch_thread(&mut *ui);
guard_dispatch_thread(&mut ui.shell);
}
nvim::open_file(ui.nvim(), open_arg().as_ref());
nvim::open_file(ui.shell.nvim(), open_arg().as_ref());
});
}
@ -81,12 +83,12 @@ fn open_arg_impl<I>(args: I) -> Option<String>
.unwrap_or(None)
}
fn guard_dispatch_thread(ui: &mut ui::Ui) {
let guard = ui.nvim().session.take_dispatch_guard();
fn guard_dispatch_thread(shell: &mut Shell) {
let guard = shell.nvim().session.take_dispatch_guard();
thread::spawn(move || {
guard.join().expect("Can't join dispatch thread");
glib::idle_add(move || {
ui::UI.with(|ui_cell| { ui_cell.borrow().destroy(); });
ui::UI.with(|ui_cell| { ui_cell.borrow().close_window(); });
glib::Continue(false)
});
});

View File

@ -4,18 +4,17 @@ use cairo;
use pangocairo as pc;
use pango;
use pango::FontDescription;
use gdk::{ModifierType, Event, EventKey, EventConfigure, EventButton, EventMotion, EventType};
use gdk::{ModifierType, EventKey, EventConfigure, EventButton, EventMotion, EventType};
use gdk_sys;
use glib;
use gtk::prelude::*;
use gtk;
use gtk::{ApplicationWindow, HeaderBar, DrawingArea, ToolButton, Image};
use gtk::DrawingArea;
use neovim_lib::{Neovim, NeovimApi, Value, Integer};
use settings;
use ui_model::{UiModel, Cell, Attrs, Color, COLOR_BLACK, COLOR_WHITE, COLOR_RED};
use nvim::{RedrawEvents, GuiApi, ErrorReport};
use nvim::{RedrawEvents, GuiApi};
use input::{convert_key, keyval_to_input_string};
use ui::{UI, Ui, SET};
@ -24,7 +23,7 @@ const DEFAULT_FONT_NAME: &'static str = "DejaVu Sans Mono 12";
macro_rules! SHELL {
($id:ident = $expr:expr) => (
UI.with(|ui_cell| {
let mut $id = ui_cell.borrow_mut().shell;
let mut $id = &mut ui_cell.borrow_mut().shell;
$expr
});
)
@ -78,6 +77,7 @@ impl Shell {
self.drawing_area.set_size_request(500, 300);
self.drawing_area.set_hexpand(true);
self.drawing_area.set_vexpand(true);
self.drawing_area.set_can_focus(true);
self.drawing_area
.set_events((gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK |

View File

@ -4,15 +4,14 @@ use std::thread;
use gtk;
use gtk_sys;
use gtk::prelude::*;
use gtk::{ApplicationWindow, HeaderBar, DrawingArea, ToolButton, Image};
use gdk::{ModifierType, Event, EventKey, EventConfigure, EventButton, EventMotion, EventType};
use glib;
use gtk::{ApplicationWindow, HeaderBar, ToolButton, Image};
use gdk::Event;
use neovim_lib::{Neovim, NeovimApi, Value, Integer};
use neovim_lib::NeovimApi;
use settings;
use shell::{Shell, NvimMode};
use nvim::{RedrawEvents, GuiApi, ErrorReport};
use nvim::ErrorReport;
macro_rules! ui_thread_var {
@ -47,10 +46,15 @@ impl Ui {
}
}
pub fn destroy(&self) {
pub fn close_window(&self) {
self.window.as_ref().unwrap().destroy();
}
pub fn destroy(&mut self) {
self.close_window();
self.shell.nvim().ui_detach().expect("Error in ui_detach");
}
pub fn init(&mut self, app: &gtk::Application) {
if self.initialized {
return;
@ -120,10 +124,6 @@ fn quit() {
UI.with(|ui_cell| {
let mut ui = ui_cell.borrow_mut();
ui.destroy();
let nvim = ui.nvim();
nvim.ui_detach().expect("Error in ui_detach");
// nvim.quit_no_save().expect("Can't stop nvim instance");
});
}