diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-01 18:45:59 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-01 18:45:59 (GMT) |
| commit | 038da72c61ea6a251d805e2de3662f240da52b02 (patch) | |
| tree | 05170050b16f9d663ec44ae451211e686ba196ac /src/console/ConsoleController.cpp | |
| parent | 857b0cc1fc58f066acd59404d16ee5e566e20f00 (diff) | |
| download | powder-038da72c61ea6a251d805e2de3662f240da52b02.zip powder-038da72c61ea6a251d805e2de3662f240da52b02.tar.gz | |
Console UI, open in browser button, tab and enter shortcut for Login UI, various
Diffstat (limited to 'src/console/ConsoleController.cpp')
| -rw-r--r-- | src/console/ConsoleController.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/console/ConsoleController.cpp b/src/console/ConsoleController.cpp new file mode 100644 index 0000000..cf4cdcd --- /dev/null +++ b/src/console/ConsoleController.cpp @@ -0,0 +1,102 @@ +/* + * ConsoleController.cpp + * + * Created on: Jan 31, 2012 + * Author: Simon + */ + +#include <stack> +#include "ConsoleController.h" + +ConsoleController::ConsoleController(ControllerCallback * callback): + HasDone(false) +{ + consoleModel = new ConsoleModel(); + consoleView = new ConsoleView(); + consoleView->AttachController(this); + consoleModel->AddObserver(consoleView); + + this->callback = callback; +} + +void ConsoleController::EvaluateCommand(std::string command) +{ + if(command.length()) + consoleModel->AddLastCommand(ConsoleCommand(command, -1, "Syntax error")); + else + if(ui::Engine::Ref().GetWindow() == consoleView) + ui::Engine::Ref().CloseWindow(); +} + +std::string ConsoleController::FormatCommand(std::string command) +{ + char * rawText = (char*)command.c_str(); + char * outputData = (char *)calloc(command.length()*6, 1); + int rawTextLoc = 0; + int outputDataLoc = 0; + std::stack<char> pstack; + while(rawText[rawTextLoc]) + { + switch(rawText[rawTextLoc]) + { + case '\\': + outputData[outputDataLoc++] = rawText[rawTextLoc++]; + if(rawText[rawTextLoc]) + outputData[outputDataLoc++] = rawText[rawTextLoc++]; + break; + case '"': + if(pstack.size() && pstack.top() == '"') + { + pstack.pop(); + outputData[outputDataLoc++] = rawText[rawTextLoc++]; + outputData[outputDataLoc++] = '\b'; + outputData[outputDataLoc++] = 'w'; + } + else + { + pstack.push('"'); + outputData[outputDataLoc++] = '\b'; + outputData[outputDataLoc++] = 'o'; + outputData[outputDataLoc++] = rawText[rawTextLoc++]; + } + break; + default: + outputData[outputDataLoc++] = rawText[rawTextLoc++]; + break; + } + } + return outputData; +} + +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() { + // TODO Auto-generated destructor stub +} + |
