The Battle for Wesnoth  1.15.2+dev
edit_text.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2018 by Iris Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "gui/auxiliary/field.hpp"
20 #include "gui/widgets/button.hpp"
21 #include "gui/widgets/settings.hpp"
22 #include "gui/widgets/text_box.hpp"
23 
24 #include <boost/algorithm/string/trim.hpp>
25 
26 namespace gui2
27 {
28 namespace dialogs
29 {
30 
31 /*WIKI
32  * @page = GUIWindowDefinitionWML
33  * @order = 2_rename_unit
34  *
35  * == Rename unit ==
36  *
37  * Dialog for renaming units in-game.
38  *
39  * @begin{table}{dialog_widgets}
40  *
41  * name & & text_box & m &
42  * Input field for the unit name. $
43  *
44  * @end{table}
45  */
46 
47 REGISTER_DIALOG(edit_text)
48 
49 edit_text::edit_text(const std::string& title,
50  const std::string& label,
51  std::string& text,
52  bool disallow_empty)
53  : disallow_empty_(disallow_empty)
54 {
55  register_label("title", true, title, true);
56  register_label("label", true, label, true);
57  register_text("text", true, text, true);
58 }
59 
61 {
62  if(disallow_empty_) {
63  text_box& text = find_widget<text_box>(&window, "text", false);
66  }
67 }
68 
70 {
71  text_box& text = find_widget<text_box>(get_window(), "text", false);
72  button& ok_button = find_widget<button>(get_window(), "ok", false);
73 
74  ok_button.set_active(!boost::trim_copy(text.get_value()).empty());
75 }
76 
77 } // namespace dialogs
78 } // namespace gui2
std::string get_value() const
STL namespace.
window * get_window() const
Returns a pointer to the dialog&#39;s window.
Label showing a text.
Definition: label.hpp:32
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
Class for a single line text area.
Definition: text_box.hpp:121
Generic file dialog.
Definition: field-fwd.hpp:22
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:248
This file contains the settings handling of the widget library.
Various uncategorised dialogs.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: edit_text.cpp:60
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:62
Simple push button.
Definition: button.hpp:35
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62