Debian Codegraph @

plugins/dm.objectives/util/TwoColumnTextCombo.h

raw
1 #ifndef TWOCOLUMNTEXTCOMBO_H_
2 #define TWOCOLUMNTEXTCOMBO_H_
3
4 #include <gtkmm/combobox.h>
5 #include <gtkmm/liststore.h>
6
7 namespace objectives
8 {
9
10 namespace util
11 {
12
13 /**
14 * \namespace objectives::util
15 * Helper classes for the Objectives Editor plugin.
16 *
17 * \ingroup objectives
18 */
19
20 /**
21 * Helper class to create a Gtk::ComboBox containing two text columns.
22 *
23 * This class provides a convenient mechanism to create a Gtk::ComboBox backed
24 * by a Gtk::ListStore containing two text columns. The first text column (column
25 * 0) contains a text string which will be displayed in the Gtk::ComboBox itself,
26 * whereas the second (column 1) contains a string which will not be displayed
27 * and is intended for use as a code-level identifier which is not visible to
28 * the user.
29 */
30 class TwoColumnTextCombo :
31 public Gtk::ComboBox
32 {
33 private:
34 struct ListColumns :
35 public Gtk::TreeModel::ColumnRecord
36 {
37 ListColumns() { add(first); add(second); }
38
39 Gtk::TreeModelColumn<Glib::ustring> first;
40 Gtk::TreeModelColumn<Glib::ustring> second;
41 };
42
43 public:
44 /**
45 * Construct a TwoColumnTextCombo.
46 */
47 TwoColumnTextCombo() :
48 Gtk::ComboBox()
49 {
50 // List store and combo box
51 ListColumns columns;
52 Glib::RefPtr<Gtk::ListStore> ls = Gtk::ListStore::create(columns);
53
54 set_model(ls);
55
56 // Add a text cell renderer for column 0
57 Gtk::CellRendererText* rend = Gtk::manage(new Gtk::CellRendererText);
58
59 pack_start(*rend, false);
60 add_attribute(rend->property_text(), columns.first);
61 }
62 };
63
64 }
65
66 }
67
68 #endif /*TWOCOLUMNTEXTCOMBO_H_*/