Use colors for selected items, enable popup menu by default

This commit is contained in:
daa84 2017-11-16 16:53:58 +03:00
parent 3b9de543ae
commit 50603b4325
4 changed files with 43 additions and 7 deletions

View File

@ -36,6 +36,15 @@ impl Color {
(std::u16::MAX as f64 * self.2) as u16, (std::u16::MAX as f64 * self.2) as u16,
) )
} }
pub fn to_hex(&self) -> String {
format!(
"#{:X}{:X}{:X}",
(self.0 * 255.0) as u8,
(self.1 * 255.0) as u8,
(self.2 * 255.0) as u8
)
}
} }
pub struct ColorModel { pub struct ColorModel {
@ -93,7 +102,7 @@ impl ColorModel {
} }
} }
pub fn actual_cell_bg<'a>(&'a self, cell: &'a Cell) -> &'a Color { pub fn actual_cell_bg<'a>(&'a self, cell: &'a Cell) -> &'a Color {
if !cell.attrs.reverse { if !cell.attrs.reverse {
cell.attrs.background.as_ref().unwrap_or(&self.bg_color) cell.attrs.background.as_ref().unwrap_or(&self.bg_color)
} else { } else {
@ -102,7 +111,7 @@ impl ColorModel {
} }
#[inline] #[inline]
pub fn actual_cell_sp<'a>(&'a self, cell: &'a Cell) -> &'a Color { pub fn actual_cell_sp<'a>(&'a self, cell: &'a Cell) -> &'a Color {
cell.attrs.special.as_ref().unwrap_or(&self.sp_color) cell.attrs.special.as_ref().unwrap_or(&self.sp_color)
} }

View File

@ -137,7 +137,7 @@ pub fn post_start_init(
rows: u64, rows: u64,
) -> result::Result<(), NvimInitError> { ) -> result::Result<(), NvimInitError> {
let mut opts = UiAttachOptions::new(); let mut opts = UiAttachOptions::new();
opts.set_popupmenu_external(false); opts.set_popupmenu_external(true);
opts.set_tabline_external(true); opts.set_tabline_external(true);
nvim.borrow().unwrap().ui_attach(cols, rows, &opts).map_err( nvim.borrow().unwrap().ui_attach(cols, rows, &opts).map_err(
NvimInitError::new_post_init, NvimInitError::new_post_init,

View File

@ -9,8 +9,8 @@ use gdk::{EventButton, EventType};
use neovim_lib::{Neovim, NeovimApi}; use neovim_lib::{Neovim, NeovimApi};
use nvim; use color::ColorModel;
use nvim::ErrorReport; use nvim::{self, ErrorReport};
use shell; use shell;
use input; use input;
@ -21,15 +21,23 @@ struct State {
renderer: gtk::CellRendererText, renderer: gtk::CellRendererText,
tree: gtk::TreeView, tree: gtk::TreeView,
scroll: gtk::ScrolledWindow, scroll: gtk::ScrolledWindow,
css_provider: gtk::CssProvider,
} }
impl State { impl State {
pub fn new() -> Self { pub fn new() -> Self {
let tree = gtk::TreeView::new();
let css_provider = gtk::CssProvider::new();
let style_context = tree.get_style_context().unwrap();
style_context.add_provider(&css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
State { State {
nvim: None, nvim: None,
renderer: gtk::CellRendererText::new(), renderer: gtk::CellRendererText::new(),
tree: gtk::TreeView::new(), tree,
scroll: gtk::ScrolledWindow::new(None, None), scroll: gtk::ScrolledWindow::new(None, None),
css_provider,
} }
} }
@ -59,6 +67,8 @@ impl State {
Some(&color_model.pmenu_bg().into()), Some(&color_model.pmenu_bg().into()),
); );
self.update_css(color_model);
let col_count = menu[0].len(); let col_count = menu[0].len();
let columns = self.tree.get_columns(); let columns = self.tree.get_columns();
@ -84,6 +94,23 @@ impl State {
self.tree.set_model(Some(&list_store)); self.tree.set_model(Some(&list_store));
} }
fn update_css(&self, color_model: &ColorModel) {
let bg = color_model.pmenu_bg_sel();
let fg = color_model.pmenu_fg_sel();
match gtk::CssProviderExtManual::load_from_data(
&self.css_provider,
&format!(
".view {{ color: {}; background-color: {};}}",
fg.to_hex(),
bg.to_hex()
),
) {
Err(e) => error!("Can't update css {}", e),
Ok(_) => (),
};
}
fn append_column(&self, id: i32) { fn append_column(&self, id: i32) {
let renderer = &self.renderer; let renderer = &self.renderer;

View File

@ -34,7 +34,7 @@ use render;
use render::CellMetrics; use render::CellMetrics;
const DEFAULT_FONT_NAME: &str = "DejaVu Sans Mono 12"; const DEFAULT_FONT_NAME: &str = "DejaVu Sans Mono 12";
pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2"; pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2.1";
macro_rules! idle_cb_call { macro_rules! idle_cb_call {
($state:ident.$cb:ident($( $x:expr ),*)) => ( ($state:ident.$cb:ident($( $x:expr ),*)) => (