Add base code for add plugin dialog
This commit is contained in:
parent
4aec520746
commit
0a7edbc602
@ -2,6 +2,7 @@ mod ui;
|
|||||||
mod vim_plug;
|
mod vim_plug;
|
||||||
mod store;
|
mod store;
|
||||||
mod manager;
|
mod manager;
|
||||||
|
mod plugin_settings_dlg;
|
||||||
|
|
||||||
pub use self::ui::Ui;
|
pub use self::ui::Ui;
|
||||||
pub use self::manager::{Manager, PlugManagerConfigSource};
|
pub use self::manager::{Manager, PlugManagerConfigSource};
|
||||||
|
44
src/plug_manager/plugin_settings_dlg.rs
Normal file
44
src/plug_manager/plugin_settings_dlg.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use super::store;
|
||||||
|
|
||||||
|
pub struct Builder<'a> {
|
||||||
|
title: &'a str
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <'a> Builder <'a> {
|
||||||
|
pub fn new(title: &'a str) -> Self {
|
||||||
|
Builder { title }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show<F: IsA<gtk::Window>>(&self, parent: &F) -> Option<store::PlugInfo> {
|
||||||
|
let dlg = gtk::Dialog::new_with_buttons(
|
||||||
|
Some(self.title),
|
||||||
|
Some(parent),
|
||||||
|
gtk::DIALOG_USE_HEADER_BAR | gtk::DIALOG_DESTROY_WITH_PARENT,
|
||||||
|
&[("Cancel", gtk::ResponseType::Cancel.into()),
|
||||||
|
("Ok", gtk::ResponseType::Accept.into())],
|
||||||
|
);
|
||||||
|
|
||||||
|
let content = dlg.get_content_area();
|
||||||
|
let grid = gtk::Grid::new();
|
||||||
|
|
||||||
|
let label = gtk::Label::new("Path:");
|
||||||
|
let entry = gtk::Entry::new();
|
||||||
|
|
||||||
|
grid.attach(&label, 0, 0, 1, 1);
|
||||||
|
grid.attach(&entry, 1, 0, 1, 1);
|
||||||
|
|
||||||
|
content.add(&grid);
|
||||||
|
content.show_all();
|
||||||
|
|
||||||
|
if dlg.run() == gtk::ResponseType::Ok.into() {
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg.destroy();
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ use gtk::prelude::*;
|
|||||||
|
|
||||||
use super::manager;
|
use super::manager;
|
||||||
use super::store::{Store, PlugInfo};
|
use super::store::{Store, PlugInfo};
|
||||||
|
use super::plugin_settings_dlg;
|
||||||
|
|
||||||
pub struct Ui<'a> {
|
pub struct Ui<'a> {
|
||||||
manager: &'a Arc<UiMutex<manager::Manager>>,
|
manager: &'a Arc<UiMutex<manager::Manager>>,
|
||||||
@ -23,13 +24,11 @@ impl<'a> Ui<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn show<T: IsA<gtk::Window>>(&mut self, parent: &T) {
|
pub fn show<T: IsA<gtk::Window>>(&mut self, parent: &T) {
|
||||||
const OK_ID: i32 = 0;
|
|
||||||
|
|
||||||
let dlg = gtk::Dialog::new_with_buttons(
|
let dlg = gtk::Dialog::new_with_buttons(
|
||||||
Some("Plug"),
|
Some("Plug"),
|
||||||
Some(parent),
|
Some(parent),
|
||||||
gtk::DialogFlags::empty(),
|
gtk::DIALOG_DESTROY_WITH_PARENT,
|
||||||
&[("Ok", OK_ID)],
|
&[("Ok", gtk::ResponseType::Ok.into())],
|
||||||
);
|
);
|
||||||
|
|
||||||
dlg.set_default_size(800, 600);
|
dlg.set_default_size(800, 600);
|
||||||
@ -37,6 +36,14 @@ impl<'a> Ui<'a> {
|
|||||||
|
|
||||||
let header_bar = gtk::HeaderBar::new();
|
let header_bar = gtk::HeaderBar::new();
|
||||||
|
|
||||||
|
let add_plug_btn = gtk::Button::new_with_label("Add..");
|
||||||
|
header_bar.pack_end(&add_plug_btn);
|
||||||
|
|
||||||
|
let manager_ref = self.manager.clone();
|
||||||
|
add_plug_btn.connect_clicked(clone!(dlg => move |_| {
|
||||||
|
add_plugin(&dlg, &manager_ref);
|
||||||
|
}));
|
||||||
|
|
||||||
let enable_swc = gtk::Switch::new();
|
let enable_swc = gtk::Switch::new();
|
||||||
enable_swc.set_valign(gtk::Align::Center);
|
enable_swc.set_valign(gtk::Align::Center);
|
||||||
|
|
||||||
@ -49,7 +56,11 @@ impl<'a> Ui<'a> {
|
|||||||
|
|
||||||
dlg.set_titlebar(&header_bar);
|
dlg.set_titlebar(&header_bar);
|
||||||
|
|
||||||
let pages = SettingsPages::new();
|
let pages = SettingsPages::new(move |row_name| if row_name == "plugins" {
|
||||||
|
add_plug_btn.show();
|
||||||
|
} else {
|
||||||
|
add_plug_btn.hide();
|
||||||
|
});
|
||||||
|
|
||||||
match self.manager.borrow_mut().plug_manage_state {
|
match self.manager.borrow_mut().plug_manage_state {
|
||||||
manager::PlugManageState::Unknown => {
|
manager::PlugManageState::Unknown => {
|
||||||
@ -91,13 +102,10 @@ impl<'a> Ui<'a> {
|
|||||||
content.show_all();
|
content.show_all();
|
||||||
|
|
||||||
|
|
||||||
match dlg.run() {
|
if dlg.run() == gtk::ResponseType::Ok.into() {
|
||||||
OK_ID => {
|
let mut manager = self.manager.borrow_mut();
|
||||||
let mut manager = self.manager.borrow_mut();
|
manager.clear_removed();
|
||||||
manager.clear_removed();
|
manager.save();
|
||||||
manager.save();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dlg.destroy();
|
dlg.destroy();
|
||||||
@ -172,6 +180,10 @@ impl<'a> Ui<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_plugin<F: IsA<gtk::Window>>(parent: &F, manager: &Arc<UiMutex<manager::Manager>>) {
|
||||||
|
plugin_settings_dlg::Builder::new("Add plugin").show(parent);
|
||||||
|
}
|
||||||
|
|
||||||
fn create_plug_label(plug_info: &PlugInfo) -> gtk::Box {
|
fn create_plug_label(plug_info: &PlugInfo) -> gtk::Box {
|
||||||
let label_box = gtk::Box::new(gtk::Orientation::Vertical, 5);
|
let label_box = gtk::Box::new(gtk::Orientation::Vertical, 5);
|
||||||
|
|
||||||
@ -202,10 +214,11 @@ struct SettingsPages {
|
|||||||
stack: gtk::Stack,
|
stack: gtk::Stack,
|
||||||
content: gtk::Box,
|
content: gtk::Box,
|
||||||
rows: Rc<RefCell<Vec<(gtk::ListBoxRow, &'static str)>>>,
|
rows: Rc<RefCell<Vec<(gtk::ListBoxRow, &'static str)>>>,
|
||||||
|
row_selected: Box<FnMut(&str)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SettingsPages {
|
impl SettingsPages {
|
||||||
pub fn new() -> Self {
|
pub fn new<F: FnMut(&str) + 'static>(row_selected: F) -> Self {
|
||||||
let content = gtk::Box::new(gtk::Orientation::Horizontal, 5);
|
let content = gtk::Box::new(gtk::Orientation::Horizontal, 5);
|
||||||
let categories = gtk::ListBox::new();
|
let categories = gtk::ListBox::new();
|
||||||
categories.get_style_context().map(|c| c.add_class("view"));
|
categories.get_style_context().map(|c| c.add_class("view"));
|
||||||
@ -233,6 +246,7 @@ impl SettingsPages {
|
|||||||
stack,
|
stack,
|
||||||
content,
|
content,
|
||||||
rows,
|
rows,
|
||||||
|
row_selected: Box::new(row_selected),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user