1 // Copyright (C) 2010, 2014 Ben Asselstine
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17
18 #include <config.h>
19
20 #include <gtkmm.h>
21 #include "use-item-dialog.h"
22 #include "ucompose.hpp"
23 #include "Item.h"
24
UseItemDialog(Gtk::Window & parent,std::list<Item * > items)25 UseItemDialog::UseItemDialog(Gtk::Window &parent, std::list<Item*> items)
26 : LwDialog(parent, "use-item-dialog.ui")
27 {
28 selected_item = 0;
29
30 xml->get_widget("select_button", select_button);
31 xml->get_widget("items_treeview", items_treeview);
32 items_list = Gtk::ListStore::create(items_columns);
33 items_treeview->set_model(items_list);
34 items_treeview->append_column("", items_columns.name);
35 items_treeview->set_headers_visible(false);
36
37 std::list<Item*>::iterator iter = items.begin();
38 for (;iter != items.end(); iter++)
39 addItem(*iter);
40
41 guint32 max = items.size();
42 if (max)
43 {
44 Gtk::TreeModel::Row row;
45 row = items_treeview->get_model()->children()[0];
46 if(row)
47 items_treeview->get_selection()->select(row);
48 }
49 }
50
addItem(Item * item)51 void UseItemDialog::addItem(Item *item)
52 {
53 Gtk::TreeIter i = items_list->append();
54 (*i)[items_columns.name] = item->getName();
55 (*i)[items_columns.attributes] = item->getBonusDescription();
56 (*i)[items_columns.item] = item;
57 }
58
run()59 void UseItemDialog::run()
60 {
61 dialog->show_all();
62 int response = dialog->run();
63
64 if (response != Gtk::RESPONSE_ACCEPT)
65 selected_item = 0;
66 else
67 {
68 Glib::RefPtr<Gtk::TreeSelection> selection =
69 items_treeview->get_selection();
70 Gtk::TreeModel::iterator iterrow = selection->get_selected();
71
72 if (iterrow)
73 {
74 Gtk::TreeModel::Row row = *iterrow;
75 selected_item = row[items_columns.item];
76 }
77 }
78 }
79
80