Consolidate input completion code in preparation for advanced completion strategies (#4639)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "controllers/completion/CompletionModel.hpp"
|
||||
#include "controllers/completion/sources/Source.hpp"
|
||||
#include "widgets/BasePopup.hpp"
|
||||
#include "widgets/listview/GenericListModel.hpp"
|
||||
#include "widgets/listview/GenericListView.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -12,35 +15,19 @@ namespace chatterino {
|
||||
class Channel;
|
||||
using ChannelPtr = std::shared_ptr<Channel>;
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct CompletionEmote {
|
||||
EmotePtr emote;
|
||||
QString displayName;
|
||||
QString providerName;
|
||||
};
|
||||
|
||||
std::vector<CompletionEmote> buildCompletionEmoteList(const QString &text,
|
||||
ChannelPtr channel);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
class GenericListView;
|
||||
|
||||
class InputCompletionPopup : public BasePopup
|
||||
{
|
||||
using ActionCallback = std::function<void(const QString &)>;
|
||||
|
||||
constexpr static int MAX_ENTRY_COUNT = 200;
|
||||
constexpr static size_t MAX_ENTRY_COUNT = 200;
|
||||
|
||||
public:
|
||||
InputCompletionPopup(QWidget *parent = nullptr);
|
||||
|
||||
void updateEmotes(const QString &text, ChannelPtr channel);
|
||||
void updateUsers(const QString &text, ChannelPtr channel);
|
||||
void updateCompletion(const QString &text, CompletionKind kind,
|
||||
ChannelPtr channel);
|
||||
|
||||
void setInputAction(ActionCallback callback);
|
||||
|
||||
@@ -54,14 +41,21 @@ protected:
|
||||
|
||||
private:
|
||||
void initLayout();
|
||||
void beginCompletion(CompletionKind kind, ChannelPtr channel);
|
||||
void endCompletion();
|
||||
|
||||
std::unique_ptr<completion::Source> getSource() const;
|
||||
|
||||
struct {
|
||||
GenericListView *listView;
|
||||
} ui_{};
|
||||
|
||||
GenericListModel model_;
|
||||
CompletionModel model_;
|
||||
ActionCallback callback_;
|
||||
QTimer redrawTimer_;
|
||||
|
||||
std::optional<CompletionKind> currentKind_{};
|
||||
ChannelPtr currentChannel_{};
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user