ocarina/gui/collection_mgr.cpp
Anna Schumaker a5f47e46a8 colmgr: Move some collection manager code into lib/
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
2014-06-21 12:27:34 -04:00

79 lines
1.9 KiB
C++

/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/callback.h>
#include <core/library.h>
#include <lib/colmgr.h>
#include <gui/ocarina.h>
static void on_collection_ok()
{
Gtk::FileChooserWidget *chooser;
chooser = lib :: get_widget<Gtk::FileChooserWidget>("o_collection_chooser");
colmgr :: add_path(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)
{
Gtk::FileChooser *chooser = lib :: get_widget<Gtk::FileChooser>("o_collection_chooser");
chooser->set_current_folder(colmgr :: get_path(path));
}
#ifndef CONFIG_TEST
static
#endif /* CONFIG_TEST */
void do_collection_delete()
{
Gtk::TreePath path;
Gtk::TreeViewColumn *col;
Gtk::TreeView *treeview = lib :: get_widget<Gtk::TreeView>("o_collection_treeview");
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;
}
#ifndef CONFIG_TEST
static
#endif /* CONFIG_TEST */
void on_collection_toggled(const Glib::ustring &path)
{
colmgr :: toggle_path_enabled(Gtk::TreePath(path));
}
void collection_mgr_init()
{
Gtk::TreeView *treeview = lib :: get_widget<Gtk::TreeView>("o_collection_treeview");
Glib::RefPtr<Gtk::CellRendererToggle> toggle;
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);
treeview->signal_row_activated().connect(sigc::ptr_fun(on_collection_row_activated));
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();
}