diff --git a/gui/wires.cpp b/gui/wires.cpp index d8b0d4f1..f6ca2faf 100644 --- a/gui/wires.cpp +++ b/gui/wires.cpp @@ -11,6 +11,9 @@ static Glib::RefPtr builder; void enable_idle(); +template +void get_object(const std::string &, Glib::RefPtr &); + /* * 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 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 list; - - list = Glib::RefPtr::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 list = Glib::RefPtr::cast_static(builder->get_object("o_collection_dirs")); + Glib::RefPtr 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 +static void get_object(const std::string &name, Glib::RefPtr &obj) +{ + obj = Glib::RefPtr::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 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); diff --git a/tests/gui/gui.cpp b/tests/gui/gui.cpp index 28eeafa6..1a0d731c 100644 --- a/tests/gui/gui.cpp +++ b/tests/gui/gui.cpp @@ -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;