1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef EDITORMANAGER_H
35 #define EDITORMANAGER_H
37 #include "../core_global.h"
39 #include <coreplugin/ifile.h> // enumerations
41 #include <QtGui/QWidget>
42 #include <QtCore/QList>
54 class IExternalEditor;
58 class IVersionControl;
62 enum MakeWritableResult {
63 OpenedWithVersionControl,
69 struct EditorManagerPrivate;
70 class OpenEditorsModel;
73 class OpenEditorsWindow;
77 class EditorClosingCoreListener;
78 class OpenEditorsViewFactory;
81 } // namespace Internal
83 class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
87 explicit EditorManagerPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
88 ~EditorManagerPlaceHolder();
89 static EditorManagerPlaceHolder* current();
91 void currentModeChanged(Core::IMode *);
94 static EditorManagerPlaceHolder* m_current;
97 class CORE_EXPORT EditorManager : public QWidget
102 typedef QList<IEditorFactory*> EditorFactoryList;
103 typedef QList<IExternalEditor*> ExternalEditorList;
105 explicit EditorManager(ICore *core, QWidget *parent);
106 virtual ~EditorManager();
108 static EditorManager *instance() { return m_instance; }
110 static EditorToolBar *createToolBar(QWidget *parent = 0);
112 enum OpenEditorFlag {
114 IgnoreNavigationHistory = 2,
116 CanContainLineNumber = 8
118 Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
120 IEditor *openEditor(const QString &fileName,
121 const QString &editorId = QString(),
122 OpenEditorFlags flags = 0,
123 bool *newEditor = 0);
124 IEditor *openEditorWithContents(const QString &editorId,
125 QString *titlePattern = 0,
126 const QString &contents = QString());
128 bool openExternalEditor(const QString &fileName, const QString &editorId);
130 QStringList getOpenFileNames() const;
131 QString getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
133 bool hasEditor(const QString &fileName) const;
134 QList<IEditor *> editorsForFileName(const QString &filename) const;
135 QList<IEditor *> editorsForFile(IFile *file) const;
137 IEditor *currentEditor() const;
138 QList<IEditor *> visibleEditors() const;
139 QList<IEditor*> openedEditors() const;
141 void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
142 void activateEditorForIndex(const QModelIndex &index, OpenEditorFlags = 0);
143 IEditor *activateEditorForFile(Core::Internal::EditorView *view, Core::IFile*file, OpenEditorFlags flags = 0);
145 OpenEditorsModel *openedEditorsModel() const;
146 void closeEditor(const QModelIndex &index);
147 void closeOtherEditors(IEditor *editor);
149 QList<IEditor*> editorsForFiles(QList<IFile*> files) const;
150 void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
151 void cutForwardNavigationHistory();
153 bool saveEditor(IEditor *editor);
155 bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
157 MakeWritableResult makeFileWritable(IFile *file);
159 QByteArray saveState() const;
160 bool restoreState(const QByteArray &state);
161 bool hasSplitter() const;
166 Internal::OpenEditorsWindow *windowPopup() const;
167 void showPopupOrSelectDocument() const;
169 void showEditorInfoBar(const QString &id,
170 const QString &infoText,
171 const QString &buttonText = QString(),
172 QObject *object = 0, const char *buttonPressMember = 0,
173 const char *cancelButtonPressMember = 0);
175 void hideEditorInfoBar(const QString &id);
177 void showEditorStatusBar(const QString &id,
178 const QString &infoText,
179 const QString &buttonText = QString(),
180 QObject *object = 0, const char *member = 0);
182 void hideEditorStatusBar(const QString &id);
184 EditorFactoryList editorFactories(const MimeType &mimeType, bool bestMatchOnly = true) const;
185 ExternalEditorList externalEditors(const MimeType &mimeType, bool bestMatchOnly = true) const;
187 void setReloadSetting(IFile::ReloadSetting behavior);
188 IFile::ReloadSetting reloadSetting() const;
190 QTextCodec *defaultTextCodec() const;
192 static qint64 maxTextFileSize();
194 void setWindowTitleAddition(const QString &addition);
195 QString windowTitleAddition() const;
198 void currentEditorChanged(Core::IEditor *editor);
199 void currentEditorStateChanged(Core::IEditor *editor);
200 void editorCreated(Core::IEditor *editor, const QString &fileName);
201 void editorOpened(Core::IEditor *editor);
202 void editorAboutToClose(Core::IEditor *editor);
203 void editorsClosed(QList<Core::IEditor *> editors);
206 bool closeAllEditors(bool askAboutModifiedEditors = true);
208 bool saveFile(Core::IFile *file = 0);
209 bool saveFileAs(Core::IFile *file = 0);
210 void revertToSaved();
212 void closeOtherEditors();
215 void gotoNextDocHistory();
216 void gotoPreviousDocHistory();
217 void handleContextChange(Core::IContext *context);
218 void updateActions();
219 void makeCurrentEditorWritable();
220 void updateWindowTitle();
221 void handleEditorStateChange();
222 void updateVariable(const QString &variable);
225 void goBackInNavigationHistory();
226 void goForwardInNavigationHistory();
227 void split(Qt::Orientation orientation);
229 void splitSideBySide();
230 void removeCurrentSplit();
231 void removeAllSplits();
232 void gotoOtherSplit();
235 QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
236 IEditor *createEditor(const QString &mimeType = QString(),
237 const QString &fileName = QString());
238 void addEditor(IEditor *editor, bool isDuplicate = false);
239 void removeEditor(IEditor *editor);
241 void restoreEditorState(IEditor *editor);
243 IEditor *placeEditor(Core::Internal::EditorView *view, Core::IEditor *editor);
244 Core::IEditor *duplicateEditor(IEditor *editor);
245 void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
246 void setCurrentView(Core::Internal::SplitterOrView *view);
247 IEditor *activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags = 0);
248 void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0);
249 IEditor *openEditor(Core::Internal::EditorView *view, const QString &fileName,
250 const QString &editorId = QString(),
251 OpenEditorFlags flags = 0,
252 bool *newEditor = 0);
253 Core::Internal::SplitterOrView *currentSplitterOrView() const;
255 void closeEditor(Core::IEditor *editor);
256 void closeDuplicate(Core::IEditor *editor);
257 void closeView(Core::Internal::EditorView *view);
258 void emptyView(Core::Internal::EditorView *view);
259 Core::Internal::EditorView *currentEditorView() const;
260 IEditor *pickUnusedEditor() const;
261 void addFileToRecentFiles(IFile *file);
262 void switchToPreferedMode();
264 static EditorManager *m_instance;
265 EditorManagerPrivate *m_d;
267 friend class Core::Internal::SplitterOrView;
268 friend class Core::Internal::EditorView;
269 friend class Core::EditorToolBar;
274 Q_DECLARE_OPERATORS_FOR_FLAGS(Core::EditorManager::OpenEditorFlags)
275 #endif // EDITORMANAGER_H