tabswitcher.h 2.82 KB
Newer Older
1
2
/* This file is part of the KDE project

3
4
5
   SPDX-FileCopyrightText: 2014 Dominik Haumann <dhaumann@kde.org>

   SPDX-License-Identifier: LGPL-2.0-or-later
6
7
8
9
10
11
*/

#ifndef KTEXTEDITOR_TAB_SWITCHER_PLUGIN_H
#define KTEXTEDITOR_TAB_SWITCHER_PLUGIN_H

#include <KTextEditor/MainWindow>
12
#include <KTextEditor/Plugin>
13
14

#include <QList>
15
#include <QSet>
16
17
18
19
20
21
22
23
#include <QVariant>

#include <KXMLGUIClient>

class TabSwitcherPluginView;
class TabSwitcherTreeView;
class QStandardItemModel;
class QModelIndex;
24
25
26
namespace detail
{
class TabswitcherFilesModel;
27
}
28
29
30
31
32
33
34
35
36
37
38

class TabSwitcherPlugin : public KTextEditor::Plugin
{
    Q_OBJECT

    friend TabSwitcherPluginView;

public:
    /**
     * Plugin constructor.
     */
39
    explicit TabSwitcherPlugin(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>());
40
41
42
43

    /**
     * Create a new tab switcher for @p mainWindow.
     */
Kevin Funk's avatar
Kevin Funk committed
44
    QObject *createView(KTextEditor::MainWindow *mainWindow) override;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

private:
    QList<TabSwitcherPluginView *> m_views;
};

class TabSwitcherPluginView : public QObject, public KXMLGUIClient
{
    Q_OBJECT

public:
    /**
     * View constructor.
     */
    TabSwitcherPluginView(TabSwitcherPlugin *plugin, KTextEditor::MainWindow *mainWindow);

    /**
     * View destructor.
     */
Kevin Funk's avatar
Kevin Funk committed
63
    ~TabSwitcherPluginView() override;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

    /**
     * Setup the shortcut actions.
     */
    void setupActions();

    /**
     * Initial fill of model with documents from the application.
     */
    void setupModel();

public Q_SLOTS:
    /**
     * Adds @p document to the model.
     */
79
    void registerDocument(KTextEditor::Document *document);
80
81
82
83

    /**
     * Removes @p document from the model.
     */
84
    void unregisterDocument(KTextEditor::Document *document);
85
86
87
88

    /**
     * Update the name in the model for @p document.
     */
89
    void updateDocumentName(KTextEditor::Document *document);
90
91

    /**
Yuri Chornoivan's avatar
Yuri Chornoivan committed
92
     * Raise @p view in a lru fashion.
93
     */
94
    void raiseView(KTextEditor::View *view);
95
96
97
98
99
100
101
102
103
104
105
106
107
108

    /**
     * Focus next item in the treeview.
     */
    void walkForward();

    /**
     * Focus previous item in the treeview.
     */
    void walkBackward();

    /**
     * Activate the document for @p index.
     */
109
    void switchToClicked(const QModelIndex &index);
110
111
112
113

    /**
     * Show the document for @p index.
     */
114
    void activateView(const QModelIndex &index);
115

116
117
118
119
120
    /**
     * Closes the current view
     */
    void closeView();

121
122
123
124
125
126
127
128
129
130
131
132
133
134
protected:
    /**
     * Move through the list.
     */
    void walk(const int from, const int to);

    /**
     * Make sure the popup view has a sane size.
     */
    void updateViewGeometry();

private:
    TabSwitcherPlugin *m_plugin;
    KTextEditor::MainWindow *m_mainWindow;
135
    detail::TabswitcherFilesModel *m_model;
136
    QSet<KTextEditor::Document *> m_documents;
137
    TabSwitcherTreeView *m_treeView;
138
139
140
};

#endif // KTEXTEDITOR_TAB_SWITCHER_PLUGIN_H