The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::ttext_history Class Reference

Class for text input history. More...

#include <text_box.hpp>

Public Member Functions

 ttext_history ()
 
void push (const std::string &text)
 Push string into the history. More...
 
std::string up (const std::string &text="")
 One step up in the history. More...
 
std::string down (const std::string &text="")
 One step down in the history. More...
 
std::string get_value () const
 Gets the current history value. More...
 
void set_enabled (bool enabled=true)
 
bool get_enabled () const
 

Static Public Member Functions

static ttext_history get_history (const std::string &id, const bool enabled)
 Gets history that matches id. More...
 

Private Member Functions

 ttext_history (std::vector< std::string > *history, const bool enabled)
 

Private Attributes

std::vector< std::string > * history_
 The items in the history. More...
 
unsigned pos_
 The current position in the history. More...
 
bool enabled_
 Is the history enabled. More...
 

Detailed Description

Class for text input history.

The history of text items can be stored in the preferences. This class handles that. Every item needs an id by which the history is loaded and saved.

Definition at line 32 of file text_box.hpp.

Constructor & Destructor Documentation

gui2::ttext_history::ttext_history ( )
inline

Definition at line 45 of file text_box.hpp.

gui2::ttext_history::ttext_history ( std::vector< std::string > *  history,
const bool  enabled 
)
inlineprivate

Definition at line 102 of file text_box.hpp.

Member Function Documentation

std::string gui2::ttext_history::down ( const std::string text = "")

One step down in the history.

Pushes text to the history if at the end.

Parameters
textThe text to push in the history.
Returns
The current value of the history.

Definition at line 76 of file text_box.cpp.

References enabled_, get_value(), history_, pos_, and push().

Referenced by gui2::ttext_box::history_down().

bool gui2::ttext_history::get_enabled ( ) const
inline

Definition at line 96 of file text_box.hpp.

References enabled_.

Referenced by gui2::ttext_box::history_down(), and gui2::ttext_box::history_up().

ttext_history gui2::ttext_history::get_history ( const std::string id,
const bool  enabled 
)
static

Gets history that matches id.

Parameters
idThe id of the history to look for.
enabledThe enabled state of the history.
Returns
The history object.

Definition at line 38 of file text_box.cpp.

References preferences::get_history().

Referenced by gui2::ttext_box::set_history().

std::string gui2::ttext_history::get_value ( ) const

Gets the current history value.

Returns
If enabled return the current history position, otherwise an empty string is returned.

Definition at line 89 of file text_box.cpp.

References enabled_, history_, and pos_.

Referenced by down(), and up().

void gui2::ttext_history::push ( const std::string text)

Push string into the history.

If the string is empty or the same as the last item in the history this function is a nop.

Parameters
textThe text to push in the history.

Definition at line 45 of file text_box.cpp.

References enabled_, history_, and pos_.

Referenced by down(), gui2::ttext_box::save_to_history(), and up().

void gui2::ttext_history::set_enabled ( bool  enabled = true)
inline

Definition at line 92 of file text_box.hpp.

References enabled_.

std::string gui2::ttext_history::up ( const std::string text = "")

One step up in the history.

Pushes text to the history if at the end.

Parameters
textThe text to push in the history.
Returns
The current value of the history.

Definition at line 58 of file text_box.cpp.

References curr, enabled_, get_value(), history_, pos_, and push().

Referenced by gui2::ttext_box::history_up().

Member Data Documentation

bool gui2::ttext_history::enabled_
private

Is the history enabled.

Definition at line 114 of file text_box.hpp.

Referenced by down(), get_enabled(), get_value(), push(), set_enabled(), and up().

std::vector<std::string>* gui2::ttext_history::history_
private

The items in the history.

Definition at line 108 of file text_box.hpp.

Referenced by down(), get_value(), push(), and up().

unsigned gui2::ttext_history::pos_
private

The current position in the history.

Definition at line 111 of file text_box.hpp.

Referenced by down(), get_value(), push(), and up().


The documentation for this class was generated from the following files: