pgLab/pglab/codeeditor/CompletionPopup.h

41 lines
1 KiB
C
Raw Normal View History

#ifndef COMPLETIONPOPUP_H
#define COMPLETIONPOPUP_H
#include <QListWidget>
#include <functional>
#include <vector>
struct EditorCompletionItem {
QString display;
QString detail;
QString insertText;
bool ambiguous = false;
};
struct EditorCompletionResult {
int replaceStart = 0;
int replaceLen = 0;
bool hasQualifier = false; // completing behind "name."
std::vector<EditorCompletionItem> items;
};
/// Callback that determines the completions for a cursor position in the text
using EditorCompletionCallback = std::function<EditorCompletionResult(const QString &text, int cursorPos)>;
/// List shown below the cursor, it never takes keyboard focus so typing continues in the editor.
class CompletionPopup : public QListWidget {
Q_OBJECT
public:
explicit CompletionPopup(QWidget *parent);
void setItems(const std::vector<EditorCompletionItem> &items);
void moveSelection(int delta);
int currentRow() const { return QListWidget::currentRow(); }
void showAt(const QPoint &globalPos);
signals:
void itemAccepted(int row);
};
#endif // COMPLETIONPOPUP_H