summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-03-29 15:17:30 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-03-29 15:17:30 (GMT)
commit289556ac7078963b6af361f5812dd62e6712359f (patch)
tree77bfff7d8594fcefe1220a0789dd69af58a48a25 /src
parent1f388e4ca02f0a84e4b9d9b19e6308224389818d (diff)
downloadpowder-289556ac7078963b6af361f5812dd62e6712359f.zip
powder-289556ac7078963b6af361f5812dd62e6712359f.tar.gz
Replace Error notification with exception for Tags model
Diffstat (limited to 'src')
-rw-r--r--src/game/GameController.cpp4
-rw-r--r--src/game/GameModel.cpp4
-rw-r--r--src/game/GameModelException.h26
-rw-r--r--src/tags/TagsModel.cpp15
-rw-r--r--src/tags/TagsModel.h3
-rw-r--r--src/tags/TagsModelException.h23
-rw-r--r--src/tags/TagsView.cpp25
-rw-r--r--src/tags/TagsView.h1
8 files changed, 74 insertions, 27 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index e5c3013..7b08716 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -10,7 +10,7 @@
#include "login/LoginController.h"
#include "interface/Point.h"
#include "dialogues/ErrorMessage.h"
-#include "SaveLoadException.h"
+#include "GameModelException.h"
using namespace std;
@@ -39,7 +39,7 @@ public:
{
cc->gameModel->SetSave(new Save(*(cc->search->GetLoadedSave())));
}
- catch(SaveLoadException & ex)
+ catch(GameModelException & ex)
{
new ErrorMessage("Cannot open save", ex.what());
}
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index a1d6b8b..0106dd7 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -8,7 +8,7 @@
#include "EllipseBrush.h"
#include "client/Client.h"
#include "game/DecorationTool.h"
-#include "SaveLoadException.h"
+#include "GameModelException.h"
GameModel::GameModel():
activeTools({NULL, NULL, NULL}),
@@ -262,7 +262,7 @@ void GameModel::SetSave(Save * newSave)
if(returnVal){
delete currentSave;
currentSave = NULL;
- throw SaveLoadException(returnVal==2?"Save from newer version":"Save data corrupt");
+ throw GameModelException(returnVal==2?"Save from newer version":"Save data corrupt");
}
}
notifySaveChanged();
diff --git a/src/game/GameModelException.h b/src/game/GameModelException.h
new file mode 100644
index 0000000..05138f2
--- /dev/null
+++ b/src/game/GameModelException.h
@@ -0,0 +1,26 @@
+/*
+ * SaveLoadException.h
+ *
+ * Created on: Mar 29, 2012
+ * Author: Simon
+ */
+
+#ifndef SAVELOADEXCEPTION_H_
+#define SAVELOADEXCEPTION_H_
+
+#include <string>
+#include <exception>
+using namespace std;
+
+struct GameModelException: public exception {
+ string message;
+public:
+ GameModelException(string message_): message(message_) {}
+ const char * what() const throw()
+ {
+ return message.c_str();
+ }
+ ~GameModelException() throw() {};
+};
+
+#endif /* SAVELOADEXCEPTION_H_ */
diff --git a/src/tags/TagsModel.cpp b/src/tags/TagsModel.cpp
index a4e5083..838dba0 100644
--- a/src/tags/TagsModel.cpp
+++ b/src/tags/TagsModel.cpp
@@ -8,6 +8,7 @@
#include "TagsModel.h"
#include "TagsView.h"
#include "client/Client.h"
+#include "TagsModelException.h"
TagsModel::TagsModel():
save(NULL)
@@ -40,8 +41,7 @@ void TagsModel::RemoveTag(string tag)
}
else
{
- lastError = Client::Ref().GetLastError();
- notifyError();
+ throw TagsModelException(Client::Ref().GetLastError());
}
}
}
@@ -59,8 +59,7 @@ void TagsModel::AddTag(string tag)
}
else
{
- lastError = Client::Ref().GetLastError();
- notifyError();
+ throw TagsModelException(Client::Ref().GetLastError());
}
}
}
@@ -79,14 +78,6 @@ void TagsModel::notifyTagsChanged()
}
}
-void TagsModel::notifyError()
-{
- for(int i = 0; i < observers.size(); i++)
- {
- observers[i]->NotifyError(this);
- }
-}
-
TagsModel::~TagsModel() {
// TODO Auto-generated destructor stub
}
diff --git a/src/tags/TagsModel.h b/src/tags/TagsModel.h
index 09e908e..c00db8d 100644
--- a/src/tags/TagsModel.h
+++ b/src/tags/TagsModel.h
@@ -14,10 +14,8 @@
class TagsView;
class TagsModel {
Save * save;
- string lastError;
std::vector<TagsView*> observers;
void notifyTagsChanged();
- void notifyError();
public:
TagsModel();
void AddObserver(TagsView * observer);
@@ -25,7 +23,6 @@ public:
void RemoveTag(string tag);
void AddTag(string tag);
Save * GetSave();
- string GetLastError(){ return lastError; }
virtual ~TagsModel();
};
diff --git a/src/tags/TagsModelException.h b/src/tags/TagsModelException.h
new file mode 100644
index 0000000..2473cab
--- /dev/null
+++ b/src/tags/TagsModelException.h
@@ -0,0 +1,23 @@
+/*
+ * TagsModelException.h
+ *
+ * Created on: Mar 29, 2012
+ * Author: Simon
+ */
+
+#ifndef TAGSMODELEXCEPTION_H_
+#define TAGSMODELEXCEPTION_H_
+
+#include <string>
+#include <exception>
+using namespace std;
+
+class TagsModelException {
+ string message;
+public:
+ TagsModelException(string message_): message(message_) {};
+ const char * what() const throw() { return message.c_str(); };
+ ~TagsModelException() throw() {};
+};
+
+#endif /* TAGSMODELEXCEPTION_H_ */
diff --git a/src/tags/TagsView.cpp b/src/tags/TagsView.cpp
index 4a4fd06..c39a4c7 100644
--- a/src/tags/TagsView.cpp
+++ b/src/tags/TagsView.cpp
@@ -11,6 +11,7 @@
#include "dialogues/ErrorMessage.h"
#include "TagsController.h"
#include "TagsModel.h"
+#include "TagsModelException.h"
TagsView::TagsView():
ui::Window(ui::Point(-1, -1), ui::Point(195, 250))
@@ -46,11 +47,6 @@ void TagsView::OnDraw()
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
}
-void TagsView::NotifyError(TagsModel * sender)
-{
- new ErrorMessage("Error", sender->GetLastError());
-}
-
void TagsView::NotifyTagsChanged(TagsModel * sender)
{
for(int i = 0; i < tags.size(); i++)
@@ -69,7 +65,14 @@ void TagsView::NotifyTagsChanged(TagsModel * sender)
DeleteTagAction(TagsView * _v, string tag) { v = _v; this->tag = tag; }
void ActionCallback(ui::Button * sender)
{
- v->c->RemoveTag(tag);
+ try
+ {
+ v->c->RemoveTag(tag);
+ }
+ catch(TagsModelException & ex)
+ {
+ new ErrorMessage("Could not remove tag", ex.what());
+ }
}
};
@@ -108,7 +111,15 @@ void TagsView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
case KEY_RETURN:
if(IsFocused(tagInput))
{
- c->AddTag(tagInput->GetText());
+
+ try
+ {
+ c->AddTag(tagInput->GetText());
+ }
+ catch(TagsModelException & ex)
+ {
+ new ErrorMessage("Could not add tag", ex.what());
+ }
tagInput->SetText("");
}
break;
diff --git a/src/tags/TagsView.h b/src/tags/TagsView.h
index 0107449..2861c8c 100644
--- a/src/tags/TagsView.h
+++ b/src/tags/TagsView.h
@@ -25,7 +25,6 @@ class TagsView: public ui::Window {
public:
TagsView();
virtual void OnDraw();
- void NotifyError(TagsModel * sender);
void AttachController(TagsController * c_) { c = c_; };
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
void NotifyTagsChanged(TagsModel * sender);