2017-10-13 15:27:10 +00:00
|
|
|
use gtk;
|
|
|
|
use gtk::prelude::*;
|
|
|
|
|
2017-10-16 15:34:26 +00:00
|
|
|
use super::manager;
|
2017-10-18 14:49:56 +00:00
|
|
|
use super::vim_plug;
|
2017-10-20 15:06:05 +00:00
|
|
|
use super::store::Store;
|
2017-10-13 15:27:10 +00:00
|
|
|
|
2017-10-17 18:34:49 +00:00
|
|
|
pub struct Ui<'a> {
|
2017-10-16 15:34:26 +00:00
|
|
|
manager: &'a manager::Manager,
|
|
|
|
}
|
|
|
|
|
2017-10-17 18:34:49 +00:00
|
|
|
impl<'a> Ui<'a> {
|
2017-10-16 15:34:26 +00:00
|
|
|
pub fn new(manager: &'a manager::Manager) -> Ui<'a> {
|
2017-10-17 18:34:49 +00:00
|
|
|
Ui { manager }
|
2017-10-13 15:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn show<T: IsA<gtk::Window>>(&self, parent: &T) {
|
|
|
|
const OK_ID: i32 = 0;
|
|
|
|
|
|
|
|
let dlg = gtk::Dialog::new_with_buttons(
|
|
|
|
Some("Plug"),
|
|
|
|
Some(parent),
|
|
|
|
gtk::DialogFlags::empty(),
|
|
|
|
&[("Ok", OK_ID)],
|
|
|
|
);
|
|
|
|
|
2017-10-21 17:20:55 +00:00
|
|
|
dlg.set_default_size(800, 600);
|
2017-10-13 15:27:10 +00:00
|
|
|
let content = dlg.get_content_area();
|
|
|
|
let tabs = gtk::Notebook::new();
|
|
|
|
|
2017-10-20 15:06:05 +00:00
|
|
|
let vim_plug_state = self.get_state();
|
|
|
|
match vim_plug_state {
|
2017-10-18 14:49:56 +00:00
|
|
|
vim_plug::State::AlreadyLoaded => {
|
2017-10-21 17:20:55 +00:00
|
|
|
let get_plugins = gtk::Box::new(gtk::Orientation::Vertical, 3);
|
|
|
|
let warn_lbl = gtk::Label::new(None);
|
|
|
|
warn_lbl.set_markup("<span foreground=\"red\">Note:</span> <b>vim-plug</b> manager already loaded.\n\
|
2017-10-17 18:34:49 +00:00
|
|
|
NeovimGtk manages plugins using vim-plug as backend.\n\
|
2017-10-20 15:06:05 +00:00
|
|
|
To allow NeovimGtk manage plugins please disable vim-plug in your configuration.\n\
|
|
|
|
You can convert vim-plug configuration to NeovimGtk conviguration using button below.\n\
|
|
|
|
List of current vim-plug plugins can be found in 'Plugins' tab.",
|
2017-10-17 18:34:49 +00:00
|
|
|
);
|
2017-10-21 17:20:55 +00:00
|
|
|
get_plugins.pack_start(&warn_lbl, true, false, 0);
|
2017-10-20 15:06:05 +00:00
|
|
|
|
|
|
|
let copy_btn = gtk::Button::new_with_label("Copy plugins from current vim-plug configuration");
|
2017-10-21 17:20:55 +00:00
|
|
|
get_plugins.pack_start(©_btn, false, false, 0);
|
2017-10-20 15:06:05 +00:00
|
|
|
|
2017-10-17 18:34:49 +00:00
|
|
|
let get_plugins_lbl = gtk::Label::new("Help");
|
|
|
|
tabs.append_page(&get_plugins, Some(&get_plugins_lbl));
|
|
|
|
}
|
2017-10-18 14:49:56 +00:00
|
|
|
vim_plug::State::Unknown => {
|
2017-10-17 18:34:49 +00:00
|
|
|
let get_plugins = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
|
|
|
let get_plugins_lbl = gtk::Label::new("Get Plugins");
|
|
|
|
tabs.append_page(&get_plugins, Some(&get_plugins_lbl));
|
|
|
|
}
|
|
|
|
}
|
2017-10-13 15:27:10 +00:00
|
|
|
|
2017-10-21 17:20:55 +00:00
|
|
|
let plugins = gtk::Box::new(gtk::Orientation::Vertical, 3);
|
2017-10-20 15:06:05 +00:00
|
|
|
let store = self.manager.load_store(&vim_plug_state);
|
|
|
|
|
|
|
|
self.fill_plugin_list(&plugins, &store);
|
|
|
|
|
2017-10-13 15:27:10 +00:00
|
|
|
let plugins_lbl = gtk::Label::new("Plugins");
|
|
|
|
tabs.append_page(&plugins, Some(&plugins_lbl));
|
|
|
|
|
|
|
|
tabs.set_tab_pos(gtk::PositionType::Left);
|
2017-10-21 17:20:55 +00:00
|
|
|
content.pack_start(&tabs, true, true, 0);
|
2017-10-13 15:27:10 +00:00
|
|
|
content.show_all();
|
|
|
|
|
|
|
|
|
|
|
|
match dlg.run() {
|
|
|
|
OK_ID => {
|
|
|
|
println!("TODO:");
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg.destroy();
|
|
|
|
}
|
2017-10-17 18:34:49 +00:00
|
|
|
|
2017-10-20 15:06:05 +00:00
|
|
|
fn fill_plugin_list(&self, panel: >k::Box, store: &Store) {
|
|
|
|
let scroll = gtk::ScrolledWindow::new(None, None);
|
2017-10-21 17:20:55 +00:00
|
|
|
let plugs_panel = gtk::ListBox::new();
|
|
|
|
|
|
|
|
for plug_info in store.get_plugs() {
|
|
|
|
let grid = gtk::Grid::new();
|
|
|
|
|
|
|
|
let name_lbl = gtk::Label::new(None);
|
|
|
|
name_lbl.set_markup(&format!("<b>{}</b>", plug_info.name.as_str()));
|
|
|
|
name_lbl.set_halign(gtk::Align::Start);
|
|
|
|
let url_lbl = gtk::Label::new(Some(plug_info.url.as_str()));
|
2017-10-20 15:06:05 +00:00
|
|
|
|
2017-10-21 17:20:55 +00:00
|
|
|
grid.attach(&name_lbl, 0, 0, 1, 1);
|
|
|
|
grid.attach(&url_lbl, 0, 1, 1, 1);
|
|
|
|
|
|
|
|
plugs_panel.insert(&grid, -1);
|
|
|
|
}
|
2017-10-20 15:06:05 +00:00
|
|
|
|
2017-10-21 17:20:55 +00:00
|
|
|
scroll.add(&plugs_panel);
|
|
|
|
panel.pack_start(&scroll, true, true, 0);
|
2017-10-20 15:06:05 +00:00
|
|
|
|
|
|
|
let copy_btn = gtk::Button::new_with_label("Copy plugins from current vim-plug configuration");
|
|
|
|
panel.add(©_btn);
|
2017-10-18 14:49:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 15:06:05 +00:00
|
|
|
fn get_state(&self) -> vim_plug::State {
|
|
|
|
self.manager.vim_plug.get_state()
|
2017-10-17 18:34:49 +00:00
|
|
|
}
|
2017-10-13 15:27:10 +00:00
|
|
|
}
|
2017-10-20 15:06:05 +00:00
|
|
|
|