96 lines
2.8 KiB
Rust
96 lines
2.8 KiB
Rust
use appstate::*;
|
|
use gtk::WidgetExt;
|
|
use gtk::prelude::*;
|
|
use gtk;
|
|
use pijul_glue::branches::*;
|
|
use pijul_glue::patches::*;
|
|
use std::rc::Rc;
|
|
|
|
|
|
const HASH_COLUMN: i32 = 3;
|
|
|
|
|
|
|
|
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 mut columns: Vec<gtk::TreeViewColumn> = Vec::new();
|
|
append_column("Patch", &mut columns, &appstate.gui.patch_tree, Some(200));
|
|
append_column("Authors", &mut columns, &appstate.gui.patch_tree, None);
|
|
append_column("Date", &mut columns, &appstate.gui.patch_tree, None);
|
|
|
|
let ls = gtk::ListStore::new(&[
|
|
// visible
|
|
gtk::Type::String, // name
|
|
gtk::Type::String, // authors
|
|
gtk::Type::String, // creation date
|
|
// not visible
|
|
gtk::Type::String, // hash
|
|
]);
|
|
let patches = get_patch_headers("/home/hasufell/git/pijul",
|
|
"master");
|
|
for patch in patches.unwrap() {
|
|
ls.insert_with_values(None, &[0, 1, 2, 3],
|
|
&[&patch.name.as_str(),
|
|
&patch.authors.as_str(),
|
|
&patch.created.as_str(),
|
|
&patch.hash_to_str(),
|
|
]);
|
|
}
|
|
appstate.gui.patch_tree.set_model(Some(&ls));
|
|
appstate.gui.patch_tree.set_headers_visible(true);
|
|
}
|
|
|
|
let selection = appstate.gui.patch_tree.get_selection();
|
|
selection.set_mode(gtk::SelectionMode::Single);
|
|
|
|
/* connect selection change */
|
|
{
|
|
let apps = appstate.clone();
|
|
selection.connect_changed(move |ts| {
|
|
if let Some((model, iter)) = ts.get_selected() {
|
|
let val = model.get_value(&iter, HASH_COLUMN);
|
|
let s: String = val.downcast().unwrap().get().unwrap();
|
|
apps.gui.hash_entry.set_text(s.as_ref());
|
|
}
|
|
});
|
|
}
|
|
|
|
appstate.gui.window.show_all();
|
|
}
|
|
|
|
|
|
fn append_column(title: &str,
|
|
v: &mut Vec<gtk::TreeViewColumn>,
|
|
tree: >k::TreeView,
|
|
max_width: Option<i32>) {
|
|
|
|
let id = v.len() as i32;
|
|
|
|
let renderer = gtk::CellRendererText::new();
|
|
let col = gtk::TreeViewColumn::new();
|
|
col.set_title(title);
|
|
col.set_resizable(true);
|
|
col.set_sort_column_id(id);
|
|
if let Some(max_width) = max_width {
|
|
col.set_max_width(max_width);
|
|
col.set_expand(true);
|
|
}
|
|
col.pack_start(&renderer, true);
|
|
col.add_attribute(&renderer, "text", id);
|
|
col.set_clickable(true);
|
|
|
|
tree.append_column(&col);
|
|
|
|
v.push(col);
|
|
}
|
|
|