diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-08-29 09:01:27 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-08-29 22:19:24 -0600 |
commit | d55c1345449a34adb3192c23fe3760bd0aae645b (patch) | |
tree | 0dfe78eba2571b2f156c14deafe375d3f3241164 /src/gui/widgets/textfield.h | |
parent | b61faa43db7a48c6a6871fb94dce2de2abd79dfe (diff) | |
download | mana-d55c1345449a34adb3192c23fe3760bd0aae645b.tar.gz mana-d55c1345449a34adb3192c23fe3760bd0aae645b.tar.bz2 mana-d55c1345449a34adb3192c23fe3760bd0aae645b.tar.xz mana-d55c1345449a34adb3192c23fe3760bd0aae645b.zip |
Move handling of autocomplete and input history into TextField
Reviewed-by: Freeyorp
Diffstat (limited to 'src/gui/widgets/textfield.h')
-rw-r--r-- | src/gui/widgets/textfield.h | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 1e6df9d6..6e50f1e9 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -24,9 +24,48 @@ #include <guichan/widgets/textfield.hpp> +#include <vector> + class ImageRect; class TextField; +typedef std::list<std::string> TextHistoryList; +typedef TextHistoryList::iterator TextHistoryIterator; + +struct TextHistory { + TextHistoryList history; /**< Command history. */ + TextHistoryIterator current; /**< History iterator. */ + + TextHistory() + { current = history.end(); } + + bool empty() const + { return history.empty(); } + + bool atBegining() const + { return current == history.begin(); } + + bool atEnd() const + { return current == history.end(); } + + void toBegining() + { current = history.begin(); } + + void toEnd() + { current = history.end(); } + + void addEntry(const std::string &text) + { history.push_back(text); } + + bool matchesEntry(const std::string &text) + { return (*current) == text; } +}; + +class AutoCompleteLister { +public: + virtual void getAutoCompleteList(std::vector<std::string>&) const {} +}; + /** * A text field. * @@ -91,16 +130,32 @@ class TextField : public gcn::TextField int getValue() const; /** - * Set if the tabulator key causes auto complete + * Sets the TextField's source of autocomplete. Passing null will + * disable autocomplete. + */ + void setAutoComplete(AutoCompleteLister *lister) + { mAutoComplete = lister; } + + /** + * Returns the TextField's source of autocomplete. */ - void setAutoComplete(bool b ) {mAutoComplete = b;} + AutoCompleteLister *getAutoComplete() const + { return mAutoComplete; } /** - * Returns if the tabulator key causes auto complete + * Sets the TextField's source of input history. */ - bool getAutoComplete() {return mAutoComplete;} + void setHistory(TextHistory *history) + { mHistory = history; } + + /** + * Returns the TextField's source of input history. + */ + TextHistory *getHistory() const + { return mHistory; } private: + void autoComplete(); void handlePaste(); static int instances; @@ -110,7 +165,10 @@ class TextField : public gcn::TextField int mMinimum; int mMaximum; bool mLoseFocusOnTab; - bool mAutoComplete; + + AutoCompleteLister *mAutoComplete; + + TextHistory *mHistory; /**< Text history. */ }; #endif |