diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
| commit | 058a2edd75debbd0297f92572316daa704bd379f (patch) | |
| tree | ad303f091f9a08b209b91eb34a9fcad996a3de69 /src/console/ConsoleController.cpp | |
| parent | e3594aba9e05c6865d396418c028049cda92c2f3 (diff) | |
| parent | 7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff) | |
| download | powder-058a2edd75debbd0297f92572316daa704bd379f.zip powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz | |
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/console/ConsoleController.cpp')
| -rw-r--r-- | src/console/ConsoleController.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/console/ConsoleController.cpp b/src/console/ConsoleController.cpp new file mode 100644 index 0000000..7d61303 --- /dev/null +++ b/src/console/ConsoleController.cpp @@ -0,0 +1,81 @@ +/* + * ConsoleController.cpp + * + * Created on: Jan 31, 2012 + * Author: Simon + */ + +#include <stack> +#include "ConsoleController.h" + +ConsoleController::ConsoleController(ControllerCallback * callback, CommandInterface * commandInterface): + HasDone(false) +{ + consoleModel = new ConsoleModel(); + consoleView = new ConsoleView(); + consoleView->AttachController(this); + consoleModel->AddObserver(consoleView); + + this->callback = callback; + this->commandInterface = commandInterface; +} + +void ConsoleController::EvaluateCommand(std::string command) +{ + if (command.substr(0, 5) == "!load ") + CloseConsole(); + int returnCode = commandInterface->Command(command); + if(command.length()) + consoleModel->AddLastCommand(ConsoleCommand(command, returnCode, commandInterface->GetLastError())); + else + CloseConsole(); +} + +void ConsoleController::CloseConsole() +{ + if(ui::Engine::Ref().GetWindow() == consoleView) + ui::Engine::Ref().CloseWindow(); +} + +std::string ConsoleController::FormatCommand(std::string command) +{ + return commandInterface->FormatCommand(command); +} + +void ConsoleController::NextCommand() +{ + int cIndex = consoleModel->GetCurrentCommandIndex(); + if(cIndex < consoleModel->GetPreviousCommands().size()) + consoleModel->SetCurrentCommandIndex(cIndex+1); +} + +void ConsoleController::PreviousCommand() +{ + int cIndex = consoleModel->GetCurrentCommandIndex(); + if(cIndex > 0) + consoleModel->SetCurrentCommandIndex(cIndex-1); +} + +void ConsoleController::Exit() +{ + if(ui::Engine::Ref().GetWindow() == consoleView) + ui::Engine::Ref().CloseWindow(); + if(callback) + callback->ControllerExit(); + HasDone = true; +} + +ConsoleView * ConsoleController::GetView() +{ + return consoleView; +} + +ConsoleController::~ConsoleController() { + if(ui::Engine::Ref().GetWindow() == consoleView) + ui::Engine::Ref().CloseWindow(); + if(callback) + delete callback; + delete consoleModel; + delete consoleView; +} + |
