/* * Copyright 2014 (c) Anna Schumaker. */ #include #include #include #include static Gtk::FileChooserWidget *c_chooser; static Gtk::TreeView *c_treeview; static void cd_chooser(const std::string &dir) { if (c_chooser->get_current_folder() != dir) c_chooser->set_current_folder(dir); } static bool find_cur_path(Gtk::TreePath &path) { Gtk::TreeViewColumn *col; c_treeview->get_cursor(path, col); return !path.empty(); } static void on_ok() { colmgr :: add_path(c_chooser->get_filename()); enable_idle(); } static void on_update() { library :: update_all(); enable_idle(); } static void on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col) { colmgr :: update_path(path); enable_idle(); } static void on_cursor_changed() { Gtk::TreePath path; if (find_cur_path(path)) cd_chooser(colmgr :: get_path(path)); } static void on_delete() { Gtk::TreePath path; if (find_cur_path(path)) colmgr :: del_path(path); } static bool on_key_pressed(GdkEventKey *event) { std::string key = gdk_keyval_name(event->keyval); if (key == "Delete") { on_delete(); return true; } return false; } static void on_toggled(const Glib::ustring &path) { colmgr :: toggle_path_enabled(Gtk::TreePath(path)); } void collection_mgr_init() { Glib::RefPtr toggle; c_treeview = lib :: get_widget("colmgr_treeview"); c_chooser = lib :: get_widget("colmgr_chooser"); toggle = lib :: get_object("colmgr_toggle"); connect_button("colmgr_add", on_ok); connect_button("colmgr_update", on_update); c_treeview->signal_row_activated().connect(sigc::ptr_fun(on_row_activated)); c_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_cursor_changed)); c_treeview->signal_key_press_event().connect(sigc::ptr_fun(on_key_pressed)); toggle->signal_toggled().connect(sigc::ptr_fun(on_toggled)); colmgr :: init(); }