Finish tabline implementation
This commit is contained in:
parent
42538027bf
commit
30f9ea98a1
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -13,7 +13,7 @@ dependencies = [
|
||||
"gtk-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"neovim-lib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"neovim-lib 0.4.1 (git+https://github.com/daa84/neovim-lib)",
|
||||
"pango 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pangocairo 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -294,7 +294,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "neovim-lib"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
source = "git+https://github.com/daa84/neovim-lib#d8addb7e84bce9bfd9ae47f5433fd33f314f1a07"
|
||||
dependencies = [
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rmp 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -584,7 +584,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
|
||||
"checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad"
|
||||
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
|
||||
"checksum neovim-lib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c4f4cf765a2dee99de95861fc1eea0b64da31552b2f8d85bfd1edb59fc26f1b9"
|
||||
"checksum neovim-lib 0.4.1 (git+https://github.com/daa84/neovim-lib)" = "<none>"
|
||||
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
|
||||
"checksum pango 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4215233226ff03c9a3ed7c85cbc3c58257203723e3a93d5a20ce3560f66261b7"
|
||||
"checksum pango-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e401ee469540e60a80d1df63dcea4e9c201115e79344b77529fa3705ea8eadcd"
|
||||
|
@ -12,7 +12,7 @@ glib = "0.1"
|
||||
glib-sys = "0.3"
|
||||
gdk = "0.5"
|
||||
gdk-sys = "0.3"
|
||||
neovim-lib = "0.4"
|
||||
#neovim-lib = "0.4"
|
||||
phf = "0.7"
|
||||
gio = "0.1"
|
||||
log = "0.3"
|
||||
@ -23,8 +23,8 @@ serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
toml = "0.4"
|
||||
|
||||
#[dependencies.neovim-lib]
|
||||
#git = "https://github.com/daa84/neovim-lib"
|
||||
[dependencies.neovim-lib]
|
||||
git = "https://github.com/daa84/neovim-lib"
|
||||
|
||||
[build-dependencies]
|
||||
phf_codegen = "0.7"
|
||||
|
@ -885,7 +885,7 @@ impl RedrawEvents for State {
|
||||
|
||||
|
||||
fn tabline_update(&mut self, selected: Tabpage, tabs: Vec<(Tabpage, Option<&str>)>) -> RepaintMode {
|
||||
self.tabs.update_tabs(&selected, &tabs);
|
||||
self.tabs.update_tabs(&self.nvim.as_ref().unwrap(), &selected, &tabs);
|
||||
|
||||
RepaintMode::Nothing
|
||||
}
|
||||
|
@ -1,12 +1,38 @@
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use neovim_lib::{Neovim, NeovimApi};
|
||||
use neovim_lib::neovim_api::Tabpage;
|
||||
|
||||
use nvim::ErrorReport;
|
||||
|
||||
struct State {
|
||||
data: Vec<Tabpage>,
|
||||
nvim: Option<Rc<RefCell<Neovim>>>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> Self {
|
||||
State {
|
||||
data: Vec::new(),
|
||||
nvim: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn change_current_page(&self, idx: i32) -> bool {
|
||||
let mut nvim = self.nvim.as_ref().unwrap().borrow_mut();
|
||||
nvim.set_current_tabpage(&self.data[idx as usize]).report_err(&mut *nvim);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Tabline {
|
||||
tabs: gtk::Notebook,
|
||||
state: Rc<RefCell<State>>,
|
||||
}
|
||||
|
||||
impl Tabline {
|
||||
@ -17,13 +43,33 @@ impl Tabline {
|
||||
tabs.set_scrollable(true);
|
||||
tabs.set_show_border(false);
|
||||
tabs.set_border_width(0);
|
||||
tabs.hide();
|
||||
|
||||
let state = Rc::new(RefCell::new(State::new()));
|
||||
|
||||
let state_ref = state.clone();
|
||||
tabs.connect_change_current_page(move |_, idx| state_ref.borrow().change_current_page(idx));
|
||||
|
||||
Tabline {
|
||||
tabs,
|
||||
state,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_tabs(&self, selected: &Tabpage, tabs: &Vec<(Tabpage, Option<&str>)>) {
|
||||
pub fn update_tabs(&self, nvim: &Rc<RefCell<Neovim>>, selected: &Tabpage, tabs: &Vec<(Tabpage, Option<&str>)>) {
|
||||
if tabs.len() <= 1 {
|
||||
self.tabs.hide();
|
||||
return;
|
||||
} else {
|
||||
self.tabs.show();
|
||||
}
|
||||
|
||||
let mut state = self.state.borrow_mut();
|
||||
|
||||
if state.nvim.is_none() {
|
||||
state.nvim = Some(nvim.clone());
|
||||
}
|
||||
|
||||
let count = self.tabs.get_n_pages() as usize;
|
||||
if count < tabs.len() {
|
||||
for _ in count..tabs.len() {
|
||||
@ -38,10 +84,16 @@ impl Tabline {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: current page
|
||||
state.data.clear();
|
||||
|
||||
for (idx, tab) in tabs.iter().enumerate() {
|
||||
let tab_child = self.tabs.get_nth_page(Some(idx as u32));
|
||||
self.tabs.set_tab_label_text(&tab_child.unwrap(), &tab.1.unwrap_or("??"));
|
||||
state.data.push(tab.0.clone());
|
||||
|
||||
if *selected == tab.0 {
|
||||
self.tabs.set_current_page(Some(idx as u32));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user