pigui/src/ui/entry.rs

96 lines
2.8 KiB
Rust
Raw Normal View History

2017-09-13 15:10:51 +00:00
use appstate::*;
use gtk::WidgetExt;
2017-09-12 13:49:26 +00:00
use gtk::prelude::*;
2017-09-13 15:10:51 +00:00
use gtk;
use pijul_glue::branches::*;
use pijul_glue::patches::*;
2017-09-07 15:30:35 +00:00
use std::rc::Rc;
2017-09-13 15:10:51 +00:00
const HASH_COLUMN: i32 = 3;
2017-09-07 15:30:35 +00:00
pub fn init(appstate: Rc<AppS>) {
2017-09-12 13:49:26 +00:00
{
2017-09-12 14:19:55 +00:00
let branches = get_branches("/home/hasufell/git/pijul");
2017-09-12 13:49:26 +00:00
2017-09-12 15:03:31 +00:00
for branch in branches.unwrap() {
appstate.gui.branch_select.append_text(branch.as_str())
2017-09-12 13:49:26 +00:00
}
2017-09-12 15:03:31 +00:00
appstate.gui.branch_select.set_active(0);
2017-09-12 13:49:26 +00:00
}
{
2017-09-13 15:10:51 +00:00
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",
2017-09-12 13:49:26 +00:00
"master");
2017-09-12 15:03:31 +00:00
for patch in patches.unwrap() {
2017-09-13 15:10:51 +00:00
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(),
]);
2017-09-12 13:49:26 +00:00
}
2017-09-13 15:10:51 +00:00
appstate.gui.patch_tree.set_model(Some(&ls));
appstate.gui.patch_tree.set_headers_visible(true);
}
2017-09-12 13:49:26 +00:00
2017-09-13 15:10:51 +00:00
let selection = appstate.gui.patch_tree.get_selection();
selection.set_mode(gtk::SelectionMode::Single);
2017-09-12 13:49:26 +00:00
2017-09-13 15:10:51 +00:00
/* 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());
}
});
2017-09-12 13:49:26 +00:00
}
2017-09-07 15:30:35 +00:00
appstate.gui.window.show_all();
}
2017-09-12 13:49:26 +00:00
2017-09-13 15:10:51 +00:00
fn append_column(title: &str,
v: &mut Vec<gtk::TreeViewColumn>,
tree: &gtk::TreeView,
max_width: Option<i32>) {
2017-09-12 13:49:26 +00:00
2017-09-13 15:10:51 +00:00
let id = v.len() as i32;
2017-09-12 13:49:26 +00:00
2017-09-13 15:10:51 +00:00
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);
2017-09-12 13:49:26 +00:00
2017-09-13 15:10:51 +00:00
tree.append_column(&col);
2017-09-12 13:49:26 +00:00
2017-09-13 15:10:51 +00:00
v.push(col);
2017-09-12 13:49:26 +00:00
}