The Battle for Wesnoth  1.19.5+dev
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::text_history Class Reference

Class for text input history. More...

#include <text_box.hpp>

Public Member Functions

 text_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 text_history get_history (const std::string &id, const bool enabled)
 Gets history that matches id. More...
 

Private Member Functions

 text_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 36 of file text_box.hpp.

Constructor & Destructor Documentation

◆ text_history() [1/2]

gui2::text_history::text_history ( )
inline

Definition at line 49 of file text_box.hpp.

◆ text_history() [2/2]

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

Definition at line 106 of file text_box.hpp.

Member Function Documentation

◆ down()

std::string gui2::text_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 78 of file text_box.cpp.

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

Referenced by gui2::multiline_text::history_down(), and gui2::text_box::history_down().

◆ get_enabled()

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

◆ get_history()

text_history gui2::text_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 40 of file text_box.cpp.

References prefs::get(), and prefs::get_history().

Referenced by gui2::multiline_text::set_history(), and gui2::text_box::set_history().

◆ get_value()

std::string gui2::text_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 91 of file text_box.cpp.

References enabled_, history_, and pos_.

Referenced by down(), and up().

◆ push()

void gui2::text_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 47 of file text_box.cpp.

References enabled_, history_, and pos_.

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

◆ set_enabled()

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

Definition at line 96 of file text_box.hpp.

References enabled_.

◆ up()

std::string gui2::text_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 60 of file text_box.cpp.

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

Referenced by gui2::multiline_text::history_up(), and gui2::text_box::history_up().

Member Data Documentation

◆ enabled_

bool gui2::text_history::enabled_
private

Is the history enabled.

Definition at line 118 of file text_box.hpp.

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

◆ history_

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

The items in the history.

Definition at line 112 of file text_box.hpp.

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

◆ pos_

unsigned gui2::text_history::pos_
private

The current position in the history.

Definition at line 115 of file text_box.hpp.

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


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