Starting point for plug manager implementation

This commit is contained in:
daa84 2017-10-13 18:27:10 +03:00
parent 42b6bdcd64
commit c5ee1ab586
4 changed files with 85 additions and 17 deletions

View File

@ -28,6 +28,7 @@ mod color;
mod value; mod value;
mod mode; mod mode;
mod ui_model; mod ui_model;
mod plug_manager;
#[macro_use] #[macro_use]
mod ui; mod ui;
mod nvim; mod nvim;

3
src/plug_manager/mod.rs Normal file
View File

@ -0,0 +1,3 @@
mod ui;
pub use self::ui::Ui;

46
src/plug_manager/ui.rs Normal file
View File

@ -0,0 +1,46 @@
use gtk;
use gtk::prelude::*;
pub struct Ui {}
impl Ui {
pub fn new() -> Self {
Ui {}
}
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)],
);
let content = dlg.get_content_area();
let tabs = gtk::Notebook::new();
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));
let plugins = gtk::Box::new(gtk::Orientation::Vertical, 0);
let plugins_lbl = gtk::Label::new("Plugins");
tabs.append_page(&plugins, Some(&plugins_lbl));
tabs.set_tab_pos(gtk::PositionType::Left);
content.add(&tabs);
content.show_all();
match dlg.run() {
OK_ID => {
println!("TODO:");
}
_ => (),
}
dlg.destroy();
}
}

View File

@ -14,6 +14,7 @@ use settings::Settings;
use shell::{Shell, ShellOptions}; use shell::{Shell, ShellOptions};
use shell_dlg; use shell_dlg;
use project::Projects; use project::Projects;
use plug_manager;
pub struct Ui { pub struct Ui {
initialized: bool, initialized: bool,
@ -30,8 +31,8 @@ pub struct Components {
impl Components { impl Components {
fn new() -> Components { fn new() -> Components {
let save_image = Image::new_from_icon_name("document-open", let save_image =
gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32); Image::new_from_icon_name("document-open", gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32);
Components { Components {
open_btn: ToolButton::new(Some(&save_image), "Open"), open_btn: ToolButton::new(Some(&save_image), "Open"),
@ -96,24 +97,41 @@ impl Ui {
let projects = self.projects.clone(); let projects = self.projects.clone();
header_bar.pack_start(&comps.open_btn); header_bar.pack_start(&comps.open_btn);
comps comps.open_btn.connect_clicked(
.open_btn move |_| projects.borrow_mut().show(),
.connect_clicked(move |_| projects.borrow_mut().show()); );
let save_image = Image::new_from_icon_name("document-save", let save_image = Image::new_from_icon_name(
gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32); "document-save",
gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32,
);
let save_btn = ToolButton::new(Some(&save_image), "Save"); let save_btn = ToolButton::new(Some(&save_image), "Save");
let shell = self.shell.clone(); let shell = self.shell.clone();
save_btn.connect_clicked(move |_| shell.borrow_mut().edit_save_all()); save_btn.connect_clicked(move |_| shell.borrow_mut().edit_save_all());
header_bar.pack_start(&save_btn); header_bar.pack_start(&save_btn);
let paste_image = Image::new_from_icon_name("edit-paste", let paste_image = Image::new_from_icon_name(
gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32); "edit-paste",
gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32,
);
let paste_btn = ToolButton::new(Some(&paste_image), "Paste"); let paste_btn = ToolButton::new(Some(&paste_image), "Paste");
let shell = self.shell.clone(); let shell = self.shell.clone();
paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste()); paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste());
header_bar.pack_start(&paste_btn); header_bar.pack_start(&paste_btn);
let plug_image = Image::new_from_icon_name(
"system-software-install",
gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32,
);
let plug_btn = ToolButton::new(Some(&plug_image), "Plug");
let comps_ref = self.comps.clone();
plug_btn.connect_clicked(move |_| {
plug_manager::Ui::new().show(comps_ref.borrow().window.as_ref().unwrap())
});
header_bar.pack_start(&plug_btn);
header_bar.set_show_close_button(true); header_bar.set_show_close_button(true);
window.set_titlebar(Some(&header_bar)); window.set_titlebar(Some(&header_bar));
@ -134,7 +152,7 @@ impl Ui {
shell.grab_focus(); shell.grab_focus();
let comps_ref = self.comps.clone(); let comps_ref = self.comps.clone();
shell.set_detach_cb(Some(move || { shell.set_detach_cb(Some(move || {
let comps_ref = comps_ref.clone(); let comps_ref = comps_ref.clone();
gtk::idle_add(move || { gtk::idle_add(move || {
comps_ref.borrow().close_window(); comps_ref.borrow().close_window();
@ -178,13 +196,13 @@ fn gtk_delete(comps: &UiMutex<Components>, shell: &RefCell<Shell>) -> Inhibit {
} }
Inhibit(if shell_dlg::can_close_window(comps, shell) { Inhibit(if shell_dlg::can_close_window(comps, shell) {
let comps = comps.borrow(); let comps = comps.borrow();
comps.close_window(); comps.close_window();
shell.borrow_mut().detach_ui(); shell.borrow_mut().detach_ui();
false false
} else { } else {
true true
}) })
} }
pub struct UiMutex<T: ?Sized> { pub struct UiMutex<T: ?Sized> {