-
Notifications
You must be signed in to change notification settings - Fork 0
/
katetabsplugin.cpp
176 lines (139 loc) · 4.79 KB
/
katetabsplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* This file is part of the KDE project
Copyright (C) 2008 Javier Goday <jgoday @ gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "katetabsplugin.h"
#include "katetabspluginconfigpage.h"
#include "katetabbar.h"
// qt headers
#include <QLabel>
#include <QVBoxLayout>
// kde headers
#include <KConfigGroup>
#include <KDebug>
#include <KGenericFactory>
#include <KVBox>
// kate headers
#include <kate/application.h>
#include <ktexteditor/document.h>
#include <ktexteditor/view.h>
K_EXPORT_COMPONENT_FACTORY(katetabsplugin, KGenericFactory<KateTabsPlugin>("katetabsplugin"))
KateTabsPlugin::KateTabsPlugin(QObject *parent, const QStringList ¶meters) :
Kate::Plugin(qobject_cast <Kate::Application *> (parent)),
m_view(0)
{
Q_UNUSED (parameters)
}
KateTabsPlugin::~KateTabsPlugin()
{/*
delete m_view;*/
}
Kate::PluginView *KateTabsPlugin::createView(Kate::MainWindow *window)
{
m_view = new KateTabsPluginView(window);
return m_view;
}
uint KateTabsPlugin::configPages() const
{
return 1;
}
Kate::PluginConfigPage *KateTabsPlugin::configPage(uint number, QWidget *parent , const char *name)
{
Q_UNUSED(number)
Q_UNUSED(name)
KateTabsPluginConfigPage *page = new KateTabsPluginConfigPage(parent);
connect(page, SIGNAL(applySettings()), m_view, SLOT(loadConfig()));
return page;
}
QString KateTabsPlugin::configPageName(uint number) const
{
Q_UNUSED(number)
return i18n("Tabs");
}
QString KateTabsPlugin::configPageFullName(uint number) const
{
Q_UNUSED(number)
return i18n("Configure kate tabbar");
}
KIcon KateTabsPlugin::configPageIcon(uint number) const
{
Q_UNUSED(number)
return KIcon("tab-duplicate");
}
void KateTabsPlugin::loadConfig()
{
KateTabsPluginView *view = qobject_cast <KateTabsPluginView *> (m_view);
view->loadConfig();
}
KateTabsPluginView::KateTabsPluginView(Kate::MainWindow *window) :
Kate::PluginView(window)
{
KVBox *layout = qobject_cast <KVBox*> (window->centralWidget());
m_tabbar = new KateTabBar(layout);
foreach(KTextEditor::Document* doc, Kate::application()->documentManager()->documents()) {
m_tabbar->addDocument(doc);
}
connect(Kate::application()->documentManager(), SIGNAL(documentCreated(KTextEditor::Document*)),
m_tabbar, SLOT(addDocument(KTextEditor::Document*)));
connect(Kate::application()->documentManager(), SIGNAL(documentWillBeDeleted(KTextEditor::Document*)),
m_tabbar, SLOT(removeDocument(KTextEditor::Document*)));
connect(m_tabbar, SIGNAL(currentChanged(int)), SLOT(slotOpenDocument(int)));
connect(m_tabbar, SIGNAL(closeRequest(int)), SLOT(slotCloseDocumentByIndex(int)));
connect(mainWindow(), SIGNAL(viewChanged()), SLOT(slotActivateDocument()));
}
KateTabsPluginView::~KateTabsPluginView()
{
}
void KateTabsPluginView::readSessionConfig(KConfigBase* config, const QString& groupPrefix)
{
Q_UNUSED(config)
Q_UNUSED(groupPrefix)
KConfigGroup cg(KGlobal::config(), "KateTabBarPlugin");
m_tabbar->setShapeAsInt(cg.readEntry("tabs_shape", 0));
insertView(cg.readEntry("tabbar_position", 0));
}
void KateTabsPluginView::writeSessionConfig(KConfigBase* config, const QString& groupPrefix)
{
Q_UNUSED(config)
Q_UNUSED(groupPrefix)
KConfigGroup cg(KGlobal::config(), "KateTabBarPlugin");
cg.writeEntry("tabs_shape", m_tabbar->shapeAsInt());
cg.writeEntry("tabbar_position", m_tabbar->position());
}
void KateTabsPluginView::loadConfig()
{
m_tabbar->setShapeAsInt(KConfigGroup(KGlobal::config(), "KateTabBarPlugin").readEntry("tabs_shape", 0));
insertView(KConfigGroup(KGlobal::config(), "KateTabBarPlugin").readEntry("tabbar_position", 0));
}
void KateTabsPluginView::insertView(int position)
{
QVBoxLayout *vlayout = qobject_cast <QVBoxLayout *> (m_tabbar->parentWidget()->layout());
vlayout->removeWidget(m_tabbar);
switch(position) {
case KateTabBar::Top:
vlayout->insertWidget(0, m_tabbar);
break;
case KateTabBar::Bottom:
vlayout->insertWidget(1, m_tabbar);
break;
};
m_tabbar->setPosition(position);
}
void KateTabsPluginView::slotOpenDocument(int index)
{
mainWindow()->activateView(m_tabbar->documentFromIndex(index));
}
void KateTabsPluginView::slotActivateDocument()
{
if (mainWindow()->activeView()) {
m_tabbar->activateDocument(mainWindow()->activeView()->document());
}
}
void KateTabsPluginView::slotCloseDocumentByIndex(int index)
{
KTextEditor::Document *document = m_tabbar->documentFromIndex(index);
Kate::application()->documentManager()->closeDocument(document);
}