1 // Copyright (C) 2007 Ole Laursen
2 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <sigc++/functors/mem_fun.h>
24 #include "signpost-editor-dialog.h"
26 #include "glade-helpers.h"
27 #include "ucompose.hpp"
29 #include "CreateScenarioRandomize.h"
32 SignpostEditorDialog::SignpostEditorDialog(Signpost *s, CreateScenarioRandomize *randomizer)
34 d_randomizer = randomizer;
37 Glib::RefPtr<Gtk::Builder> xml
38 = Gtk::Builder::create_from_file(get_glade_path()
39 + "/signpost-editor-dialog.ui");
41 xml->get_widget("dialog", dialog);
43 xml->get_widget("sign_textview", sign_textview);
44 sign_textview->get_buffer()->set_text(s->getName());
46 xml->get_widget("randomize_button", randomize_button);
47 randomize_button->signal_clicked().connect(
48 sigc::mem_fun(this, &SignpostEditorDialog::on_randomize_clicked));
51 SignpostEditorDialog::~SignpostEditorDialog()
55 void SignpostEditorDialog::set_parent_window(Gtk::Window &parent)
57 dialog->set_transient_for(parent);
58 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
61 int SignpostEditorDialog::run()
64 int response = dialog->run();
66 if (response == Gtk::RESPONSE_ACCEPT) // accepted
67 signpost->setName(sign_textview->get_buffer()->get_text());
70 if (sign_textview->get_buffer()->get_text() != DEFAULT_SIGNPOST)
71 d_randomizer->pushRandomSignpost
72 (sign_textview->get_buffer()->get_text());
77 void SignpostEditorDialog::on_randomize_clicked()
79 std::string existing_name = sign_textview->get_buffer()->get_text();
80 bool dynamic = ((rand() % d_randomizer->getNumSignposts()) == 0);
81 if (existing_name == DEFAULT_SIGNPOST)
84 sign_textview->get_buffer()->set_text
85 (d_randomizer->getDynamicSignpost(signpost));
87 sign_textview->get_buffer()->set_text
88 (d_randomizer->popRandomSignpost());
93 sign_textview->get_buffer()->set_text
94 (d_randomizer->getDynamicSignpost(signpost));
97 sign_textview->get_buffer()->set_text
98 (d_randomizer->popRandomSignpost());
99 d_randomizer->pushRandomSignpost(existing_name);