Update: Translations from eints
[openttd-github.git] / src / autocompletion.h
blob452c23e87a4d2d2ead373cae6c17ce2d4fe535d1
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file autocompletion.h Generic auto-completion engine. */
10 #ifndef AUTOCOMPLETION_H
11 #define AUTOCOMPLETION_H
13 #include "textbuf_type.h"
15 class AutoCompletion {
16 protected:
17 Textbuf *textbuf;
19 private:
20 std::string initial_buf; ///< Value of text buffer when we started current suggestion session.
22 std::string_view prefix; ///< Prefix of the text before the last space.
23 std::string_view query; ///< Last token of the text. This is used to based the suggestions on.
25 std::vector<std::string> suggestions;
26 size_t current_suggestion_index;
28 public:
29 AutoCompletion(Textbuf *textbuf) : textbuf(textbuf)
31 this->Reset();
33 virtual ~AutoCompletion() = default;
35 // Returns true the textbuf was updated.
36 bool AutoComplete();
37 void Reset();
39 private:
40 void InitSuggestions(std::string_view text);
42 virtual std::vector<std::string> GetSuggestions(std::string_view prefix, std::string_view query) = 0;
43 virtual void ApplySuggestion(std::string_view prefix, std::string_view suggestion) = 0;
46 #endif /* AUTOCOMPLETION_H */