The Battle for Wesnoth
1.19.7+dev
gui
dialogs
edit_text.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2013 - 2024
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
18
#include "
gui/dialogs/edit_text.hpp
"
19
20
#include "
gui/auxiliary/field.hpp
"
21
#include "
gui/widgets/button.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
:
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
43
void
edit_text::pre_show
()
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
));
48
on_text_change
();
49
}
50
}
51
52
void
edit_text::on_text_change
()
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
gui2::button
Simple push button.
Definition:
button.hpp:36
gui2::button::set_active
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition:
button.cpp:64
gui2::dialogs::edit_text
Definition:
edit_text.hpp:24
gui2::dialogs::edit_text::pre_show
virtual void pre_show() override
Actions to be taken before showing the window.
Definition:
edit_text.cpp:43
gui2::dialogs::edit_text::on_text_change
void on_text_change()
Definition:
edit_text.cpp:52
gui2::dialogs::edit_text::disallow_empty_
bool disallow_empty_
Definition:
edit_text.hpp:57
gui2::dialogs::modal_dialog
Abstract base class for all modal dialogs.
Definition:
modal_dialog.hpp:146
gui2::label
Definition:
label.hpp:32
gui2::text_box_base::get_value
std::string get_value() const
Definition:
text_box_base.hpp:140
gui2::text_box
A widget that allows the user to input text in single line.
Definition:
text_box.hpp:125
edit_text.hpp
field.hpp
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
button.hpp
gui2::dialogs
Definition:
achievements_dialog.cpp:36
gui2::dialogs::REGISTER_DIALOG
REGISTER_DIALOG(editor_edit_unit)
gui2::event::connect_signal_notify_modified
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
Definition:
dispatcher.cpp:203
text_box.hpp
Generated by
1.9.1