Remember Console history

This commit is contained in:
Simon Robertshaw 2012-08-21 17:58:45 +01:00
parent fb6f36907f
commit b7328e03ac
2 changed files with 17 additions and 2 deletions

View File

@ -19,6 +19,11 @@ public:
std::string Command;
int ReturnStatus;
std::string ReturnValue;
operator std::string() const
{
return Command;
}
};

View File

@ -5,15 +5,25 @@
* Author: Simon
*/
#include "client/Client.h"
#include "ConsoleModel.h"
ConsoleModel::ConsoleModel() {
std::vector<std::string> previousHistory = Client::Ref().GetPrefStringArray("Console.History");
for(std::vector<std::string>::reverse_iterator iter = previousHistory.rbegin(), end = previousHistory.rend(); iter != end; ++iter)
{
if(previousCommands.size()<25)
{
previousCommands.push_front(ConsoleCommand(*iter, 0, ""));
currentCommandIndex = previousCommands.size();
}
}
}
void ConsoleModel::AddObserver(ConsoleView * observer)
{
observers.push_back(observer);
observer->NotifyPreviousCommandsChanged(this);
}
int ConsoleModel::GetCurrentCommandIndex()
@ -67,6 +77,6 @@ void ConsoleModel::notifyCurrentCommandChanged()
}
ConsoleModel::~ConsoleModel() {
Client::Ref().SetPref("Console.History", std::vector<std::string>(previousCommands.begin(), previousCommands.end()));
}