diff options
author | Stefan Dombrowski <stefan@uni-bonn.de> | 2010-08-25 20:38:06 +0200 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-25 12:59:25 -0600 |
commit | 627e1271f0ac2e7bd95a83f521ecbcf1b554ba80 (patch) | |
tree | 5071591268bdfa40add8a07b859fb1bf4d123db4 | |
parent | 38474d0c3c14cf595aed61ee1e4a69d48abbcf92 (diff) | |
download | mana-627e1271f0ac2e7bd95a83f521ecbcf1b554ba80.tar.gz mana-627e1271f0ac2e7bd95a83f521ecbcf1b554ba80.tar.bz2 mana-627e1271f0ac2e7bd95a83f521ecbcf1b554ba80.tar.xz mana-627e1271f0ac2e7bd95a83f521ecbcf1b554ba80.zip |
Adding autoComplete for invite
Signed-off-by: Jared Adams <jaxad0127@gmail.com>
-rw-r--r-- | src/gui/chat.h | 1 | ||||
-rw-r--r-- | src/gui/socialwindow.cpp | 17 | ||||
-rw-r--r-- | src/gui/textdialog.cpp | 10 | ||||
-rw-r--r-- | src/gui/textdialog.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/shoplistbox.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 16 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 11 |
7 files changed, 48 insertions, 11 deletions
diff --git a/src/gui/chat.h b/src/gui/chat.h index e49d02c9..b0d91556 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -177,6 +177,7 @@ class ChatWindow : public Window, protected: friend class ChatTab; friend class WhisperTab; + friend class TextField; /** Remove the given tab from the window */ void removeTab(ChatTab *tab); diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 7a13f96b..3d8afa44 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -121,12 +121,16 @@ public: if (event.getId() == "do invite") { std::string name = mInviteDialog->getText(); - Net::getGuildHandler()->invite(mGuild->getId(), name); - localChatTab->chatLog(strprintf(_("Invited user %s to guild %s."), + if (!name.empty()) + { + Net::getGuildHandler()->invite(mGuild->getId(), name); + localChatTab->chatLog(strprintf(_("Invited user %s to guild %s."), name.c_str(), mGuild->getName().c_str()), BY_SERVER); + } + mInviteDialog = NULL; } else if (event.getId() == "~do invite") @@ -153,7 +157,7 @@ protected: mInviteDialog = new TextDialog(_("Member Invite to Guild"), strprintf(_("Who would you like to invite to guild %s?"), mGuild->getName().c_str()), - socialWindow); + socialWindow, true); mInviteDialog->setActionEventId("do invite"); mInviteDialog->addActionListener(this); } @@ -202,7 +206,10 @@ public: if (event.getId() == "do invite") { std::string name = mInviteDialog->getText(); - Net::getPartyHandler()->invite(name); + + if (!name.empty()) + Net::getPartyHandler()->invite(name); + mInviteDialog = NULL; } else if (event.getId() == "~do invite") @@ -229,7 +236,7 @@ protected: mInviteDialog = new TextDialog(_("Member Invite to Party"), strprintf(_("Who would you like to invite to party %s?"), mParty->getName().c_str()), - socialWindow); + socialWindow, true); mInviteDialog->setActionEventId("do invite"); mInviteDialog->addActionListener(this); } diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp index 6faa1162..28792a0b 100644 --- a/src/gui/textdialog.cpp +++ b/src/gui/textdialog.cpp @@ -30,14 +30,18 @@ int TextDialog::instances = 0; TextDialog::TextDialog(const std::string &title, const std::string &msg, - Window *parent): - Window(title, true, parent), - mTextField(new TextField) + Window *parent, bool autoCompleteEnabled): + Window(title, true, parent) { gcn::Label *textLabel = new Label(msg); mOkButton = new Button(_("OK"), "OK", this); gcn::Button *cancelButton = new Button(_("Cancel"), "CANCEL", this); + // In TextField the escape key will either cause autoComplete or lose focus + mTextField = new TextField("", ! autoCompleteEnabled); + if (autoCompleteEnabled) + mTextField->setAutoComplete(true); + mTextField->addActionListener(this); place(0, 0, textLabel, 4); diff --git a/src/gui/textdialog.h b/src/gui/textdialog.h index d4c611cc..aa8fcf8f 100644 --- a/src/gui/textdialog.h +++ b/src/gui/textdialog.h @@ -42,7 +42,7 @@ public: * @see Window::Window */ TextDialog(const std::string &title, const std::string &msg, - Window *parent = NULL); + Window *parent = NULL, bool autoCompleteEnabled = false); ~TextDialog(); diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h index 9232a5a4..087bdd53 100644 --- a/src/gui/widgets/shoplistbox.h +++ b/src/gui/widgets/shoplistbox.h @@ -48,7 +48,7 @@ class ShopListBox : public ListBox ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel); /** - * Deconstructor + * Destructor */ ~ShopListBox(); diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 4453f522..60a1f57f 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -21,9 +21,11 @@ #include "gui/widgets/textfield.h" +#include "beingmanager.h" #include "configuration.h" #include "graphics.h" +#include "gui/chat.h" #include "gui/palette.h" #include "gui/sdlinput.h" #include "gui/theme.h" @@ -43,7 +45,8 @@ ImageRect TextField::skin; TextField::TextField(const std::string &text, bool loseFocusOnTab): gcn::TextField(text), - mNumeric(false) + mNumeric(false), + mAutoComplete(false) { setFrameSize(2); @@ -246,6 +249,17 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) break; case Key::TAB: + if (mAutoComplete && mText.size() > 0) + { + std::vector<std::string> names; + beingManager->getPlayerNames(names, false); + std::string newName = chatWindow->autoComplete(names, mText); + if (newName != "") + { + setText(newName); + setCaretPosition(mText.size()); + } + } if (mLoseFocusOnTab) return; break; diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 58e37f5c..1e6df9d6 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -90,6 +90,16 @@ class TextField : public gcn::TextField */ int getValue() const; + /** + * Set if the tabulator key causes auto complete + */ + void setAutoComplete(bool b ) {mAutoComplete = b;} + + /** + * Returns if the tabulator key causes auto complete + */ + bool getAutoComplete() {return mAutoComplete;} + private: void handlePaste(); @@ -100,6 +110,7 @@ class TextField : public gcn::TextField int mMinimum; int mMaximum; bool mLoseFocusOnTab; + bool mAutoComplete; }; #endif |