editormanager.h 8.96 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33 34 35 36 37
#ifndef EDITORMANAGER_H
#define EDITORMANAGER_H

#include "../core_global.h"

hjk's avatar
hjk committed
38
#include <coreplugin/id.h>
39
#include <coreplugin/ifile.h> // enumerations
con's avatar
con committed
40 41

#include <QtCore/QList>
42 43
#include <QtGui/QWidget>
#include <QtGui/QMenu>
con's avatar
con committed
44 45

QT_BEGIN_NAMESPACE
46
class QModelIndex;
con's avatar
con committed
47 48 49 50 51 52 53
QT_END_NAMESPACE

namespace Core {

class IContext;
class IEditor;
class IEditorFactory;
54
class IExternalEditor;
con's avatar
con committed
55 56 57
class MimeType;
class IFile;
class IMode;
58
class IVersionControl;
con's avatar
con committed
59

Lasse Holmstedt's avatar
Lasse Holmstedt committed
60
class EditorToolBar;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
61

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

struct EditorManagerPrivate;
70
class OpenEditorsModel;
71

con's avatar
con committed
72 73
namespace Internal {
class OpenEditorsWindow;
mae's avatar
mae committed
74
class EditorView;
mae's avatar
mae committed
75
class SplitterOrView;
con's avatar
con committed
76 77 78

class EditorClosingCoreListener;
class OpenEditorsViewFactory;
mae's avatar
mae committed
79 80


con's avatar
con committed
81 82 83 84 85 86
} // namespace Internal

class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
{
    Q_OBJECT
public:
87
    explicit EditorManagerPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
con's avatar
con committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
    ~EditorManagerPlaceHolder();
    static EditorManagerPlaceHolder* current();
private slots:
    void currentModeChanged(Core::IMode *);
private:
    Core::IMode *m_mode;
    static EditorManagerPlaceHolder* m_current;
};

class CORE_EXPORT EditorManager : public QWidget
{
    Q_OBJECT

public:
hjk's avatar
hjk committed
102 103
    typedef QList<IEditorFactory *> EditorFactoryList;
    typedef QList<IExternalEditor *> ExternalEditorList;
con's avatar
con committed
104

hjk's avatar
hjk committed
105
    explicit EditorManager(QWidget *parent);
con's avatar
con committed
106 107
    virtual ~EditorManager();
    void init();
hjk's avatar
hjk committed
108
    static EditorManager *instance();
con's avatar
con committed
109

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

mae's avatar
mae committed
112 113
    enum OpenEditorFlag {
        NoActivate = 1,
114
        IgnoreNavigationHistory = 2,
115 116
        ModeSwitch = 4,
        CanContainLineNumber = 8
mae's avatar
mae committed
117 118 119
    };
    Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)

hjk's avatar
hjk committed
120 121 122 123
    IEditor *openEditor(const QString &fileName, const Id &editorId = Id(),
        OpenEditorFlags flags = 0, bool *newEditor = 0);
    IEditor *openEditorWithContents(const Id &editorId,
        QString *titlePattern = 0, const QString &contents = QString());
124

hjk's avatar
hjk committed
125
    bool openExternalEditor(const QString &fileName, const Id &editorId);
126

con's avatar
con committed
127
    QStringList getOpenFileNames() const;
hjk's avatar
hjk committed
128
    Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
con's avatar
con committed
129 130 131

    bool hasEditor(const QString &fileName) const;
    QList<IEditor *> editorsForFileName(const QString &filename) const;
132
    QList<IEditor *> editorsForFile(IFile *file) const;
con's avatar
con committed
133 134

    IEditor *currentEditor() const;
135 136 137
    QList<IEditor *> visibleEditors() const;
    QList<IEditor*> openedEditors() const;

138 139
    void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
    void activateEditorForIndex(const QModelIndex &index, OpenEditorFlags = 0);
hjk's avatar
hjk committed
140
    IEditor *activateEditorForFile(Internal::EditorView *view, IFile *file, OpenEditorFlags flags = 0);
con's avatar
con committed
141

142
    OpenEditorsModel *openedEditorsModel() const;
143
    void closeEditor(const QModelIndex &index);
144
    void closeOtherEditors(IEditor *editor);
145

hjk's avatar
hjk committed
146
    QList<IEditor*> editorsForFiles(QList<IFile *> files) const;
147
    void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
148
    void cutForwardNavigationHistory();
con's avatar
con committed
149 150 151

    bool saveEditor(IEditor *editor);

152
    bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
con's avatar
con committed
153

154
    MakeWritableResult makeFileWritable(IFile *file);
con's avatar
con committed
155 156 157

    QByteArray saveState() const;
    bool restoreState(const QByteArray &state);
hjk's avatar
hjk committed
158
    bool hasSplitter() const;
con's avatar
con committed
159

160 161
    void saveSettings();
    void readSettings();
con's avatar
con committed
162 163

    Internal::OpenEditorsWindow *windowPopup() const;
164
    void showPopupOrSelectDocument() const;
con's avatar
con committed
165

166
    void showEditorStatusBar(const QString &id,
167 168 169 170
                           const QString &infoText,
                           const QString &buttonText = QString(),
                           QObject *object = 0, const char *member = 0);

171
    void hideEditorStatusBar(const QString &id);
172

con's avatar
con committed
173
    EditorFactoryList editorFactories(const MimeType &mimeType, bool bestMatchOnly = true) const;
174
    ExternalEditorList externalEditors(const MimeType &mimeType, bool bestMatchOnly = true) const;
con's avatar
con committed
175

176 177
    void setReloadSetting(IFile::ReloadSetting behavior);
    IFile::ReloadSetting reloadSetting() const;
178

179 180 181 182 183
    void setAutoSaveEnabled(bool enabled);
    bool autoSaveEnabled() const;
    void setAutoSaveInterval(int interval);
    int autoSaveInterval() const;

184
    QTextCodec *defaultTextCodec() const;
185

186 187
    static qint64 maxTextFileSize();

188 189 190
    void setWindowTitleAddition(const QString &addition);
    QString windowTitleAddition() const;

191
    void addCloseEditorActions(QMenu *contextMenu, const QModelIndex &editorIndex);
Robert Loehning's avatar
Robert Loehning committed
192
    void addNativeDirActions(QMenu *contextMenu, const QModelIndex &editorIndex);
193

con's avatar
con committed
194 195
signals:
    void currentEditorChanged(Core::IEditor *editor);
196
    void currentEditorStateChanged(Core::IEditor *editor);
con's avatar
con committed
197 198 199 200 201 202 203 204
    void editorCreated(Core::IEditor *editor, const QString &fileName);
    void editorOpened(Core::IEditor *editor);
    void editorAboutToClose(Core::IEditor *editor);
    void editorsClosed(QList<Core::IEditor *> editors);

public slots:
    bool closeAllEditors(bool askAboutModifiedEditors = true);

205 206
    bool saveFile(Core::IFile *file = 0);
    bool saveFileAs(Core::IFile *file = 0);
207
    void revertToSaved();
con's avatar
con committed
208
    void closeEditor();
con's avatar
con committed
209
    void closeOtherEditors();
mae's avatar
mae committed
210

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

223 224 225
    void closeEditorFromContextMenu();
    void closeOtherEditorsFromContextMenu();

Robert Loehning's avatar
Robert Loehning committed
226 227 228
    void showInGraphicalShell();
    void openTerminal();

mae's avatar
mae committed
229
public slots:
230 231
    void goBackInNavigationHistory();
    void goForwardInNavigationHistory();
232
    void split(Qt::Orientation orientation);
233 234
    void split();
    void splitSideBySide();
235 236 237
    void removeCurrentSplit();
    void removeAllSplits();
    void gotoOtherSplit();
con's avatar
con committed
238 239 240

private:
    QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
hjk's avatar
hjk committed
241
    IEditor *createEditor(const Id &id = Id(), const QString &fileName = QString());
mae's avatar
mae committed
242 243
    void addEditor(IEditor *editor, bool isDuplicate = false);
    void removeEditor(IEditor *editor);
con's avatar
con committed
244 245 246

    void restoreEditorState(IEditor *editor);

hjk's avatar
hjk committed
247 248
    IEditor *placeEditor(Internal::EditorView *view, IEditor *editor);
    IEditor *duplicateEditor(IEditor *editor);
mae's avatar
mae committed
249
    void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
hjk's avatar
hjk committed
250 251
    void setCurrentView(Internal::SplitterOrView *view);
    IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = 0);
252
    void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0);
hjk's avatar
hjk committed
253
    IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
hjk's avatar
hjk committed
254
        const Id &id = Id(), OpenEditorFlags flags = 0, bool *newEditor = 0);
hjk's avatar
hjk committed
255
    Internal::SplitterOrView *currentSplitterOrView() const;
256
    Internal::SplitterOrView *topSplitterOrView() const;
mae's avatar
mae committed
257

hjk's avatar
hjk committed
258 259 260 261 262
    void closeEditor(IEditor *editor);
    void closeDuplicate(IEditor *editor);
    void closeView(Internal::EditorView *view);
    void emptyView(Internal::EditorView *view);
    Internal::EditorView *currentEditorView() const;
mae's avatar
mae committed
263
    IEditor *pickUnusedEditor() const;
264
    void addFileToRecentFiles(IFile *file);
265
    void switchToPreferedMode();
266
    void updateAutoSave();
267
    void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
mae's avatar
mae committed
268

hjk's avatar
hjk committed
269
    EditorManagerPrivate *d;
mae's avatar
mae committed
270 271

    friend class Core::Internal::SplitterOrView;
mae's avatar
mae committed
272
    friend class Core::Internal::EditorView;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
273
    friend class Core::EditorToolBar;
con's avatar
con committed
274 275
};

276 277
} // namespace Core

278
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::EditorManager::OpenEditorFlags)
hjk's avatar
hjk committed
279

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