ocarina/gui/collection_mgr.cpp

74 lines
1.7 KiB
C++

/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/callback.h>
#include <core/library.h>
#include <lib/colmgr.h>
#include <gui/ocarina.h>
static Gtk::FileChooserWidget *c_chooser;
static Gtk::TreeView *c_treeview;
static void on_collection_ok()
{
colmgr :: add_path(c_chooser->get_filename());
enable_idle();
}
static void on_collection_update()
{
library :: update_all();
enable_idle();
}
static void on_collection_row_activated(const Gtk::TreePath &path,
Gtk::TreeViewColumn *col)
{
c_chooser->set_current_folder(colmgr :: get_path(path));
}
static void do_collection_delete()
{
Gtk::TreePath path;
Gtk::TreeViewColumn *col;
c_treeview->get_cursor(path, col);
if (path)
colmgr :: del_path(path);
}
static bool on_collection_key_pressed(GdkEventKey *event)
{
std::string key = gdk_keyval_name(event->keyval);
if (key == "Delete") {
do_collection_delete();
return true;
}
return false;
}
static void on_collection_toggled(const Glib::ustring &path)
{
colmgr :: toggle_path_enabled(Gtk::TreePath(path));
}
void collection_mgr_init()
{
Glib::RefPtr<Gtk::CellRendererToggle> toggle;
c_treeview = lib :: get_widget<Gtk::TreeView>("o_collection_treeview");
c_chooser = lib :: get_widget<Gtk::FileChooserWidget>("o_collection_chooser");
toggle = lib :: get_object<Gtk::CellRendererToggle>("o_collection_toggle");
connect_button("o_collection_ok", on_collection_ok);
connect_button("o_collection_update", on_collection_update);
c_treeview->signal_row_activated().connect(sigc::ptr_fun(on_collection_row_activated));
c_treeview->signal_key_press_event().connect(sigc::ptr_fun(on_collection_key_pressed));
toggle->signal_toggled().connect(sigc::ptr_fun(on_collection_toggled));
colmgr :: init();
}