File indexing completed on 2025-01-05 05:20:13

0001 /*
0002     SPDX-FileCopyrightText: 2023 Waqar Ahmed <waqar.17a@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 #pragma once
0006 
0007 #include <KTextEditor/Cursor>
0008 #include <KTextEditor/MainWindow>
0009 #include <KTextEditor/MovingRange>
0010 #include <KTextEditor/Plugin>
0011 #include <KXMLGUIClient>
0012 
0013 #include <QPointer>
0014 #include <QVariant>
0015 
0016 #include <unordered_map>
0017 #include <utility>
0018 
0019 namespace KTextEditor
0020 {
0021 class MovingRange;
0022 }
0023 class KateTextHintProvider;
0024 using MovingRangeList = std::vector<std::unique_ptr<KTextEditor::MovingRange>>;
0025 
0026 class OpenLinkPlugin final : public KTextEditor::Plugin
0027 {
0028     Q_OBJECT
0029 public:
0030     explicit OpenLinkPlugin(QObject *parent = nullptr, const QVariantList & = QVariantList())
0031         : KTextEditor::Plugin(parent)
0032     {
0033     }
0034     QObject *createView(KTextEditor::MainWindow *mainWindow) override;
0035 };
0036 
0037 class OpenLinkPluginView final : public QObject, public KXMLGUIClient
0038 {
0039     Q_OBJECT
0040 public:
0041     explicit OpenLinkPluginView(OpenLinkPlugin *plugin, KTextEditor::MainWindow *mainwindow);
0042     ~OpenLinkPluginView();
0043 
0044 private:
0045     void onActiveViewChanged(KTextEditor::View *);
0046     bool eventFilter(QObject *obj, QEvent *event) override;
0047     void highlightIfLink(KTextEditor::Cursor c, QWidget *viewInternal);
0048     void gotoLink();
0049     void onTextRemoved(KTextEditor::Document *, KTextEditor::Range range, const QString &text);
0050     void onTextInserted(KTextEditor::Document *, KTextEditor::Cursor pos, const QString &text);
0051     void onViewScrolled();
0052     void highlightLinks(KTextEditor::Range range);
0053     void clear(KTextEditor::Document *doc);
0054 
0055     QPointer<KTextEditor::View> m_activeView;
0056     KTextEditor::MainWindow *m_mainWindow;
0057     std::unique_ptr<class GotoLinkHover> m_ctrlHoverFeedback;
0058     std::unordered_map<KTextEditor::Document *, MovingRangeList> m_docHighligtedLinkRanges;
0059     class OpenLinkTextHint *m_textHintProvider;
0060     friend class OpenLinkTextHint;
0061 };