editormanager.h 10.9 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24
25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
33
34
#ifndef EDITORMANAGER_H
#define EDITORMANAGER_H

#include "../core_global.h"

35
#include "documentmodel.h"
36

hjk's avatar
hjk committed
37
#include <coreplugin/id.h>
38
#include <coreplugin/idocument.h> // enumerations
con's avatar
con committed
39

40
41
42
#include <QList>
#include <QWidget>
#include <QMenu>
con's avatar
con committed
43
44
45
46
47
48
49
50
51

QT_BEGIN_NAMESPACE
QT_END_NAMESPACE

namespace Core {

class IContext;
class IEditor;
class IEditorFactory;
52
class IExternalEditor;
con's avatar
con committed
53
class MimeType;
54
class IDocument;
con's avatar
con committed
55
class IMode;
56
class IVersionControl;
con's avatar
con committed
57

Lasse Holmstedt's avatar
Lasse Holmstedt committed
58
class EditorToolBar;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
59

con's avatar
con committed
60
61
62
63
64
65
66
67
68
enum MakeWritableResult {
    OpenedWithVersionControl,
    MadeWritable,
    SavedAs,
    Failed
};

namespace Internal {
class EditorClosingCoreListener;
69
70
class EditorView;
class MainWindow;
con's avatar
con committed
71
class OpenEditorsViewFactory;
72
73
class OpenEditorsWindow;
class SplitterOrView;
con's avatar
con committed
74
75
76
77
78
79
} // namespace Internal

class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
{
    Q_OBJECT
public:
80
    explicit EditorManagerPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
con's avatar
con committed
81
82
83
84
85
86
87
88
89
90
91
92
    ~EditorManagerPlaceHolder();
private slots:
    void currentModeChanged(Core::IMode *);
private:
    Core::IMode *m_mode;
};

class CORE_EXPORT EditorManager : public QWidget
{
    Q_OBJECT

public:
hjk's avatar
hjk committed
93
94
    typedef QList<IEditorFactory *> EditorFactoryList;
    typedef QList<IExternalEditor *> ExternalEditorList;
con's avatar
con committed
95

96
    static EditorManager *instance();
con's avatar
con committed
97

Lasse Holmstedt's avatar
Lasse Holmstedt committed
98
    static EditorToolBar *createToolBar(QWidget *parent = 0);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
99

mae's avatar
mae committed
100
    enum OpenEditorFlag {
101
        NoFlags = 0,
Eike Ziller's avatar
Eike Ziller committed
102
        DoNotChangeCurrentEditor = 1,
103
        IgnoreNavigationHistory = 2,
Eike Ziller's avatar
Eike Ziller committed
104
        DoNotMakeVisible = 4,
105
106
        CanContainLineNumber = 8,
        OpenInOtherSplit = 16
mae's avatar
mae committed
107
108
109
    };
    Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)

110
    static QString splitLineNumber(QString *fileName);
hjk's avatar
hjk committed
111
    static IEditor *openEditor(const QString &fileName, const Id &editorId = Id(),
112
        OpenEditorFlags flags = NoFlags, bool *newEditor = 0);
113
    static IEditor *openEditorAt(const QString &fileName,  int line, int column = 0,
114
                                 const Id &editorId = Id(), OpenEditorFlags flags = NoFlags,
115
                                 bool *newEditor = 0);
hjk's avatar
hjk committed
116
    static IEditor *openEditorWithContents(const Id &editorId,
117
        QString *titlePattern = 0, const QByteArray &contents = QByteArray());
118

hjk's avatar
hjk committed
119
    static bool openExternalEditor(const QString &fileName, const Id &editorId);
120

121
122
    static QStringList getOpenFileNames();
    static Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0);
con's avatar
con committed
123

124
    static IDocument *currentDocument();
hjk's avatar
hjk committed
125
    static IEditor *currentEditor();
126
    static QList<IEditor *> visibleEditors();
127

hjk's avatar
hjk committed
128
    static void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
129
130
131
    static void activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags = 0);
    static IEditor *activateEditorForDocument(IDocument *document, OpenEditorFlags flags = 0);
    static IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
con's avatar
con committed
132

133
    static DocumentModel *documentModel();
134
    static bool closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
135
136
    static void closeEditor(DocumentModel::Entry *entry);
    static void closeOtherEditors(IDocument *document);
137

138
139
    static void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
    static void cutForwardNavigationHistory();
con's avatar
con committed
140

141
    static bool saveEditor(IEditor *editor);
con's avatar
con committed
142

143
144
    static bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
    static void closeEditor(IEditor *editor, bool askAboutModifiedEditors = true);
con's avatar
con committed
145

146
    static MakeWritableResult makeFileWritable(IDocument *document);
con's avatar
con committed
147

148
149
150
    static QByteArray saveState();
    static bool restoreState(const QByteArray &state);
    static bool hasSplitter();
con's avatar
con committed
151

152
153
    static void saveSettings();
    static void readSettings();
con's avatar
con committed
154

155
156
    static Internal::OpenEditorsWindow *windowPopup();
    static void showPopupOrSelectDocument();
con's avatar
con committed
157

158
    static void showEditorStatusBar(const QString &id,
159
160
161
162
                           const QString &infoText,
                           const QString &buttonText = QString(),
                           QObject *object = 0, const char *member = 0);

163
    static void hideEditorStatusBar(const QString &id);
164

hjk's avatar
hjk committed
165
166
    static EditorFactoryList editorFactories(const MimeType &mimeType, bool bestMatchOnly = true);
    static ExternalEditorList externalEditors(const MimeType &mimeType, bool bestMatchOnly = true);
con's avatar
con committed
167

168
169
    static void setReloadSetting(IDocument::ReloadSetting behavior);
    static IDocument::ReloadSetting reloadSetting();
170

171
172
173
174
    static void setAutoSaveEnabled(bool enabled);
    static bool autoSaveEnabled();
    static void setAutoSaveInterval(int interval);
    static int autoSaveInterval();
175
    static bool isAutoSaveFile(const QString &fileName);
176

177
    static QTextCodec *defaultTextCodec();
178

179
180
    static qint64 maxTextFileSize();

181
182
    static void setWindowTitleAddition(const QString &addition);
    static QString windowTitleAddition();
183

Orgad Shaneh's avatar
Orgad Shaneh committed
184
185
186
    static void setWindowTitleVcsTopic(const QString &topic);
    static QString windowTitleVcsTopic();

187
188
    static void addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry);
    static void addNativeDirActions(QMenu *contextMenu, DocumentModel::Entry *entry);
189

con's avatar
con committed
190
191
signals:
    void currentEditorChanged(Core::IEditor *editor);
192
    void currentDocumentStateChanged();
con's avatar
con committed
193
194
195
196
    void editorCreated(Core::IEditor *editor, const QString &fileName);
    void editorOpened(Core::IEditor *editor);
    void editorAboutToClose(Core::IEditor *editor);
    void editorsClosed(QList<Core::IEditor *> editors);
197
    void findOnFileSystemRequest(const QString &path);
con's avatar
con committed
198
199

public slots:
200
    static bool closeAllEditors(bool askAboutModifiedEditors = true);
201
    static void closeAllEditorsExceptVisible();
con's avatar
con committed
202

203
204
205
206
207
208
209
    static bool saveDocument(Core::IDocument *documentParam = 0);
    static bool saveDocumentAs(Core::IDocument *documentParam = 0);
    static void revertToSaved();
    static void revertToSaved(IDocument *document);
    static void closeEditor();
    static void closeOtherEditors();
    static void doEscapeKeyFocusMoveMagic();
mae's avatar
mae committed
210

211
private slots:
212
213
214
215
216
217
218
    static void gotoNextDocHistory();
    static void gotoPreviousDocHistory();
    static void handleContextChange(const QList<Core::IContext *> &context);
    static void updateActions();
    static void makeCurrentEditorWritable();
    static void vcsOpenCurrentEditor();
    static void updateWindowTitle();
219
    void handleDocumentStateChange();
220
221
    static void updateVariable(const QByteArray &variable);
    static void autoSave();
mae's avatar
mae committed
222

223
224
225
    static void saveDocumentFromContextMenu();
    static void saveDocumentAsFromContextMenu();
    static void revertToSavedFromContextMenu();
226

227
228
    static void closeEditorFromContextMenu();
    static void closeOtherEditorsFromContextMenu();
229

230
231
    static void showInGraphicalShell();
    static void openTerminal();
232
    static void findInDirectory();
Robert Loehning's avatar
Robert Loehning committed
233

234
235
    static void rootDestroyed(QObject *root);
    static void setCurrentEditorFromContextChange();
236

237
    static void gotoNextSplit();
238

mae's avatar
mae committed
239
public slots:
240
241
242
243
244
245
246
247
248
    static void goBackInNavigationHistory();
    static void goForwardInNavigationHistory();
    static void split(Qt::Orientation orientation);
    static void split();
    static void splitSideBySide();
    static void splitNewWindow();
    static void removeCurrentSplit();
    static void removeAllSplits();
    static void gotoOtherSplit();
con's avatar
con committed
249
250

private:
251
    explicit EditorManager(QWidget *parent);
252
253
    ~EditorManager();
    static void init();
254

hjk's avatar
hjk committed
255
    static IEditor *createEditor(const Id &id = Id(), const QString &fileName = QString());
256
257
    static void addEditor(IEditor *editor);
    static void removeEditor(IEditor *editor);
con's avatar
con committed
258

259
    static void restoreEditorState(IEditor *editor);
con's avatar
con committed
260

261
262
    static IEditor *placeEditor(Internal::EditorView *view, IEditor *editor);
    static IEditor *duplicateEditor(IEditor *editor);
263
264
265
    static IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = NoFlags);
    static void activateEditorForEntry(Internal::EditorView *view, DocumentModel::Entry *entry,
                                       OpenEditorFlags flags = NoFlags);
266
267
    static void activateView(Internal::EditorView *view);
    static IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
268
        const Id &id = Id(), OpenEditorFlags flags = NoFlags, bool *newEditor = 0);
269
    static int visibleDocumentsCount();
270

271
272
273
    static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
    static void setCurrentView(Internal::EditorView *view);
    static Internal::EditorView *currentEditorView();
274
    static Internal::EditorView *viewForEditor(IEditor *editor);
275
    static Internal::SplitterOrView *findRoot(const Internal::EditorView *view, int *rootIndex = 0);
mae's avatar
mae committed
276

277
278
    static void closeView(Internal::EditorView *view);
    static void emptyView(Internal::EditorView *view);
279
    static void splitNewWindow(Internal::EditorView *view);
280
281
282
283
284
285
    static IEditor *pickUnusedEditor(Internal::EditorView **foundView = 0);
    static void addDocumentToRecentFiles(IDocument *document);
    static void updateAutoSave();
    static void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
    static void updateMakeWritableWarning();
    static void setupSaveActions(IDocument *document, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction);
mae's avatar
mae committed
286

287
    friend class Core::Internal::MainWindow;
mae's avatar
mae committed
288
    friend class Core::Internal::SplitterOrView;
mae's avatar
mae committed
289
    friend class Core::Internal::EditorView;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
290
    friend class Core::EditorToolBar;
con's avatar
con committed
291
292
};

293
294
} // namespace Core

295
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::EditorManager::OpenEditorFlags)
hjk's avatar
hjk committed
296

con's avatar
con committed
297
#endif // EDITORMANAGER_H