summaryrefslogtreecommitdiff
path: root/src/console/ConsoleModel.cpp
diff options
context:
space:
mode:
authorSimon 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)
commit038da72c61ea6a251d805e2de3662f240da52b02 (patch)
tree05170050b16f9d663ec44ae451211e686ba196ac /src/console/ConsoleModel.cpp
parent857b0cc1fc58f066acd59404d16ee5e566e20f00 (diff)
downloadpowder-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/ConsoleModel.cpp')
-rw-r--r--src/console/ConsoleModel.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/console/ConsoleModel.cpp b/src/console/ConsoleModel.cpp
new file mode 100644
index 0000000..fcbee80
--- /dev/null
+++ b/src/console/ConsoleModel.cpp
@@ -0,0 +1,72 @@
+/*
+ * ConsoleModel.cpp
+ *
+ * Created on: Feb 1, 2012
+ * Author: Simon
+ */
+
+#include "ConsoleModel.h"
+
+ConsoleModel::ConsoleModel() {
+
+}
+
+void ConsoleModel::AddObserver(ConsoleView * observer)
+{
+ observers.push_back(observer);
+}
+
+int ConsoleModel::GetCurrentCommandIndex()
+{
+ return currentCommandIndex;
+}
+
+void ConsoleModel::SetCurrentCommandIndex(int index)
+{
+ currentCommandIndex = index;
+ notifyCurrentCommandChanged();
+}
+
+ConsoleCommand ConsoleModel::GetCurrentCommand()
+{
+ if(currentCommandIndex < 0 || currentCommandIndex >= previousCommands.size())
+ {
+ return ConsoleCommand("", 0, "");
+ }
+ return previousCommands[currentCommandIndex];
+}
+
+void ConsoleModel::AddLastCommand(ConsoleCommand command)
+{
+ previousCommands.push_back(command);
+ if(previousCommands.size()>25)
+ previousCommands.pop_front();
+ currentCommandIndex = previousCommands.size();
+ notifyPreviousCommandsChanged();
+}
+
+std::deque<ConsoleCommand> ConsoleModel::GetPreviousCommands()
+{
+ return previousCommands;
+}
+
+void ConsoleModel::notifyPreviousCommandsChanged()
+{
+ for(int i = 0; i < observers.size(); i++)
+ {
+ observers[i]->NotifyPreviousCommandsChanged(this);
+ }
+}
+
+void ConsoleModel::notifyCurrentCommandChanged()
+{
+ for(int i = 0; i < observers.size(); i++)
+ {
+ observers[i]->NotifyCurrentCommandChanged(this);
+ }
+}
+
+ConsoleModel::~ConsoleModel() {
+
+}
+