use std::ops::Deref;
use htmlescape::encode_minimal;
use gtk;
use gtk::prelude::*;
use gtk_sys;
use shell;
pub struct ErrorArea {
base: gtk::Box,
label: gtk::Label,
}
impl ErrorArea {
pub fn new() -> Self {
let base = gtk::Box::new(gtk::Orientation::Horizontal, 0);
let label = gtk::Label::new(None);
label.set_line_wrap(true);
let error_image = gtk::Image::new_from_icon_name("dialog-error",
gtk_sys::GTK_ICON_SIZE_DIALOG as i32);
base.pack_start(&error_image, false, true, 10);
base.pack_start(&label, true, true, 1);
ErrorArea { base, label }
}
pub fn show_nvim_init_error(&self, err: &str) {
error!("Can't initialize nvim: {}", err);
self.label.set_markup(&format!("Can't initialize nvim:\n\
{}\n\n\
Possible error reasons:\n\
● Not supported nvim version (minimum supported version is {})\n\
● Error in configuration file (init.vim or ginit.vim)\n\
● Wrong nvim binary path \
(right path can be passed with --nvim-bin-path=path_here)",
encode_minimal(err), shell::MINIMUM_SUPPORTED_NVIM_VERSION));
self.base.show_all();
}
pub fn show_nvim_start_error(&self, err: &str, cmd: &str) {
error!("Can't start nvim: {}\nCommand line: {}", err, cmd);
self.label.set_markup(&format!("Can't start nvim instance:\n\
{}\n\
{}\n\n\
Possible error reasons:\n\
● Not supported nvim version (minimum supported version is {})\n\
● Error in configuration file (init.vim or ginit.vim)\n\
● Wrong nvim binary path \
(right path can be passed with --nvim-bin-path=path_here)",
encode_minimal(cmd), encode_minimal(err), shell::MINIMUM_SUPPORTED_NVIM_VERSION));
self.base.show_all();
}
}
impl Deref for ErrorArea {
type Target = gtk::Box;
fn deref(&self) -> >k::Box {
&self.base
}
}