The Battle for Wesnoth
1.17.23+dev
gui
dialogs
edit_text.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2013 - 2023
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/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
:
modal_dialog
(window_id())
37
, disallow_empty_(disallow_empty)
38
{
39
register_label(
"title"
,
true
, title,
true
);
40
register_label(
"label"
,
true
,
label
,
true
);
41
register_text(
"text"
,
true
, text,
true
);
42
}
43
44
void
edit_text::pre_show
(
window
&
window
)
45
{
46
if
(
disallow_empty_
) {
47
text_box
& text = find_widget<text_box>(&
window
,
"text"
,
false
);
48
connect_signal_notify_modified
(text, std::bind(&
edit_text::on_text_change
,
this
));
49
on_text_change
();
50
}
51
}
52
53
void
edit_text::on_text_change
()
54
{
55
text_box
& text = find_widget<text_box>(
get_window
(),
"text"
,
false
);
56
button
& ok_button = find_widget<button>(
get_window
(),
"ok"
,
false
);
57
58
ok_button.
set_active
(!boost::trim_copy(text.
get_value
()).empty());
59
}
60
61
}
// namespace dialogs
gui2::button
Simple push button.
Definition:
button.hpp:37
gui2::button::set_active
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition:
button.cpp:65
gui2::dialogs::edit_text
Dialog for renaming units in-game.
Definition:
edit_text.hpp:32
gui2::dialogs::edit_text::on_text_change
void on_text_change()
Definition:
edit_text.cpp:53
gui2::dialogs::edit_text::disallow_empty_
bool disallow_empty_
Definition:
edit_text.hpp:71
gui2::dialogs::edit_text::pre_show
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition:
edit_text.cpp:44
gui2::dialogs::modal_dialog
Abstract base class for all modal dialogs.
Definition:
modal_dialog.hpp:146
gui2::dialogs::modal_dialog::get_window
window * get_window()
Returns a pointer to the dialog's window.
Definition:
modal_dialog.hpp:177
gui2::label
A label displays text that can be wrapped but no scrollbars are provided.
Definition:
label.hpp:57
gui2::text_box_base::get_value
std::string get_value() const
Definition:
text_box_base.hpp:82
gui2::text_box
Class for a single line text area.
Definition:
text_box.hpp:142
gui2::window
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition:
window.hpp:67
edit_text.hpp
field.hpp
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
button.hpp
REGISTER_DIALOG
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
Definition:
modal_dialog.hpp:89
gui2::dialogs
Definition:
achievements_dialog.cpp:37
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:205
settings.hpp
This file contains the settings handling of the widget library.
text_box.hpp
Generated by
1.9.1