1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef EDITORMANAGER_H
34 #define EDITORMANAGER_H
36 #include "../core_global.h"
38 #include <coreplugin/ifile.h> // enumerations
40 #include <QtGui/QWidget>
41 #include <QtCore/QList>
53 class IExternalEditor;
57 class IVersionControl;
61 enum MakeWritableResult {
62 OpenedWithVersionControl,
68 struct EditorManagerPrivate;
69 class OpenEditorsModel;
72 class OpenEditorsWindow;
76 class EditorClosingCoreListener;
77 class OpenEditorsViewFactory;
80 } // namespace Internal
82 class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
86 explicit EditorManagerPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
87 ~EditorManagerPlaceHolder();
88 static EditorManagerPlaceHolder* current();
90 void currentModeChanged(Core::IMode *);
93 static EditorManagerPlaceHolder* m_current;
96 class CORE_EXPORT EditorManager : public QWidget
101 typedef QList<IEditorFactory*> EditorFactoryList;
102 typedef QList<IExternalEditor*> ExternalEditorList;
104 explicit EditorManager(ICore *core, QWidget *parent);
105 virtual ~EditorManager();
107 static EditorManager *instance() { return m_instance; }
109 static EditorToolBar *createToolBar(QWidget *parent = 0);
111 enum OpenEditorFlag {
113 IgnoreNavigationHistory = 2,
115 CanContainLineNumber = 8
117 Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
119 IEditor *openEditor(const QString &fileName,
120 const QString &editorId = QString(),
121 OpenEditorFlags flags = 0,
122 bool *newEditor = 0);
123 IEditor *openEditorWithContents(const QString &editorId,
124 QString *titlePattern = 0,
125 const QString &contents = QString());
127 bool openExternalEditor(const QString &fileName, const QString &editorId);
129 QStringList getOpenFileNames() const;
130 QString getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
132 bool hasEditor(const QString &fileName) const;
133 QList<IEditor *> editorsForFileName(const QString &filename) const;
134 QList<IEditor *> editorsForFile(IFile *file) const;
136 IEditor *currentEditor() const;
137 QList<IEditor *> visibleEditors() const;
138 QList<IEditor*> openedEditors() const;
140 void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
141 void activateEditorForIndex(const QModelIndex &index, OpenEditorFlags = 0);
142 IEditor *activateEditorForFile(Core::Internal::EditorView *view, Core::IFile*file, OpenEditorFlags flags = 0);
144 OpenEditorsModel *openedEditorsModel() const;
145 void closeEditor(const QModelIndex &index);
146 void closeOtherEditors(IEditor *editor);
148 QList<IEditor*> editorsForFiles(QList<IFile*> files) const;
149 void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
150 void cutForwardNavigationHistory();
152 bool saveEditor(IEditor *editor);
154 bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
156 MakeWritableResult makeFileWritable(IFile *file);
158 QByteArray saveState() const;
159 bool restoreState(const QByteArray &state);
160 bool hasSplitter() const;
165 Internal::OpenEditorsWindow *windowPopup() const;
166 void showPopupOrSelectDocument() const;
168 void showEditorInfoBar(const QString &id,
169 const QString &infoText,
170 const QString &buttonText = QString(),
171 QObject *object = 0, const char *buttonPressMember = 0,
172 const char *cancelButtonPressMember = 0);
174 void hideEditorInfoBar(const QString &id);
176 void showEditorStatusBar(const QString &id,
177 const QString &infoText,
178 const QString &buttonText = QString(),
179 QObject *object = 0, const char *member = 0);
181 void hideEditorStatusBar(const QString &id);
183 EditorFactoryList editorFactories(const MimeType &mimeType, bool bestMatchOnly = true) const;
184 ExternalEditorList externalEditors(const MimeType &mimeType, bool bestMatchOnly = true) const;
186 void setReloadSetting(IFile::ReloadSetting behavior);
187 IFile::ReloadSetting reloadSetting() const;
189 QTextCodec *defaultTextCodec() const;
191 static qint64 maxTextFileSize();
193 void setWindowTitleAddition(const QString &addition);
194 QString windowTitleAddition() const;
197 void currentEditorChanged(Core::IEditor *editor);
198 void currentEditorStateChanged(Core::IEditor *editor);
199 void editorCreated(Core::IEditor *editor, const QString &fileName);
200 void editorOpened(Core::IEditor *editor);
201 void editorAboutToClose(Core::IEditor *editor);
202 void editorsClosed(QList<Core::IEditor *> editors);
205 bool closeAllEditors(bool askAboutModifiedEditors = true);
207 bool saveFile(Core::IFile *file = 0);
208 bool saveFileAs(Core::IFile *file = 0);
209 void revertToSaved();
211 void closeOtherEditors();
214 void gotoNextDocHistory();
215 void gotoPreviousDocHistory();
216 void handleContextChange(Core::IContext *context);
217 void updateActions();
218 void makeCurrentEditorWritable();
219 void updateWindowTitle();
220 void handleEditorStateChange();
221 void updateVariable(const QString &variable);
224 void goBackInNavigationHistory();
225 void goForwardInNavigationHistory();
226 void split(Qt::Orientation orientation);
228 void splitSideBySide();
229 void removeCurrentSplit();
230 void removeAllSplits();
231 void gotoOtherSplit();
234 QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
235 IEditor *createEditor(const QString &mimeType = QString(),
236 const QString &fileName = QString());
237 void addEditor(IEditor *editor, bool isDuplicate = false);
238 void removeEditor(IEditor *editor);
240 void restoreEditorState(IEditor *editor);
242 IEditor *placeEditor(Core::Internal::EditorView *view, Core::IEditor *editor);
243 Core::IEditor *duplicateEditor(IEditor *editor);
244 void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
245 void setCurrentView(Core::Internal::SplitterOrView *view);
246 IEditor *activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags = 0);
247 void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0);
248 IEditor *openEditor(Core::Internal::EditorView *view, const QString &fileName,
249 const QString &editorId = QString(),
250 OpenEditorFlags flags = 0,
251 bool *newEditor = 0);
252 Core::Internal::SplitterOrView *currentSplitterOrView() const;
254 void closeEditor(Core::IEditor *editor);
255 void closeDuplicate(Core::IEditor *editor);
256 void closeView(Core::Internal::EditorView *view);
257 void emptyView(Core::Internal::EditorView *view);
258 Core::Internal::EditorView *currentEditorView() const;
259 IEditor *pickUnusedEditor() const;
260 void addFileToRecentFiles(IFile *file);
261 void switchToPreferedMode();
263 static EditorManager *m_instance;
264 EditorManagerPrivate *m_d;
266 friend class Core::Internal::SplitterOrView;
267 friend class Core::Internal::EditorView;
268 friend class Core::EditorToolBar;
273 Q_DECLARE_OPERATORS_FOR_FLAGS(Core::EditorManager::OpenEditorFlags)
274 #endif // EDITORMANAGER_H