From b7328e03acc683839ee84f3ea3eb12c9dfa8d8f1 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 21 Aug 2012 17:58:45 +0100 Subject: [PATCH] Remember Console history --- src/console/ConsoleCommand.h | 5 +++++ src/console/ConsoleModel.cpp | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/console/ConsoleCommand.h b/src/console/ConsoleCommand.h index f6f91a3ea..a40a68832 100644 --- a/src/console/ConsoleCommand.h +++ b/src/console/ConsoleCommand.h @@ -19,6 +19,11 @@ public: std::string Command; int ReturnStatus; std::string ReturnValue; + + operator std::string() const + { + return Command; + } }; diff --git a/src/console/ConsoleModel.cpp b/src/console/ConsoleModel.cpp index fcbee8033..df900a3ba 100644 --- a/src/console/ConsoleModel.cpp +++ b/src/console/ConsoleModel.cpp @@ -5,15 +5,25 @@ * Author: Simon */ +#include "client/Client.h" #include "ConsoleModel.h" ConsoleModel::ConsoleModel() { - + std::vector previousHistory = Client::Ref().GetPrefStringArray("Console.History"); + for(std::vector::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(previousCommands.begin(), previousCommands.end())); }