OSDN Git Service

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