From 462bd7bdf914b2663c7e574a0bf4de6d4a8a723c Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 15 Dec 2012 22:55:53 -0500 Subject: [PATCH] fix comments being deleted when hitting enter and opening a save or getting an error when commenting --- src/preview/PreviewController.cpp | 7 +++++-- src/preview/PreviewController.h | 2 +- src/preview/PreviewView.cpp | 13 ++++++++++--- src/preview/PreviewView.h | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index 89e3ca620..37561b7b5 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -84,24 +84,27 @@ void PreviewController::Update() } } -void PreviewController::SubmitComment(std::string comment) +bool PreviewController::SubmitComment(std::string comment) { if(comment.length() < 4) { new ErrorMessage("Error", "Comment is too short"); + return false; } else { RequestStatus status = Client::Ref().AddComment(saveId, comment); if(status != RequestOkay) { - new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError()); + new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError()); + return false; } else { previewModel->UpdateComments(1); } } + return true; } void PreviewController::ShowLogin() diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h index c8c3f8e36..2d8e35a1b 100644 --- a/src/preview/PreviewController.h +++ b/src/preview/PreviewController.h @@ -41,7 +41,7 @@ public: PreviewView * GetView() { return previewView; } void Update(); void FavouriteSave(); - void SubmitComment(std::string comment); + bool SubmitComment(std::string comment); void NextCommentPage(); void PrevCommentPage(); diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 0e8c43cf2..fca7fa005 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -19,6 +19,7 @@ #include "search/Thumbnail.h" #include "client/Client.h" #include "interface/ScrollPanel.h" +#include "interface/Keys.h" class PreviewView::LoginAction: public ui::ButtonAction { @@ -121,7 +122,6 @@ PreviewView::PreviewView(): openButton->SetIcon(IconOpen); openButton->SetActionCallback(new OpenAction(this)); AddComponent(openButton); - SetOkayButton(openButton); class BrowserOpenAction: public ui::ButtonAction { @@ -363,6 +363,12 @@ void PreviewView::OnMouseWheel(int x, int y, int d) } +void PreviewView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) +{ + if ((key == KEY_ENTER || key == KEY_RETURN) && !addCommentBox->IsFocused()) + openButton->DoAction(); +} + void PreviewView::NotifySaveChanged(PreviewModel * sender) { SaveInfo * save = sender->GetSave(); @@ -429,10 +435,11 @@ void PreviewView::submitComment() std::string comment = std::string(addCommentBox->GetText()); submitCommentButton->Enabled = false; addCommentBox->SetText(""); - addCommentBox->SetPlaceholder("Submitting comment"); + addCommentBox->SetPlaceholder("Submitting comment"); //This doesn't appear to ever show since no separate thread is created FocusComponent(NULL); - c->SubmitComment(comment); + if (!c->SubmitComment(comment)) + addCommentBox->SetText(comment); addCommentBox->SetPlaceholder("Add comment"); submitCommentButton->Enabled = true; diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 2dc667bf9..c5931af49 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -72,6 +72,7 @@ public: virtual void OnTick(float dt); virtual void OnTryExit(ExitMethod method); virtual void OnMouseWheel(int x, int y, int d); + virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); virtual ~PreviewView(); };