paste command improvement

This commit is contained in:
daa 2017-03-08 22:22:58 +03:00
parent 5316b37919
commit c3d30177b1
2 changed files with 29 additions and 11 deletions

View File

@ -188,3 +188,17 @@ fn safe_call<F>(cb: F)
glib::Continue(false) glib::Continue(false)
}); });
} }
pub trait ErrorReport {
fn report_err(&self, nvim: &mut NeovimApi, ctx_msg: &str);
}
impl<T> ErrorReport for result::Result<T, String> {
fn report_err(&self, _: &mut NeovimApi, ctx_msg: &str) {
if let &Err(ref msg) = self {
let err_msg = format!("{} {}", ctx_msg, msg);
println!("{}", err_msg);
//nvim.report_error(&err_msg).expect("Error report error :)");
}
}
}

View File

@ -16,7 +16,7 @@ use glib;
use neovim_lib::{Neovim, NeovimApi, Value, Integer}; use neovim_lib::{Neovim, NeovimApi, Value, Integer};
use ui_model::{UiModel, Attrs, Color, COLOR_BLACK, COLOR_WHITE}; use ui_model::{UiModel, Attrs, Color, COLOR_BLACK, COLOR_WHITE};
use nvim::{RedrawEvents, GuiApi}; use nvim::{RedrawEvents, GuiApi, ErrorReport};
use input::{convert_key, keyval_to_input_string}; use input::{convert_key, keyval_to_input_string};
@ -189,12 +189,17 @@ fn gtk_motion_notify(_: &DrawingArea, ev: &EventMotion) -> Inhibit {
} }
fn edit_paste() { fn edit_paste() {
UI.with(|ui_cell| { UI.with(|ui_cell| {
let mut ui = ui_cell.borrow_mut(); let mut ui = ui_cell.borrow_mut();
if let Err(e) = ui.nvim().input("<Esc>\"*p") { let paste_command = if ui.mode == NvimMode::Normal {
println!("Error paste from clipboard {}", e); "\"*p"
} } else {
"<Esc>\"*p"
};
let mut nvim = ui.nvim();
nvim.input(paste_command).report_err(nvim, "Error paste from clipboard");
}); });
} }
@ -202,9 +207,8 @@ fn edit_save_all() {
UI.with(|ui_cell| { UI.with(|ui_cell| {
let mut ui = ui_cell.borrow_mut(); let mut ui = ui_cell.borrow_mut();
if let Err(e) = ui.nvim().command(":wa") { let mut nvim = ui.nvim();
println!("Error save all files {}", e); nvim.command(":wa").report_err(nvim, "Error save all files");
}
}); });
} }
@ -396,9 +400,9 @@ fn request_width(ui: &Ui) {
} }
impl GuiApi for Ui { impl GuiApi for Ui {
fn set_font(&mut self, font_desc: &str) { fn set_font(&mut self, font_desc: &str) {
self.set_font_desc(font_desc); self.set_font_desc(font_desc);
} }
} }
impl RedrawEvents for Ui { impl RedrawEvents for Ui {