From e88fca8aa1d4b0c585b50abf501ce733d1645f05 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 25 Aug 2012 18:11:36 +0100 Subject: [PATCH] Save ID copying for preview --- src/interface/Textbox.cpp | 13 +++++++++---- src/interface/Textbox.h | 1 + src/preview/PreviewController.cpp | 9 +++------ src/preview/PreviewController.h | 1 + src/preview/PreviewView.cpp | 30 ++++++++++++++++++++++++++++++ src/preview/PreviewView.h | 3 ++- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 159c32626..603fa23d8 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -19,7 +19,8 @@ Textbox::Textbox(Point position, Point size, std::string textboxText, std::strin limit(std::string::npos), inputType(All), keyDown(0), - characterDown(0) + characterDown(0), + ReadOnly(false) { placeHolder = textboxPlaceholder; @@ -268,12 +269,12 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool copySelection(); return; } - if(ctrl && key == 'v') + if(ctrl && key == 'v' && !ReadOnly) { pasteIntoSelection(); return; } - if(ctrl && key == 'x' && !masked) + if(ctrl && key == 'x' && !masked && !ReadOnly) { cutSelection(); return; @@ -307,6 +308,8 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool ClearSelection(); break; case KEY_DELETE: + if(ReadOnly) + break; if(HasSelection()) { if(getLowerSelectionBound() < 0 || getHigherSelectionBound() > backingText.length()) @@ -326,6 +329,8 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool ClearSelection(); break; case KEY_BACKSPACE: + if(ReadOnly) + break; if(HasSelection()) { if(getLowerSelectionBound() < 0 || getHigherSelectionBound() > backingText.length()) @@ -351,7 +356,7 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool ClearSelection(); break; } - if(CharacterValid(character)) + if(CharacterValid(character) && !ReadOnly) { if(HasSelection()) { diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h index a43a7e571..7d06111ef 100644 --- a/src/interface/Textbox.h +++ b/src/interface/Textbox.h @@ -20,6 +20,7 @@ class Textbox : public Label { friend class TextboxAction; public: + bool ReadOnly; enum ValidInput { All, Numeric, Number }; Textbox(Point position, Point size, std::string textboxText = "", std::string textboxPlaceholder = ""); virtual ~Textbox(); diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index b81ccdab2..651db3235 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -124,12 +124,9 @@ void PreviewController::FavouriteSave() void PreviewController::OpenInBrowser() { - if(previewModel->GetSave()) - { - std::stringstream uriStream; - uriStream << "http://" << SERVER << "/Browse/View.html?ID=" << previewModel->GetSave()->id; - OpenURI(uriStream.str()); - } + std::stringstream uriStream; + uriStream << "http://" << SERVER << "/Browse/View.html?ID=" << saveId; + OpenURI(uriStream.str()); } void PreviewController::NextCommentPage() diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h index e6b8caa84..c04a07f87 100644 --- a/src/preview/PreviewController.h +++ b/src/preview/PreviewController.h @@ -25,6 +25,7 @@ class PreviewController: public ClientListener { ControllerCallback * callback; public: virtual void NotifyAuthUserChanged(Client * sender); + inline int SaveID() { return saveId; }; bool HasExited; PreviewController(int saveID, ControllerCallback * callback); diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 5b7952b23..c0aacf9e3 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -155,15 +155,45 @@ PreviewView::PreviewView(): authorDateLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom; AddComponent(authorDateLabel); + pageInfo = new ui::Label(ui::Point((XRES/2) + 5, Size.Y+1), ui::Point(Size.X-((XRES/2) + 10), 15), "Page 1 of 1"); pageInfo->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + saveIDTextbox = new ui::Textbox(ui::Point((XRES/2)-55, Size.Y-40), ui::Point(50, 16), "0000000"); + saveIDTextbox->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; + saveIDTextbox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + saveIDTextbox->ReadOnly = true; + AddComponent(saveIDTextbox); + + class CopyIDAction: public ui::ButtonAction + { + PreviewView * v; + public: + CopyIDAction(PreviewView * v_){ v = v_; } + virtual void ActionCallback(ui::Button * sender) + { + clipboard_push_text((char*)v->saveIDTextbox->GetText().c_str()); + } + }; + + ui::Button * tempButton = new ui::Button(ui::Point((XRES/2)-130, Size.Y-40), ui::Point(70, 16), "Copy Save ID"); + tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; + tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + tempButton->SetActionCallback(new CopyIDAction(this)); + AddComponent(tempButton); + commentsPanel = new ui::ScrollPanel(ui::Point((XRES/2)+1, 1), ui::Point((Size.X-(XRES/2))-2, Size.Y-commentBoxHeight)); AddComponent(commentsPanel); AddComponent(pageInfo); } +void PreviewView::AttachController(PreviewController * controller) +{ + c = controller; + saveIDTextbox->SetText(format::NumberToString(c->SaveID())); +} + void PreviewView::commentBoxAutoHeight() { if(!addCommentBox) diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 5e777fb27..7fb9ff55d 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -41,6 +41,7 @@ class PreviewView: public ui::Window { ui::Label * authorDateLabel; ui::Label * pageInfo; ui::Label * saveDescriptionLabel; + ui::Textbox * saveIDTextbox; ui::ScrollPanel * commentsPanel; std::vector comments; std::vector commentComponents; @@ -59,7 +60,7 @@ class PreviewView: public ui::Window { void commentBoxAutoHeight(); void submitComment(); public: - void AttachController(PreviewController * controller) { c = controller;} + void AttachController(PreviewController * controller); PreviewView(); void NotifySaveChanged(PreviewModel * sender); void NotifyCommentsChanged(PreviewModel * sender);