Show wild menu, starting point
This commit is contained in:
parent
0ff34d0cbe
commit
d288caf37f
@ -7,6 +7,7 @@ use std::cmp::max;
|
|||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use cairo;
|
use cairo;
|
||||||
|
use pango;
|
||||||
|
|
||||||
use neovim_lib::Value;
|
use neovim_lib::Value;
|
||||||
|
|
||||||
@ -262,6 +263,8 @@ impl cursor::CursorRedrawCb for State {
|
|||||||
|
|
||||||
pub struct CmdLine {
|
pub struct CmdLine {
|
||||||
popover: gtk::Popover,
|
popover: gtk::Popover,
|
||||||
|
wild_tree: gtk::TreeView,
|
||||||
|
wild_scroll: gtk::ScrolledWindow,
|
||||||
displyed: bool,
|
displyed: bool,
|
||||||
state: Arc<UiMutex<State>>,
|
state: Arc<UiMutex<State>>,
|
||||||
}
|
}
|
||||||
@ -272,9 +275,10 @@ impl CmdLine {
|
|||||||
popover.set_modal(false);
|
popover.set_modal(false);
|
||||||
popover.set_position(gtk::PositionType::Right);
|
popover.set_position(gtk::PositionType::Right);
|
||||||
|
|
||||||
|
let content = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||||
|
|
||||||
let drawing_area = gtk::DrawingArea::new();
|
let drawing_area = gtk::DrawingArea::new();
|
||||||
drawing_area.show_all();
|
content.pack_start(&drawing_area, true, true, 0);
|
||||||
popover.add(&drawing_area);
|
|
||||||
|
|
||||||
let state = Arc::new(UiMutex::new(State::new(drawing_area.clone(), render_state)));
|
let state = Arc::new(UiMutex::new(State::new(drawing_area.clone(), render_state)));
|
||||||
let weak_cb = Arc::downgrade(&state);
|
let weak_cb = Arc::downgrade(&state);
|
||||||
@ -283,13 +287,49 @@ impl CmdLine {
|
|||||||
|
|
||||||
drawing_area.connect_draw(clone!(state => move |_, ctx| gtk_draw(ctx, &state)));
|
drawing_area.connect_draw(clone!(state => move |_, ctx| gtk_draw(ctx, &state)));
|
||||||
|
|
||||||
|
|
||||||
|
let (wild_scroll, wild_tree) = CmdLine::create_widlmenu();
|
||||||
|
content.pack_start(&wild_scroll, false, true, 0);
|
||||||
|
popover.add(&content);
|
||||||
|
|
||||||
|
drawing_area.show_all();
|
||||||
|
content.show();
|
||||||
|
|
||||||
CmdLine {
|
CmdLine {
|
||||||
popover,
|
popover,
|
||||||
state,
|
state,
|
||||||
displyed: false,
|
displyed: false,
|
||||||
|
wild_scroll,
|
||||||
|
wild_tree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_widlmenu() -> (gtk::ScrolledWindow, gtk::TreeView) {
|
||||||
|
let tree = gtk::TreeView::new();
|
||||||
|
|
||||||
|
tree.get_selection().set_mode(gtk::SelectionMode::Single);
|
||||||
|
tree.set_headers_visible(false);
|
||||||
|
tree.set_can_focus(false);
|
||||||
|
|
||||||
|
let renderer = gtk::CellRendererText::new();
|
||||||
|
renderer.set_property_ellipsize(pango::EllipsizeMode::End);
|
||||||
|
|
||||||
|
let word_column = gtk::TreeViewColumn::new();
|
||||||
|
word_column.pack_start(&renderer, true);
|
||||||
|
word_column.add_attribute(&renderer, "text", 0);
|
||||||
|
tree.append_column(&word_column);
|
||||||
|
|
||||||
|
let scroll = gtk::ScrolledWindow::new(None, None);
|
||||||
|
scroll.set_propagate_natural_height(true);
|
||||||
|
|
||||||
|
scroll.add(&tree);
|
||||||
|
|
||||||
|
tree.show_all();
|
||||||
|
scroll.hide();
|
||||||
|
|
||||||
|
(scroll, tree)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show_level(&mut self, ctx: &CmdLineContext) {
|
pub fn show_level(&mut self, ctx: &CmdLineContext) {
|
||||||
let mut state = self.state.borrow_mut();
|
let mut state = self.state.borrow_mut();
|
||||||
let render_state = state.render_state.clone();
|
let render_state = state.render_state.clone();
|
||||||
@ -405,6 +445,19 @@ impl CmdLine {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.set_mode_info(mode_info);
|
.set_mode_info(mode_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_wildmenu(&self, items: Vec<String>) {
|
||||||
|
let list_store = gtk::ListStore::new(&vec![gtk::Type::String; 1]);
|
||||||
|
for item in items {
|
||||||
|
list_store.insert_with_values(None, &[0], &[&item]);
|
||||||
|
}
|
||||||
|
self.wild_tree.set_model(&list_store);
|
||||||
|
self.wild_scroll.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hide_wildmenu(&self) {
|
||||||
|
self.wild_scroll.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtk_draw(ctx: &cairo::Context, state: &Arc<UiMutex<State>>) -> Inhibit {
|
fn gtk_draw(ctx: &cairo::Context, state: &Arc<UiMutex<State>>) -> Inhibit {
|
||||||
|
@ -110,6 +110,8 @@ pub fn call_gui_event(
|
|||||||
.ok_or_else(|| "Nvim not initialized".to_owned())
|
.ok_or_else(|| "Nvim not initialized".to_owned())
|
||||||
.and_then(|mut nvim| {
|
.and_then(|mut nvim| {
|
||||||
nvim.set_option(UiOption::ExtCmdline(try_uint!(args[1]) == 1))
|
nvim.set_option(UiOption::ExtCmdline(try_uint!(args[1]) == 1))
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
nvim.set_option(UiOption::ExtWildmenu(try_uint!(args[1]) == 1))
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
})?,
|
})?,
|
||||||
opt => error!("Unknown option {}", opt),
|
opt => error!("Unknown option {}", opt),
|
||||||
@ -229,6 +231,8 @@ pub fn call(
|
|||||||
"cmdline_block_hide" => ui.cmdline_block_hide(),
|
"cmdline_block_hide" => ui.cmdline_block_hide(),
|
||||||
"cmdline_pos" => call!(ui->cmdline_pos(args: uint, uint)),
|
"cmdline_pos" => call!(ui->cmdline_pos(args: uint, uint)),
|
||||||
"cmdline_special_char" => call!(ui->cmdline_special_char(args: str, bool, uint)),
|
"cmdline_special_char" => call!(ui->cmdline_special_char(args: str, bool, uint)),
|
||||||
|
"wildmenu_show" => call!(ui->wildmenu_show(args: ext)),
|
||||||
|
"wildmenu_hide" => ui.wildmenu_hide(),
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Event {}({:?})", method, args);
|
warn!("Event {}({:?})", method, args);
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
|
@ -152,7 +152,7 @@ impl State {
|
|||||||
list_store.insert_with_values(None, &all_column_ids, &line_array[..]);
|
list_store.insert_with_values(None, &all_column_ids, &line_array[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tree.set_model(Some(&list_store));
|
self.tree.set_model(&list_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_css(&self, color_model: &ColorModel) {
|
fn update_css(&self, color_model: &ColorModel) {
|
||||||
|
10
src/shell.rs
10
src/shell.rs
@ -1421,6 +1421,16 @@ impl State {
|
|||||||
self.cmd_line.special_char(&*render_state, c, shift, level);
|
self.cmd_line.special_char(&*render_state, c, shift, level);
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn wildmenu_show(&mut self, items: Vec<String>) -> RepaintMode {
|
||||||
|
self.cmd_line.show_wildmenu(items);
|
||||||
|
RepaintMode::Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn wildmenu_hide(&mut self) -> RepaintMode {
|
||||||
|
self.cmd_line.hide_wildmenu();
|
||||||
|
RepaintMode::Nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CursorRedrawCb for State {
|
impl CursorRedrawCb for State {
|
||||||
|
Loading…
Reference in New Issue
Block a user