OSDN Git Service

0b53bba595b044eec5d79f836c94b75ab1625faf
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / editormanager / editormanager.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef EDITORMANAGER_H
35 #define EDITORMANAGER_H
36
37 #include "../core_global.h"
38
39 #include <coreplugin/ifile.h> // enumerations
40
41 #include <QtGui/QWidget>
42 #include <QtCore/QList>
43
44 QT_BEGIN_NAMESPACE
45 class QModelIndex;
46 QT_END_NAMESPACE
47
48 namespace Core {
49
50 class IContext;
51 class ICore;
52 class IEditor;
53 class IEditorFactory;
54 class IExternalEditor;
55 class MimeType;
56 class IFile;
57 class IMode;
58 class IVersionControl;
59
60 class EditorToolBar;
61
62 enum MakeWritableResult {
63     OpenedWithVersionControl,
64     MadeWritable,
65     SavedAs,
66     Failed
67 };
68
69 struct EditorManagerPrivate;
70 class OpenEditorsModel;
71
72 namespace Internal {
73 class OpenEditorsWindow;
74 class EditorView;
75 class SplitterOrView;
76
77 class EditorClosingCoreListener;
78 class OpenEditorsViewFactory;
79
80
81 } // namespace Internal
82
83 class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
84 {
85     Q_OBJECT
86 public:
87     explicit EditorManagerPlaceHolder(Core::IMode *mode, QWidget *parent = 0);
88     ~EditorManagerPlaceHolder();
89     static EditorManagerPlaceHolder* current();
90 private slots:
91     void currentModeChanged(Core::IMode *);
92 private:
93     Core::IMode *m_mode;
94     static EditorManagerPlaceHolder* m_current;
95 };
96
97 class CORE_EXPORT EditorManager : public QWidget
98 {
99     Q_OBJECT
100
101 public:
102     typedef QList<IEditorFactory*> EditorFactoryList;
103     typedef QList<IExternalEditor*> ExternalEditorList;
104
105     explicit EditorManager(ICore *core, QWidget *parent);
106     virtual ~EditorManager();
107     void init();
108     static EditorManager *instance() { return m_instance; }
109
110     static EditorToolBar *createToolBar(QWidget *parent = 0);
111
112     enum OpenEditorFlag {
113         NoActivate = 1,
114         IgnoreNavigationHistory = 2,
115         ModeSwitch = 4,
116         CanContainLineNumber = 8
117     };
118     Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
119
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());
127
128     bool openExternalEditor(const QString &fileName, const QString &editorId);
129
130     QStringList getOpenFileNames() const;
131     QString getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
132
133     bool hasEditor(const QString &fileName) const;
134     QList<IEditor *> editorsForFileName(const QString &filename) const;
135     QList<IEditor *> editorsForFile(IFile *file) const;
136
137     IEditor *currentEditor() const;
138     QList<IEditor *> visibleEditors() const;
139     QList<IEditor*> openedEditors() const;
140
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);
144
145     OpenEditorsModel *openedEditorsModel() const;
146     void closeEditor(const QModelIndex &index);
147     void closeOtherEditors(IEditor *editor);
148
149     QList<IEditor*> editorsForFiles(QList<IFile*> files) const;
150     void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
151     void cutForwardNavigationHistory();
152
153     bool saveEditor(IEditor *editor);
154
155     bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
156
157     MakeWritableResult makeFileWritable(IFile *file);
158
159     QByteArray saveState() const;
160     bool restoreState(const QByteArray &state);
161     bool hasSplitter() const;
162
163     void saveSettings();
164     void readSettings();
165
166     Internal::OpenEditorsWindow *windowPopup() const;
167     void showPopupOrSelectDocument() const;
168
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);
174
175     void hideEditorInfoBar(const QString &id);
176
177     void showEditorStatusBar(const QString &id,
178                            const QString &infoText,
179                            const QString &buttonText = QString(),
180                            QObject *object = 0, const char *member = 0);
181
182     void hideEditorStatusBar(const QString &id);
183
184     EditorFactoryList editorFactories(const MimeType &mimeType, bool bestMatchOnly = true) const;
185     ExternalEditorList externalEditors(const MimeType &mimeType, bool bestMatchOnly = true) const;
186
187     void setReloadSetting(IFile::ReloadSetting behavior);
188     IFile::ReloadSetting reloadSetting() const;
189
190     QTextCodec *defaultTextCodec() const;
191
192     static qint64 maxTextFileSize();
193
194     void setWindowTitleAddition(const QString &addition);
195     QString windowTitleAddition() const;
196
197 signals:
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);
204
205 public slots:
206     bool closeAllEditors(bool askAboutModifiedEditors = true);
207
208     bool saveFile(Core::IFile *file = 0);
209     bool saveFileAs(Core::IFile *file = 0);
210     void revertToSaved();
211     void closeEditor();
212     void closeOtherEditors();
213
214 private slots:
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);
223
224 public slots:
225     void goBackInNavigationHistory();
226     void goForwardInNavigationHistory();
227     void split(Qt::Orientation orientation);
228     void split();
229     void splitSideBySide();
230     void removeCurrentSplit();
231     void removeAllSplits();
232     void gotoOtherSplit();
233
234 private:
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);
240
241     void restoreEditorState(IEditor *editor);
242
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;
254
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();
263
264     static EditorManager *m_instance;
265     EditorManagerPrivate *m_d;
266
267     friend class Core::Internal::SplitterOrView;
268     friend class Core::Internal::EditorView;
269     friend class Core::EditorToolBar;
270 };
271
272 } // namespace Core
273
274 Q_DECLARE_OPERATORS_FOR_FLAGS(Core::EditorManager::OpenEditorFlags)
275 #endif // EDITORMANAGER_H