2017-10-24 15:03:34 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use ui::UiMutex;
|
2017-10-23 15:07:04 +00:00
|
|
|
|
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-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-24 15:03:34 +00:00
|
|
|
manager: &'a Arc<UiMutex<manager::Manager>>,
|
2017-10-16 15:34:26 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 18:34:49 +00:00
|
|
|
impl<'a> Ui<'a> {
|
2017-10-24 15:03:34 +00:00
|
|
|
pub fn new(manager: &'a Arc<UiMutex<manager::Manager>>) -> Ui<'a> {
|
|
|
|
manager.borrow_mut().update_state();
|
|
|
|
|
2017-10-17 18:34:49 +00:00
|
|
|
Ui { manager }
|
2017-10-13 15:27:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-24 15:03:34 +00:00
|
|
|
pub fn show<T: IsA<gtk::Window>>(&mut self, parent: &T) {
|
2017-10-13 15:27:10 +00:00
|
|
|
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();
|
2017-10-27 15:06:18 +00:00
|
|
|
let top_panel = gtk::Box::new(gtk::Orientation::Horizontal, 3);
|
|
|
|
|
2017-10-13 15:27:10 +00:00
|
|
|
let tabs = gtk::Notebook::new();
|
2017-10-27 15:06:18 +00:00
|
|
|
tabs.set_tab_pos(gtk::PositionType::Left);
|
|
|
|
|
|
|
|
let enable_swc = gtk::Switch::new();
|
2017-10-13 15:27:10 +00:00
|
|
|
|
2017-10-24 15:03:34 +00:00
|
|
|
match self.manager.borrow_mut().plug_manage_state {
|
|
|
|
manager::PlugManageState::Unknown => {
|
|
|
|
let help = gtk::Box::new(gtk::Orientation::Vertical, 3);
|
|
|
|
let warn_lbl = gtk::Label::new(None);
|
|
|
|
warn_lbl.set_markup("<span foreground=\"red\">Note:</span> NeovimGtk plugin manager <b>disabled</b>!");
|
|
|
|
help.pack_start(&warn_lbl, true, false, 0);
|
|
|
|
|
|
|
|
let get_plugins_lbl = gtk::Label::new("Help");
|
|
|
|
tabs.append_page(&help, Some(&get_plugins_lbl));
|
|
|
|
}
|
|
|
|
manager::PlugManageState::Configuration(ref store) => {
|
2017-10-23 15:07:04 +00:00
|
|
|
let help = gtk::Box::new(gtk::Orientation::Vertical, 3);
|
2017-10-21 17:20:55 +00:00
|
|
|
let warn_lbl = gtk::Label::new(None);
|
2017-10-24 15:03:34 +00:00
|
|
|
warn_lbl.set_markup("<span foreground=\"red\">Note:</span> NeovimGtk plugin manager <b>disabled</b>!\n\
|
2017-10-27 15:06:18 +00:00
|
|
|
NeovimGtk manages plugins use vim-plug as backend, so enable it disables vim-plug configuration.");
|
2017-10-23 15:07:04 +00:00
|
|
|
help.pack_start(&warn_lbl, true, 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");
|
2017-10-23 15:07:04 +00:00
|
|
|
tabs.append_page(&help, Some(&get_plugins_lbl));
|
2017-10-24 15:03:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
self.add_plugin_list_tab(&tabs, store);
|
2017-10-17 18:34:49 +00:00
|
|
|
}
|
2017-10-24 15:03:34 +00:00
|
|
|
manager::PlugManageState::NvimGtk(ref store) => {
|
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-24 15:03:34 +00:00
|
|
|
|
|
|
|
self.add_plugin_list_tab(&tabs, store);
|
2017-10-17 18:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-13 15:27:10 +00:00
|
|
|
|
|
|
|
|
2017-10-27 15:06:18 +00:00
|
|
|
top_panel.pack_end(&enable_swc, false, false, 0);
|
|
|
|
|
|
|
|
content.pack_start(&top_panel, false, true, 3);
|
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-24 15:03:34 +00:00
|
|
|
fn add_plugin_list_tab(&self, tabs: >k::Notebook, store: &Store) {
|
|
|
|
// Plugins
|
|
|
|
let plugins = gtk::Box::new(gtk::Orientation::Vertical, 3);
|
|
|
|
self.fill_plugin_list(&plugins, store);
|
|
|
|
|
|
|
|
let plugins_lbl = gtk::Label::new("Plugins");
|
|
|
|
tabs.append_page(&plugins, Some(&plugins_lbl));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fill_plugin_list(&self, panel: >k::Box, store: &Store) {
|
2017-10-20 15:06:05 +00:00
|
|
|
let scroll = gtk::ScrolledWindow::new(None, None);
|
2017-10-21 17:20:55 +00:00
|
|
|
let plugs_panel = gtk::ListBox::new();
|
2017-10-23 15:07:04 +00:00
|
|
|
plugs_panel.set_selection_mode(gtk::SelectionMode::None);
|
2017-10-21 17:20:55 +00:00
|
|
|
|
2017-10-24 15:03:34 +00:00
|
|
|
for (idx, plug_info) in store.get_plugs().iter().enumerate() {
|
2017-10-23 15:07:04 +00:00
|
|
|
let row = gtk::ListBoxRow::new();
|
|
|
|
let row_container = gtk::Box::new(gtk::Orientation::Vertical, 5);
|
|
|
|
let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 5);
|
|
|
|
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 5);
|
2017-10-21 17:20:55 +00:00
|
|
|
|
|
|
|
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-23 15:07:04 +00:00
|
|
|
url_lbl.set_halign(gtk::Align::Start);
|
|
|
|
let remove_btn = gtk::Button::new_with_label("Remove");
|
|
|
|
remove_btn.set_halign(gtk::Align::End);
|
|
|
|
|
|
|
|
let store_ref = store.clone();
|
|
|
|
let panel_ref = panel.clone();
|
|
|
|
let row_ref = row.clone();
|
|
|
|
remove_btn.connect_clicked(move |_| {
|
|
|
|
// store_ref.borrow_mut().remove(idx);
|
2017-10-24 15:03:34 +00:00
|
|
|
row_ref.remove(row_ref.get_child().as_ref().unwrap());
|
|
|
|
let undo_btn = gtk::Button::new_with_label("Undo");
|
|
|
|
let row_container = gtk::Box::new(gtk::Orientation::Horizontal, 5);
|
|
|
|
row_container.pack_end(&undo_btn, false, true, 0);
|
|
|
|
row_ref.add(&row_container);
|
|
|
|
row_container.show_all();
|
2017-10-23 15:07:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
row_container.pack_start(&hbox, true, true, 0);
|
2017-10-24 15:03:34 +00:00
|
|
|
row_container.pack_start(
|
|
|
|
>k::Separator::new(gtk::Orientation::Horizontal),
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
0,
|
|
|
|
);
|
2017-10-23 15:07:04 +00:00
|
|
|
vbox.pack_start(&name_lbl, true, true, 0);
|
|
|
|
vbox.pack_start(&url_lbl, true, true, 0);
|
|
|
|
hbox.pack_start(&vbox, true, true, 0);
|
|
|
|
hbox.pack_start(&remove_btn, false, true, 0);
|
|
|
|
|
|
|
|
row.add(&row_container);
|
|
|
|
plugs_panel.add(&row);
|
2017-10-21 17:20:55 +00:00
|
|
|
}
|
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-18 14:49:56 +00:00
|
|
|
}
|
2017-10-13 15:27:10 +00:00
|
|
|
}
|