uMenuItemStringWithHistory Class Reference

uMenuItemString extended by a simple history function and tab completion More...

#include <uMenu.h>

Inheritance diagram for uMenuItemStringWithHistory:

Inheritance graph
[legend]
Collaboration diagram for uMenuItemStringWithHistory:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 uMenuItemStringWithHistory (uMenu *M, const tOutput &desc, const tOutput &help, tString &c, int maxLength, history_t &history, int limit, uAutoCompleter *completer=0)
 Consructor.
 ~uMenuItemStringWithHistory ()
 Destructor.
virtual bool Event (SDL_Event &e)
 Handles an event.
virtual void Render (REAL x, REAL y, REAL alpha=1, bool selected=0)
 Renders the search suggestion if needed and calls uMenuItemString::Render().

Protected Attributes

history_tm_History
 The saved history lines.
unsigned int m_HistoryPos
 The current position within the history.
unsigned int m_HistoryLimit
 The maximal length of the history.
uAutoCompleterm_Completer
 The object used for completion.
bool m_Searchmode
 Are we in search mode?
bool m_SearchFailing
 Is the seach turning up any useful results?

Classes

class  history_t
 handles loading and saving the contents of the history to a file More...


Detailed Description

uMenuItemString extended by a simple history function and tab completion

Definition at line 436 of file uMenu.h.


Constructor & Destructor Documentation

uMenuItemStringWithHistory::uMenuItemStringWithHistory ( uMenu M,
const tOutput desc,
const tOutput help,
tString c,
int  maxLength,
history_t history,
int  limit,
uAutoCompleter completer = 0 
)

Consructor.

Parameters:
M passed on to uMenuItemString
desc passed on to uMenuItemString
help passed on to uMenuItemString
c passed on to uMenuItemString
maxLength passed on to uMenuItemString
history a reference to the history of commands
limit the limit for the history's size
completer the autocompleter to be used, if 0, no completion will take place

Definition at line 1069 of file uMenu.cpp.

01071                                                                                                                                                                                             :
01072         uMenuItemString(M, desc,help,c, maxLength ),
01073         m_History(history),
01074         m_HistoryPos(0),
01075         m_HistoryLimit(limit),
01076         m_Completer(completer),
01077 m_Searchmode(false) {
    m_History.push_front(tString());

uMenuItemStringWithHistory::~uMenuItemStringWithHistory (  ) 

Destructor.

This destructor will write the currently displayed string into the history if it isn't already in it.

Definition at line 1080 of file uMenu.cpp.

References uMenuItemString::content, tString::Len(), m_History, and m_HistoryLimit.

01082                                                         {
01083     if(content->Len() > 1){
01084         for(history_t::iterator i=m_History.begin(); i!=m_History.end(); ++i) {
01085             if(*i == *content) {
01086                 m_History.erase(i);
01087                 break;
01088             }
01089         }
01090         m_History.front() = *content;
01091     } else {
01092         m_History.pop_front();
01093     }
01094     if(m_History.size() > m_HistoryLimit)

Here is the call graph for this function:


Member Function Documentation

bool uMenuItemStringWithHistory::Event ( SDL_Event &  e  )  [virtual]

Handles an event.

Parameters:
e the event to process
Returns:
true if the event was handled, false if it wasn't

Reimplemented from uMenuItemString.

Reimplemented in eMenuItemChat, and gMemuItemConsole.

Definition at line 1098 of file uMenu.cpp.

Referenced by gMemuItemConsole::Event().

01100                                                   {
01101 #ifndef DEDICATED
01102     if (e.type==SDL_KEYDOWN &&
01103             (e.key.keysym.sym==SDLK_UP && !m_Searchmode )){
01104         if (m_History.size() - 1 > m_HistoryPos)
01105         {
01106             if(m_HistoryPos == 0)  //the new entry... save it before overwriting it
01107                 m_History.front() = *content;
01108             m_HistoryPos++;
01109             *content = m_History[m_HistoryPos];
01110             cursorPos = content->Len() - 1;
01111         }
01112 
01113         return true;
01114     }
01115     else if (e.type==SDL_KEYDOWN &&
01116              (e.key.keysym.sym==SDLK_DOWN && !m_Searchmode)){
01117         if (m_HistoryPos > 0)
01118         {
01119             m_HistoryPos--;
01120             *content = m_History[m_HistoryPos];
01121             cursorPos = content->Len() - 1;
01122         }
01123 
01124         return true;
01125     }
01126     else if (e.type==SDL_KEYDOWN && e.key.keysym.mod & KMOD_CTRL && e.key.keysym.sym == SDLK_r ) {
01127         m_Searchmode = true;
01128         if(m_HistoryPos == 0 && !content->empty()) {  //the new entry... save it before overwriting it
01129             m_History.front() = *content;
01130             m_History.push_front(tString());
01131         }
01132         content->erase();
01133         m_HistoryPos++;
01134         cursorPos=0;
01135         m_SearchFailing=false;
01136         return true;
01137     }
01138     else if (e.type==SDL_KEYDOWN &&
01139              (e.key.keysym.sym==SDLK_TAB && !m_Searchmode)){
01140         if(m_Completer != 0) {
01141             cursorPos = m_Completer->Complete(*content, cursorPos);
01142         }
01143 
01144         return true;
01145     }
01146     else if (e.type==SDL_KEYDOWN && m_Searchmode) {
01147         if(e.key.keysym.sym==SDLK_LEFT || e.key.keysym.sym==SDLK_RIGHT) {
01148             *content = m_History[m_HistoryPos];
01149             m_Searchmode = false;
01150             cursorPos=0;
01151             return true;
01152         }
01153         bool ret = uMenuItemString::Event(e);
01154         tString searchstring = content->ToLower();
01155         unsigned int pos = 0;
01156         for(history_t::iterator iter = m_History.begin(); iter != m_History.end(); ++iter, ++pos) {
01157             if (iter->ToLower().find(searchstring) != tString::npos) {
01158                 m_HistoryPos = pos;
01159                 m_SearchFailing=false;
01160                 return ret;
01161             }
01162         }
01163         m_SearchFailing=true;
01164         return ret;
01165     }
01166 
01167     else
01168         return uMenuItemString::Event(e);
01169 #endif

Here is the caller graph for this function:

void uMenuItemStringWithHistory::Render ( REAL  x,
REAL  y,
REAL  alpha = 1,
bool  selected = 0 
) [virtual]

Renders the search suggestion if needed and calls uMenuItemString::Render().

Reimplemented from uMenuItemString.

Definition at line 1171 of file uMenu.cpp.

01173                                                                               {
01174     if(m_Searchmode) {
01175         DisplayText(-.88, y-.1, ((m_SearchFailing ? "Failing reverse search: " : "Reverse search: ") + m_History[m_HistoryPos]).c_str(), selected, alpha, -1);
01176     }


Member Data Documentation

history_t& uMenuItemStringWithHistory::m_History [protected]

The saved history lines.

Definition at line 446 of file uMenu.h.

Referenced by ~uMenuItemStringWithHistory().

unsigned int uMenuItemStringWithHistory::m_HistoryPos [protected]

The current position within the history.

Definition at line 447 of file uMenu.h.

unsigned int uMenuItemStringWithHistory::m_HistoryLimit [protected]

The maximal length of the history.

Definition at line 448 of file uMenu.h.

Referenced by ~uMenuItemStringWithHistory().

uAutoCompleter* uMenuItemStringWithHistory::m_Completer [protected]

The object used for completion.

Definition at line 449 of file uMenu.h.

bool uMenuItemStringWithHistory::m_Searchmode [protected]

Are we in search mode?

Definition at line 450 of file uMenu.h.

bool uMenuItemStringWithHistory::m_SearchFailing [protected]

Is the seach turning up any useful results?

Definition at line 451 of file uMenu.h.


The documentation for this class was generated from the following files:
Generated on Sun Mar 16 00:01:19 2008 for Armagetron Advanced by  doxygen 1.5.4