The Battle for Wesnoth  1.15.9+dev
edit_text.hpp
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 #pragma once
16 
18 
19 namespace gui2
20 {
21 namespace dialogs
22 {
23 
24 /**
25  * @ingroup GUIWindowDefinitionWML
26  *
27  * Dialog for renaming units in-game.
28  * Key |Type |Mandatory|Description
29  * ------------------|--------------|---------|-----------
30  * name | text_box |yes |Input field for the unit name.
31  */
32 class edit_text : public modal_dialog
33 {
34 public:
35  /**
36  * Constructor.
37  *
38  * @param title The dialog's title.
39  * @param label Label of the text field.
40  * @param [in, out] text The parameter's usage is:
41  * - Input: The initial value of the text field.
42  * - Output: The new unit name the user entered
43  * if the dialog returns retval::OK,
44  * undefined otherwise.
45  * @param disallow_empty Whether to prevent the user from entering a string that is
46  * empty or consists only of whitespace.
47  */
48  edit_text(const std::string& title,
49  const std::string& label,
50  std::string& text,
51  bool disallow_empty = false);
52 
53  /**
54  * Executes the dialog.
55  * See @ref modal_dialog for more information.
56  *
57  * @param [in, out] text The parameter's usage is:
58  * - Input: The initial value of the unit name.
59  * - Output: The new unit name the user entered
60  * if this method returns @a true, undefined
61  * otherwise.
62  */
64 
65 private:
66  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
67  virtual const std::string& window_id() const override;
68 
69  virtual void pre_show(window& window) override;
70 
71  void on_text_change();
72 
74 };
75 } // namespace dialogs
76 } // namespace gui2
virtual const std::string & window_id() const override
Executes the dialog.
Dialog for renaming units in-game.
Definition: edit_text.hpp:32
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
Generic file dialog.
Definition: field-fwd.hpp:22
edit_text(const std::string &title, const std::string &label, std::string &text, bool disallow_empty=false)
Constructor.
Definition: edit_text.cpp:33
Various uncategorised dialogs.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: edit_text.cpp:44
Abstract base class for all modal dialogs.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64