117 lines
3.0 KiB
Rust
117 lines
3.0 KiB
Rust
use gtk;
|
|
use gtk::prelude::*;
|
|
use std::rc::Rc;
|
|
use gtk::WidgetExt;
|
|
use libpijul;
|
|
use libpijul::fs_representation::*;
|
|
use std::path::Path;
|
|
use errors::*;
|
|
|
|
|
|
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: (),
|
|
pub window: gtk::Window,
|
|
pub branch_select: gtk::ComboBoxText,
|
|
pub patch_tree: gtk::TreeView,
|
|
}
|
|
|
|
impl Gui {
|
|
pub fn new(builder: gtk::Builder) -> Self {
|
|
return Gui {
|
|
_cant_construct: (),
|
|
window: builder.get_object("main").unwrap(),
|
|
branch_select: builder.get_object("branch_select").unwrap(),
|
|
patch_tree: builder.get_object("patch_tree").unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
pub fn init(appstate: Rc<AppS>) {
|
|
{
|
|
let branches = get_branches("/home/hasufell/git/pijul");
|
|
|
|
for branch in branches.unwrap() {
|
|
appstate.gui.branch_select.append_text(branch.as_str())
|
|
}
|
|
appstate.gui.branch_select.set_active(0);
|
|
}
|
|
|
|
{
|
|
let ls = gtk::ListStore::new(&[gtk::Type::String]);
|
|
let patches = get_patches("/home/hasufell/git/pijul",
|
|
"master");
|
|
for patch in patches.unwrap() {
|
|
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));
|
|
}
|
|
|
|
appstate.gui.window.show_all();
|
|
}
|
|
|
|
|
|
|
|
fn get_branches(path: &str) -> Result<Vec<String>> {
|
|
let mut vec = Vec::new();
|
|
|
|
let repo = libpijul::Repository::open(pristine_dir(path), None).unwrap();
|
|
let txn = repo.txn_begin().unwrap();
|
|
|
|
let branches = txn.iter_branches(None).map(|x| String::from(x.name.as_str()));
|
|
|
|
vec.extend(branches);
|
|
return Ok(vec);
|
|
}
|
|
|
|
|
|
fn get_patches(path: &str, branch: &str) -> Result<Vec<String>> {
|
|
let mut vec = Vec::new();
|
|
|
|
let repo = libpijul::Repository::open(pristine_dir(path), None)?;
|
|
let txn = repo.txn_begin().unwrap();
|
|
|
|
let branch = txn.get_branch(branch).unwrap();
|
|
|
|
let patches_ids = txn.iter_patches(&branch, None).map(|x| x.0);
|
|
for pid in patches_ids {
|
|
let mp = libpijul::fs_representation::read_patch(Path::new(path),
|
|
txn.external_hash(pid));
|
|
match mp {
|
|
Ok(p) => vec.push(p.header().name.clone()),
|
|
Err(e) => warn!("Could not get patch for patch_id {:?}\nError: {:?}", pid, e),
|
|
}
|
|
}
|
|
|
|
return Ok(vec);
|
|
}
|