The Battle for Wesnoth  1.15.12+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::dialogs
27 {
28 
29 REGISTER_DIALOG(edit_text)
30 
31 edit_text::edit_text(const std::string& title,
32  const std::string& label,
33  std::string& text,
34  bool disallow_empty)
35  : disallow_empty_(disallow_empty)
36 {
37  register_label("title", true, title, true);
38  register_label("label", true, label, true);
39  register_text("text", true, text, true);
40 }
41 
43 {
44  if(disallow_empty_) {
45  text_box& text = find_widget<text_box>(&window, "text", false);
48  }
49 }
50 
52 {
53  text_box& text = find_widget<text_box>(get_window(), "text", false);
54  button& ok_button = find_widget<button>(get_window(), "ok", false);
55 
56  ok_button.set_active(!boost::trim_copy(text.get_value()).empty());
57 }
58 
59 } // namespace dialogs
std::string get_value() const
STL namespace.
window * get_window() const
Returns a pointer to the dialog&#39;s window.
Dialog for renaming units in-game.
Definition: edit_text.hpp:30
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
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:140
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:186
This file contains the settings handling of the widget library.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: edit_text.cpp:42
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:64