pigui/src/ui/entry.rs

128 lines
3.2 KiB
Rust
Raw Normal View History

2017-09-07 15:30:35 +00:00
use gtk;
2017-09-12 13:49:26 +00:00
use gtk::prelude::*;
2017-09-07 15:30:35 +00:00
use std::rc::Rc;
use gtk::WidgetExt;
2017-09-12 13:49:26 +00:00
use libpijul;
2017-09-12 14:19:55 +00:00
use libpijul::fs_representation::*;
2017-09-12 13:49:26 +00:00
use std::path::Path;
2017-09-07 15:30:35 +00:00
pub struct AppS {
_cant_construct: (),
pub gui: Gui,
}
impl AppS {
pub fn new() -> Self {
let builder = gtk::Builder::new_from_string(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/data/ui/window.glade")));
return AppS {
_cant_construct: (),
gui: Gui::new(builder),
}
}
}
pub struct Gui {
_cant_construct: (),
2017-09-12 13:49:26 +00:00
pub window: gtk::Window,
pub branch_tree: gtk::TreeView,
pub patch_tree: gtk::TreeView,
2017-09-07 15:30:35 +00:00
}
impl Gui {
pub fn new(builder: gtk::Builder) -> Self {
return Gui {
_cant_construct: (),
window: builder.get_object("main").unwrap(),
2017-09-12 13:49:26 +00:00
branch_tree: builder.get_object("branch_tree").unwrap(),
patch_tree: builder.get_object("patch_tree").unwrap(),
2017-09-07 15:30:35 +00:00
}
}
}
pub fn init(appstate: Rc<AppS>) {
2017-09-12 13:49:26 +00:00
{
let ls = gtk::ListStore::new(&[gtk::Type::String]);
2017-09-12 14:19:55 +00:00
let branches = get_branches("/home/hasufell/git/pijul");
2017-09-12 13:49:26 +00:00
for branch in branches {
ls.insert_with_values(None, &[0], &[&branch.as_str()]);
}
let renderer = gtk::CellRendererText::new();
let col = gtk::TreeViewColumn::new();
col.set_title("Branch");
col.set_resizable(true);
col.pack_start(&renderer, true);
col.add_attribute(&renderer, "text", 0);
col.set_clickable(true);
col.set_sort_column_id(0);
appstate.gui.branch_tree.append_column(&col);
appstate.gui.branch_tree.set_model(Some(&ls));
}
{
let ls = gtk::ListStore::new(&[gtk::Type::String]);
2017-09-12 14:19:55 +00:00
let patches = get_patches("/home/hasufell/git/pijul",
2017-09-12 13:49:26 +00:00
"master");
for patch in patches {
ls.insert_with_values(None, &[0], &[&patch.as_str()]);
}
let renderer = gtk::CellRendererText::new();
let col = gtk::TreeViewColumn::new();
col.set_title("Patch");
col.set_resizable(true);
col.pack_start(&renderer, true);
col.add_attribute(&renderer, "text", 0);
col.set_clickable(true);
col.set_sort_column_id(0);
appstate.gui.patch_tree.append_column(&col);
appstate.gui.patch_tree.set_model(Some(&ls));
}
2017-09-07 15:30:35 +00:00
appstate.gui.window.show_all();
}
2017-09-12 13:49:26 +00:00
fn get_branches(path: &str) -> Vec<String> {
let mut vec = Vec::new();
2017-09-12 14:19:55 +00:00
let repo = libpijul::Repository::open(pristine_dir(path), None).unwrap();
2017-09-12 13:49:26 +00:00
let txn = repo.txn_begin().unwrap();
let branches = txn.iter_branches(None).map(|x| String::from(x.name.as_str()));
vec.extend(branches);
return vec;
}
fn get_patches(path: &str, branch: &str) -> Vec<String> {
let mut vec = Vec::new();
2017-09-12 14:19:55 +00:00
let repo = libpijul::Repository::open(pristine_dir(path), None).unwrap();
2017-09-12 13:49:26 +00:00
let txn = repo.txn_begin().unwrap();
let branch = txn.get_branch(branch).unwrap();
let patches = txn.iter_patches(&branch, None).map(|x| {
2017-09-12 14:19:55 +00:00
let p = libpijul::fs_representation::read_patch(Path::new(path),
2017-09-12 13:49:26 +00:00
txn.external_hash(x.0)).unwrap();
p.header().name.clone()
});
vec.extend(patches);
return vec;
}