ocarina/gui/collection_mgr.cpp

75 lines
1.6 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_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)
{
//c_chooser->set_current_folder(colmgr :: get_path(path));
colmgr :: update_path(path);
enable_idle();
}
static void on_delete()
{
Gtk::TreePath path;
Gtk::TreeViewColumn *col;
c_treeview->get_cursor(path, col);
if (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<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_ok);
connect_button("o_collection_update", on_update);
c_treeview->signal_row_activated().connect(sigc::ptr_fun(on_row_activated));
c_treeview->signal_key_press_event().connect(sigc::ptr_fun(on_key_pressed));
toggle->signal_toggled().connect(sigc::ptr_fun(on_toggled));
colmgr :: init();
}