The Battle for Wesnoth  1.17.0-dev
edit_text.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2021
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
20 #include "gui/auxiliary/field.hpp"
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/settings.hpp"
23 #include "gui/widgets/text_box.hpp"
24 
25 #include <boost/algorithm/string/trim.hpp>
26 
27 namespace gui2::dialogs
28 {
29 
30 REGISTER_DIALOG(edit_text)
31 
32 edit_text::edit_text(const std::string& title,
33  const std::string& label,
34  std::string& text,
35  bool disallow_empty)
36  : disallow_empty_(disallow_empty)
37 {
38  register_label("title", true, title, true);
39  register_label("label", true, label, true);
40  register_text("text", true, text, true);
41 }
42 
44 {
45  if(disallow_empty_) {
46  text_box& text = find_widget<text_box>(&window, "text", false);
49  }
50 }
51 
53 {
54  text_box& text = find_widget<text_box>(get_window(), "text", false);
55  button& ok_button = find_widget<button>(get_window(), "ok", false);
56 
57  ok_button.set_active(!boost::trim_copy(text.get_value()).empty());
58 }
59 
60 } // 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:31
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:57
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:141
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:187
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:43
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: button.cpp:63
Simple push button.
Definition: button.hpp:36
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65