The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
edit_text.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2013 - 2025
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
23
24#include <boost/algorithm/string/trim.hpp>
25
26namespace gui2::dialogs
27{
28
29REGISTER_DIALOG(edit_text)
30
31edit_text::edit_text(const std::string& title,
32 const std::string& label,
33 std::string& text,
34 bool disallow_empty)
35 : modal_dialog(window_id())
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>("text");
47 connect_signal_notify_modified(text, std::bind(&edit_text::on_text_change, this));
49 }
50}
51
53{
54 text_box& text = find_widget<text_box>("text");
55 button& ok_button = find_widget<button>("ok");
56
57 ok_button.set_active(!boost::trim_copy(text.get_value()).empty());
58}
59
60} // namespace dialogs
Simple push button.
Definition button.hpp:36
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition button.cpp:64
virtual void pre_show() override
Actions to be taken before showing the window.
Definition edit_text.cpp:43
Abstract base class for all modal dialogs.
std::string get_value() const
A widget that allows the user to input text in single line.
Definition text_box.hpp:125
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
STL namespace.