122 lines
3.3 KiB
C++
122 lines
3.3 KiB
C++
#ifndef OLLIE_KATE_PLUGIN_H
|
|
#define OLLIE_KATE_PLUGIN_H
|
|
|
|
#include <KTextEditor/Plugin>
|
|
#include <KTextEditor/ConfigPage>
|
|
#include <KTextEditor/MainWindow>
|
|
#include <KTextEditor/View>
|
|
#if QT_VERSION_MAJOR >= 6
|
|
#include <KPluginMetaData>
|
|
#endif
|
|
|
|
#include <QDBusInterface>
|
|
#include <QDBusConnection>
|
|
#include <QPointer>
|
|
#include <QTextEdit>
|
|
#include <QLineEdit>
|
|
#include <QLabel>
|
|
#include <QAction>
|
|
#include <QEvent>
|
|
|
|
class OllieKateView;
|
|
class OllieGhostProvider;
|
|
|
|
class OllieKatePlugin : public KTextEditor::Plugin
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
#if QT_VERSION_MAJOR >= 6
|
|
explicit OllieKatePlugin(QObject *parent, const KPluginMetaData &data, const QVariantList &args = {});
|
|
#else
|
|
explicit OllieKatePlugin(QObject *parent, const QVariantList &args = {});
|
|
#endif
|
|
~OllieKatePlugin() override = default;
|
|
|
|
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
|
|
int configPages() const override;
|
|
KTextEditor::ConfigPage *configPage(int number, QWidget *parent) override;
|
|
|
|
// Completion config accessors
|
|
QString completionBackend() const;
|
|
QString completionModel() const;
|
|
void setCompletionBackend(const QString &backend);
|
|
void setCompletionModel(const QString &model);
|
|
bool completionEnabled() const;
|
|
void setCompletionEnabled(bool enabled);
|
|
|
|
// Default session backend/model (overrides OLLIE_BACKEND / OLLIE_MODEL)
|
|
QString defaultBackend() const;
|
|
QString defaultModel() const;
|
|
void setDefaultBackend(const QString &backend);
|
|
void setDefaultModel(const QString &model);
|
|
|
|
private:
|
|
void loadConfig();
|
|
void saveConfig();
|
|
|
|
QString m_completionBackend;
|
|
QString m_completionModel;
|
|
bool m_completionEnabled = true;
|
|
QString m_defaultBackend;
|
|
QString m_defaultModel;
|
|
};
|
|
|
|
class OllieKateView : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit OllieKateView(OllieKatePlugin *plugin, KTextEditor::MainWindow *mainWindow);
|
|
~OllieKateView() override;
|
|
|
|
OllieKatePlugin *plugin() const { return m_plugin; }
|
|
|
|
protected:
|
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
|
|
|
private slots:
|
|
void onChatUpdated(const QString &session_id, qlonglong offset, const QString &new_text);
|
|
void onStateChanged(const QString &session_id, const QString &new_state);
|
|
void onSessionCreated(const QString &session_id);
|
|
void onSessionKilled(const QString &session_id);
|
|
|
|
void submitPrompt();
|
|
void askAboutFile();
|
|
void explainSelection();
|
|
void newSession();
|
|
void pickSession();
|
|
void renameSession();
|
|
void refreshSessions();
|
|
|
|
private:
|
|
void ensureSession();
|
|
QString activeSessionId();
|
|
void appendChat(const QString &text);
|
|
|
|
OllieKatePlugin *m_plugin;
|
|
KTextEditor::MainWindow *m_mainWindow;
|
|
QDBusInterface *m_iface;
|
|
QWidget *m_toolView;
|
|
QLabel *m_sessionLabel;
|
|
QLabel *m_cwdLabel;
|
|
QLabel *m_completionStatus;
|
|
QTextEdit *m_chatView;
|
|
QLineEdit *m_promptInput;
|
|
QAction *m_askFileAction;
|
|
QAction *m_explainAction;
|
|
QAction *m_newSessionAction;
|
|
|
|
QString m_sessionId;
|
|
qlonglong m_chatOffset = 0;
|
|
|
|
QPointer<OllieGhostProvider> m_ghost;
|
|
bool m_ghostPrefix = false; // true after Meta+O, waiting for second key
|
|
|
|
QString projectBaseDir();
|
|
void switchToSession(const QString &sessionId);
|
|
void setupGhostProvider();
|
|
};
|
|
|
|
#endif // OLLIE_KATE_PLUGIN_H
|