From b1507a033486ab9296d32b821426d0ced07a9aba Mon Sep 17 00:00:00 2001 From: daa84 Date: Thu, 16 Mar 2017 13:18:13 +0300 Subject: [PATCH] Finish migration to shell.rs --- src/main.rs | 14 ++++++++------ src/shell.rs | 10 +++++----- src/ui.rs | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index ca7c04c..31fe675 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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: >k::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(args: I) -> Option .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) }); }); diff --git a/src/shell.rs b/src/shell.rs index 4ce8f82..c426b93 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -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 | diff --git a/src/ui.rs b/src/ui.rs index 4f1cf55..121250a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -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: >k::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"); }); }