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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
/***************************************************************************
plugin_katetabbarextension.h
-------------------
begin : 2004-04-20
copyright : (C) 2004 by Dominik Haumann
email : dhdev@gmx.de
***************************************************************************/
/***************************************************************************
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/
#ifndef _PLUGIN_TABBAREXTENSION_H_
#define _PLUGIN_TABBAREXTENSION_H_
#include <kate/application.h>
#include <kate/documentmanager.h>
#include <kate/document.h>
#include <kate/mainwindow.h>
#include <kate/plugin.h>
#include <kate/view.h>
#include <kate/viewmanager.h>
#include <kate/pluginconfiginterface.h>
#include <kate/pluginconfiginterfaceextension.h>
#include <klibloader.h>
#include <tdelocale.h>
#include <tdetoolbar.h>
#include <tqwidget.h>
#include <tqpushbutton.h>
#include <tqptrlist.h>
class TQBoxLayout;
class TQCheckBox;
class KateTabBarButton;
/**
* Same as TQPtrList. Only difference is: overwrite compareItems() for sorting reason.
*/
class MyPtrList : public TQPtrList <KateTabBarButton>
{
public:
MyPtrList() { TQPtrList<KateTabBarButton>(); }
virtual int compareItems ( TQPtrCollection::Item item1_, TQPtrCollection::Item item2_ );
};
class KatePluginFactory : public KLibFactory
{
Q_OBJECT
public:
KatePluginFactory() { s_instance = new TDEInstance( "kate" ); }
virtual ~KatePluginFactory() { delete s_instance; }
virtual TQObject* createObject(TQObject *parent = 0, const char *pname = 0,
const char *name = "TQObject", const TQStringList &args = TQStringList());
private:
static TDEInstance* s_instance;
};
/**
* This class implements a single tab. Every tab represents a document and shows
* the current flag (modified: true or false).
*/
class KateTabBarButton: public TQPushButton
{
Q_OBJECT
public:
/**
* constructor
* @param pViewManager pointer to kate's the view manager
* @param pDoc pointer to the document, that the tab button represents
* @param parent parent widget
* @param name name of the tab button
*/
KateTabBarButton(Kate::ViewManager* pViewManager, Kate::Document *pDoc,
TQWidget* parent = 0, const char * name = 0);
/**
* standard destructor (emtpy)
*/
~KateTabBarButton() {}
/**
* @return the unique document ID
*/
uint documentNumber() { return myDocID; }
/**
* @return the document pointer
*/
Kate::Document* document() { return doc; }
/**
* get the document's full name (eg. main.cpp), used for comparison
* @return the document's name
*/
TQString fullName() const;
/**
* negate the modified flag and change the button color
* (usually red or black)
*/
void triggerModified();
/**
* dirty flag indicates whether the file was modified on disk
* @param d if true, a small warning icon appears
*/
void setDirty(bool d);
/**
* set text for this tab
* @param newText new text
*/
virtual void setText(const TQString& newText);
/**
* mouse release event handler to provide middle click functionality
* @param e the mouse event
*/
virtual void mouseReleaseEvent(TQMouseEvent *e);
signals:
/**
* signal that is only emitted when the toggle button toggles to state 'on'
* @param tab pointer to the button that emitted the signal
*/
void myToggled(KateTabBarButton* tab);
/**
* signal emitted when the middle button is pressed
* @param tab pointer to the button that emitted the signal
*/
void middleButtonPressed(KateTabBarButton* tab);
public slots:
/**
* control the ToggleButton
* @param on if true, the button is toggled on
*/
virtual void setOn(bool on);
private:
bool modified; ///< if true, doc is modified
uint myDocID; ///< unique document ID
Kate::Document *doc; ///< pointer to the doc
Kate::ViewManager *viewManager; ///< pointer to the view manager
};
/**
* This class handels all tabs and implements a full-featured "tabbar".
*/
class KateTabBarExtension : public TQWidget
{
Q_OBJECT
public:
/**
* constructor
* @param pDocManager pointer to kate's document manager
* @param win pinter to the main window
* @param bHorizOrientation true, if orientation is Qt::Horizontal
* @param bSort true, if orientation is Qt::Horizontal
* @param parent parent widget
* @param name name of widget
* @param f widget flags
*/
KateTabBarExtension(Kate::DocumentManager *pDocManager,
Kate::MainWindow *win, bool bHorizOrientation, bool bSort,
bool bCloseOnMiddleClick, TQWidget *parent = 0,
const char *name = 0, WFlags f = 0);
/** standard destructor */
~KateTabBarExtension() {}
/**
* @return the tabbar's orientation
*/
Qt::Orientation orientation() const { return m_orientation; }
/**
* @return true, when sorting is alphabetically
*/
bool sortByName() const { return m_sort; }
/**
* set sorting type
* @param sbn if true, sort by filename.lower()
*/
void setSortByName(bool sbn);
/**
* sort all tabs
*/
void updateSort();
/**
* @return true when closing a document with mouse middle click is allowed
*/
bool closeOnMiddleClick() const { return m_closeOnMiddleClick; }
/**
* set flag to enable/disable "close document on mouse middle click" feature
* @param cmc true -> enabled, false -> disabled
*/
void setCloseOnMiddleClick(bool cmc) { m_closeOnMiddleClick = cmc; }
public slots:
/**
* called when a new document is created/loaded
* @param doc the new document
*/
void slotDocumentCreated (Kate::Document *doc);
/**
* called when an existing document is being deleted
* @param documentNumber ID of the document
*/
void slotDocumentDeleted (uint documentNumber);
/**
* called whenever the view changes
* @param v pointer to the button that represents the active view
*/
void slotActivateView(KateTabBarButton* v);
/**
* called when the document's modified flag changes
* @param doc the document
*/
void slotModChanged (Kate::Document *doc);
/**
* called when the document changed on disk [NOT SUPPORTED AT THE MOMENT]
* @param doc the document
* @param b modified flag
* @param reason the reason why the file changed
*/
void slotModifiedOnDisc (Kate::Document *doc, bool b, unsigned char reason);
/**
* called when the document's name changed
* @param doc the document
*/
void slotNameChanged (Kate::Document *doc);
/**
* called when the active view changes
*/
void slotViewChanged ();
/**
* called whenever the toolbar's orientation changes
* @param o new orientation [Qt::Horizontal or Qt::Vertical]
*/
void slotMoved(Qt::Orientation o);
/**
* called when we want to close the document associated with the tab
* @param tab pointer to the button that represents the active view
*/
void slotRequestDocClose(KateTabBarButton *tab);
private:
KateTabBarButton* pCurrentTab; ///< pointer to the current tab
TQBoxLayout* top; ///< layout that contains all tabs
Kate::MainWindow* m_win; ///< pointer to the main window
Kate::DocumentManager* m_docManager; ///< pointer to the document manager
// TQPtrList <KateTabBarButton> m_tabs; ///< list containing all tabs
MyPtrList m_tabs; ///< list containing all tabs
Qt::Orientation m_orientation; ///< save tabbar's orientation
bool m_sort; ///< how to sort
bool m_closeOnMiddleClick; ///< Enable/disable "close document on mouse middle click" feature
};
/**
* The tabbar's config page
*/
class KateTabBarExtensionConfigPage : public Kate::PluginConfigPage
{
Q_OBJECT
friend class KatePluginTabBarExtension;
public:
KateTabBarExtensionConfigPage(TQObject* parent = 0L, TQWidget *parentWidget = 0L);
~KateTabBarExtensionConfigPage() {}
/**
* Reimplemented from Kate::PluginConfigPage
* just emits configPageApplyRequest( this ).
*/
virtual void apply() { emit configPageApplyRequest(this); }
virtual void reset() {}
virtual void defaults() {}
signals:
/**
* Ask the plugin to set initial values
*/
void configPageApplyRequest( KateTabBarExtensionConfigPage* );
/**
* Ask the plugin to apply changes
*/
void configPageInitRequest( KateTabBarExtensionConfigPage* );
private:
TQCheckBox* pSortAlpha;
TQCheckBox* pCloseOnMiddleClick;
};
class KatePluginTabBarExtension : public Kate::Plugin, Kate::PluginViewInterface, Kate::PluginConfigInterfaceExtension
{
Q_OBJECT
public:
KatePluginTabBarExtension(TQObject* parent = 0, const char* name = 0);
virtual ~KatePluginTabBarExtension();
void addView (Kate::MainWindow *win);
void removeView (Kate::MainWindow *win);
uint configPages () const { return 1; }
Kate::PluginConfigPage *configPage (uint , TQWidget *w, const char *name=0);
TQString configPageName(uint) const { return i18n("Tab Bar Extension"); }
TQString configPageFullName(uint) const { return i18n("Configure Tab Bar Extension"); }
TQPixmap configPagePixmap (uint = 0, int = TDEIcon::SizeSmall) const { return 0L; }
public slots:
void applyConfig( KateTabBarExtensionConfigPage* );
private:
void initConfigPage( KateTabBarExtensionConfigPage* );
private:
TQPtrList<class PluginView> m_views;
TDEConfig* pConfig;
};
#endif // _PLUGIN_TABBAREXTENSION_H_
|