diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index e5c301336..7b0871626 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 a1d6b8bd2..0106dd709 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 000000000..05138f27d --- /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 +#include +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 a4e50832a..838dba0a0 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 09e908e4a..c00db8d64 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 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 000000000..2473cabd3 --- /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 +#include +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 4a4fd0663..c39a4c72c 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 01074497a..2861c8c6c 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);