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
|
/***************************************************************************
* Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org> *
* Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr> *
* *
* 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. *
***************************************************************************/
#ifndef EDITOR_MANAGER_H
#define EDITOR_MANAGER_H
class QEvent;
#include <ktabbar.h>
#include <ktabwidget.h>
#include <klineedit.h>
#include "text_editor.h"
#include "common/gui/misc_gui.h"
#include "common/gui/dialog.h"
//-----------------------------------------------------------------------------
class SwitchToDialog : public Dialog
{
Q_OBJECT
public:
SwitchToDialog(const QStringList &names, QWidget *parent);
QString name() const { return _edit->text(); }
private:
KLineEdit *_edit;
};
//-----------------------------------------------------------------------------
class EditorTabBar : public TabBar
{
Q_OBJECT
public:
EditorTabBar(QWidget *parent) : TabBar(parent, "editor_tab_bar") {}
void setReadOnly(uint index, bool readOnly) { _readOnly[tabAt(index)] = readOnly; }
private:
QMap<QTab *, bool> _readOnly;
virtual void paintLabel(QPainter *p, const QRect &br, QTab *t, bool has_focus) const;
};
//-----------------------------------------------------------------------------
class EditorHistory
{
public:
EditorHistory() : _current(0) {}
bool hasBack() const { return _current!=0; }
bool hasForward() const { return (_current+1)<_names.count(); }
void add(const QString &name);
void closedLast();
QString goBack();
QString goForward();
private:
uint _current;
QValueVector<QString> _names;
};
//-----------------------------------------------------------------------------
class EditorManager : public TabWidget
{
Q_OBJECT
public:
EditorManager(QWidget *parent);
PURL::UrlList files() const;
QValueList<Editor *> &editors() { return _editors; }
uint nbEditors() const { return _editors.count(); }
Editor *createEditor(PURL::FileType type, const PURL::Url &url);
void addEditor(Editor *e);
Editor *currentEditor() const { return _current; }
Editor *findEditor(const PURL::Url &file);
Editor *findEditor(const QString &tag);
void showEditor(Editor *e);
bool closeEditor(const PURL::Url &url);
bool closeEditor(Editor *e, bool ask);
bool openFile(const PURL::Url &url);
Editor *openEditor(const PURL::Url &url);
void connectEditor(Editor *editor);
void disconnectEditor(Editor *editor);
const EditorHistory &history() const { return _history; }
enum EditorType { DeviceEditor = 0, RegisterEditor, Nb_EditorTypes };
Editor *openEditor(EditorType type);
public slots:
void updateTitles();
void slotDropEvent(QDropEvent *e);
void saveAllFiles();
bool closeCurrentEditor();
bool closeAllEditors();
bool closeAllOtherEditors();
void switchHeaderImplementation();
void switchToEditor();
void goBack();
void goForward();
signals:
void modified(const PURL::Url &url);
void guiChanged();
void statusChanged(const QString &);
private:
void changeToEditor(Editor *e);
void enableActions(bool enable);
QString title(const Editor &e) const;
QString name(const Editor &e) const;
virtual void contextMenu(int i, const QPoint &p);
void saveBookmarks(const Editor &e);
void restoreBookmarks(Editor &e);
private slots:
void showEditor(QWidget *w) { showEditor(static_cast<Editor *>(w)); }
void closeRequest(int i);
void modifiedSlot();
private:
Editor *_current;
QValueList<Editor *> _editors;
EditorHistory _history;
static const char * const EDITOR_TAGS[Nb_EditorTypes];
};
#endif
|