gui: Change directory on row double click
This allows a user to explore what has been added in each of their library paths. Right now I filter for directories only, but it may be a good idea to change this in the future. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
31af8482de
commit
a077b8cbad
|
@ -11,6 +11,9 @@
|
|||
static Glib::RefPtr<Gtk::Builder> builder;
|
||||
void enable_idle();
|
||||
|
||||
template <class T>
|
||||
void get_object(const std::string &, Glib::RefPtr<T> &);
|
||||
|
||||
|
||||
/*
|
||||
* Collection manager functions
|
||||
|
@ -50,12 +53,26 @@ static void on_collection_import()
|
|||
enable_idle();
|
||||
}
|
||||
|
||||
static void on_collection_row_activated(const Gtk::TreePath &path,
|
||||
Gtk::TreeViewColumn *col)
|
||||
{
|
||||
Gtk::FileChooser *chooser;
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
|
||||
get_object("o_collection_dirs", list);
|
||||
builder->get_widget("o_collection_chooser", chooser);
|
||||
|
||||
Gtk::TreeModel::Row row = *(list->get_iter(path));
|
||||
Glib::ustring dir = row[collection_cols.c_col_path];
|
||||
|
||||
chooser->set_current_folder(dir);
|
||||
}
|
||||
|
||||
static void on_library_add(unsigned int id, library :: Library *path)
|
||||
{
|
||||
Gtk::TreeModel::Row row;
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
|
||||
list = Glib::RefPtr<Gtk::ListStore>::cast_static(builder->get_object("o_collection_dirs"));
|
||||
get_object("o_collection_dirs", list);
|
||||
|
||||
row = *(list->append());
|
||||
row[collection_cols.c_col_id] = id;
|
||||
|
@ -67,7 +84,8 @@ static void on_library_add(unsigned int id, library :: Library *path)
|
|||
static void on_library_update(unsigned int id, library :: Library *path)
|
||||
{
|
||||
Gtk::TreeModel::Row row;
|
||||
Glib::RefPtr<Gtk::ListStore> list = Glib::RefPtr<Gtk::ListStore>::cast_static(builder->get_object("o_collection_dirs"));
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
get_object("o_collection_dirs", list);
|
||||
Gtk::TreeModel::Children children = list->children();
|
||||
|
||||
for (Gtk::TreeModel::Children::iterator it = children.begin();
|
||||
|
@ -119,6 +137,12 @@ Gtk::Button *get_button(const std::string &name)
|
|||
return button;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void get_object(const std::string &name, Glib::RefPtr<T> &obj)
|
||||
{
|
||||
obj = Glib::RefPtr<T>::cast_static(builder->get_object(name));
|
||||
}
|
||||
|
||||
static void connect_button(const std::string &name, void (*func)())
|
||||
{
|
||||
get_button(name)->signal_clicked().connect(sigc::ptr_fun(func));
|
||||
|
@ -128,6 +152,8 @@ Gtk::Window *connect_wires()
|
|||
{
|
||||
Gtk::Window *window;
|
||||
struct Callbacks *cb = get_callbacks();
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
Gtk::TreeView *treeview;
|
||||
|
||||
builder = Gtk::Builder::create();
|
||||
builder->add_from_file("gui/ocarina6.glade");
|
||||
|
@ -136,6 +162,12 @@ Gtk::Window *connect_wires()
|
|||
/* Collection manager */
|
||||
cb->on_library_add = on_library_add;
|
||||
cb->on_library_update = on_library_update;
|
||||
get_object("o_collection_dirs", list);
|
||||
list->set_sort_column(collection_cols.c_col_path, Gtk::SORT_ASCENDING);
|
||||
|
||||
builder->get_widget("o_collection_treeview", treeview);
|
||||
treeview->signal_row_activated().connect(sigc::ptr_fun(on_collection_row_activated));
|
||||
|
||||
connect_button("o_collection_ok", on_collection_ok);
|
||||
connect_button("o_collection_update", on_collection_update);
|
||||
connect_button("o_collection_import", on_collection_import);
|
||||
|
|
|
@ -24,6 +24,15 @@ void click_button(const std::string &name)
|
|||
get_button(name)->clicked();
|
||||
}
|
||||
|
||||
void activate_treeview_row(const std::string &tv_name, const std::string &path)
|
||||
{
|
||||
Gtk::TreeView *treeview;
|
||||
Gtk::TreeViewColumn col("2");
|
||||
get_builder()->get_widget("o_collection_treeview", treeview);
|
||||
treeview->set_cursor(Gtk::TreePath(path));
|
||||
treeview->row_activated(Gtk::TreePath(path), col);
|
||||
}
|
||||
|
||||
/* Collection manager tests */
|
||||
bool test_0()
|
||||
{
|
||||
|
@ -51,6 +60,15 @@ bool test_0()
|
|||
case 5:
|
||||
click_button("o_collection_update");
|
||||
break;
|
||||
case 7:
|
||||
activate_treeview_row("o_collection_treeview", "0");
|
||||
break;
|
||||
case 8:
|
||||
activate_treeview_row("o_collection_treeview", "1");
|
||||
break;
|
||||
case 9:
|
||||
activate_treeview_row("o_collection_treeview", "2");
|
||||
break;
|
||||
default:
|
||||
end_test();
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue