Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5244 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Sep 24, 2005, 8:06:05 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: scrolling back through the Shell's History works

Location:
trunk/src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_input.cc

    r5243 r5244  
    108108
    109109/**
     110 * sets the entire text of the InputLine to text
     111 * @param text the new Text to set as InputLine
     112 */
     113void ShellInput::setInputText(const char* text)
     114{
     115  delete[] this->inputLine;
     116  if (text == NULL)
     117  {
     118    this->inputLine = new char[1];
     119    this->inputLine[0] = '\0';
     120  }
     121  else
     122  {
     123    this->inputLine = new char[strlen(text)+1];
     124    strcpy(this->inputLine, text);
     125  }
     126  this->setText(this->inputLine, true);
     127}
     128
     129
     130/**
    110131 * adds one character to the inputLine
    111132 * @param character the character to add to the inputLine
     
    113134void ShellInput::addCharacter(char character)
    114135{
     136  if (this->historyScrolling)
     137  {
     138    delete[] this->history->lastElement();
     139    this->history->remove(this->history->lastElement());
     140    this->historyScrolling = false;
     141  }
     142
    115143  char* addCharLine = new char[strlen(this->inputLine)+2];
    116144
     
    127155void ShellInput::addCharacters(const char* characters)
    128156{
     157  if (this->historyScrolling)
     158  {
     159    delete[] this->history->lastElement();
     160    this->history->remove(this->history->lastElement());
     161    this->historyScrolling = false;
     162  }
     163
    129164  char* addCharLine = new char[strlen(this->inputLine)+strlen(characters)+1];
    130165
     
    141176void ShellInput::removeCharacters(unsigned int characterCount)
    142177{
     178  if (this->historyScrolling)
     179  {
     180    delete[] this->history->lastElement();
     181    this->history->remove(this->history->lastElement());
     182    this->historyScrolling = false;
     183  }
     184
    143185  if (strlen(this->inputLine) == 0)
    144186    return;
     
    171213  {
    172214    delete[] this->history->lastElement();
     215    this->history->remove(this->history->lastElement());
    173216    this->historyScrolling = false;
    174217  }
     
    197240  if (!this->historyScrolling)
    198241  {
    199     char* newCommand = new char[strlen(this->inputLine)+1];
    200     strcpy(newCommand, this->inputLine);
    201     this->history->add(newCommand);
     242    char* currentText = new char[strlen(this->inputLine)+1];
     243    strcpy(currentText, this->inputLine);
     244    this->history->add(currentText);
    202245    this->historyScrolling = true;
    203246    this->historyIT->lastElement();
     
    210253  {
    211254    this->flush();
    212     this->addCharacters(prevElem);
    213   }
    214 
     255    this->setInputText(prevElem);
     256  }
    215257}
    216258
     
    228270  {
    229271    this->flush();
    230     this->addCharacters(nextElem);
     272    this->setInputText(nextElem);
    231273  }
    232274}
     
    301343    else if (event.type == SDLK_RETURN)
    302344      this->executeCommand();
    303     /*
    304     else if (event.type == SDLK_UP)
    305     {
    306 //      this->flushInputLine();
    307     tIterator<char>* iterator = this->commandList->getIterator();
    308     char* command = iterator->lastElement();
    309     while (command)
    310     {
    311     if (!strcmp (command, inputLine))
    312     {
    313     inputLine = iterator->prevElement();
    314     return;
    315   }
    316     command = iterator->prevElement();
    317   }
    318     inputLine = iterator->lastElement();
    319   }
    320     */
     345    // any other keyboard key
    321346    else if (likely(event.type < 127))
    322347    {
  • trunk/src/lib/shell/shell_input.h

    r5243 r5244  
    3131  // InputLine
    3232  void flush();
     33  void setInputText(const char* text);
    3334  void addCharacter(char character);
    3435  void addCharacters(const char* characters);
  • trunk/src/lib/util/list.h

    r5243 r5244  
    520520}
    521521
    522 
    523522/**
    524523 *  use it to move through the list without interfering with the iteration
     524 * @returns previous list element
     525 *
     526 * this stepping mode will !not! step beyond the boundraries of the List!
    525527 */
    526528template<class T>
     
    540542 *  use it to move backwards through the list without interfering with the itereation
    541543 * @returns next list element
     544 *
     545 * this stepping mode will !not! step beyond the boundraries of the List!
    542546 */
    543547template<class T>
     
    553557}
    554558
     559/**
     560 * @returns the current Element
     561 */
    555562template<class T>
    556563    inline T* tIterator<T>::getCurrent()
Note: See TracChangeset for help on using the changeset viewer.