OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / filemanager.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 FILEMANAGER_H
34 #define FILEMANAGER_H
35
36 #include <coreplugin/core_global.h>
37
38 #include <QtCore/QObject>
39 #include <QtCore/QStringList>
40 #include <QtCore/QPair>
41 #include <QtCore/QVariant>
42
43 QT_BEGIN_NAMESPACE
44 class QMainWindow;
45 QT_END_NAMESPACE
46
47 namespace Core {
48
49 class ICore;
50 class IContext;
51 class IFile;
52 class IVersionControl;
53
54 namespace Internal {
55 struct FileManagerPrivate;
56 }
57
58 class CORE_EXPORT FileManager : public QObject
59 {
60     Q_OBJECT
61 public:
62     enum FixMode {
63         ResolveLinks,
64         KeepLinks
65     };
66
67     typedef QPair<QString, QString> RecentFile;
68
69     explicit FileManager(QMainWindow *ew);
70     virtual ~FileManager();
71
72     static FileManager *instance();
73
74     // file pool to monitor
75     void addFiles(const QList<IFile *> &files, bool addWatcher = true);
76     void addFile(IFile *file, bool addWatcher = true);
77     void removeFile(IFile *file);
78     QList<IFile *> modifiedFiles() const;
79
80     void renamedFile(const QString &from, const QString &to);
81
82     void blockFileChange(IFile *file);
83     void unblockFileChange(IFile *file);
84
85     void expectFileChange(const QString &fileName);
86     void unexpectFileChange(const QString &fileName);
87
88     // recent files
89     void addToRecentFiles(const QString &fileName, const QString &editorId = QString());
90     QList<RecentFile> recentFiles() const;
91     void saveSettings();
92
93     // current file
94     void setCurrentFile(const QString &filePath);
95     QString currentFile() const;
96
97     // helper methods
98     static QString fixFileName(const QString &fileName, FixMode fixmode);
99
100     QStringList getOpenFileNames(const QString &filters,
101                                  const QString path = QString(),
102                                  QString *selectedFilter = 0);
103     QString getSaveFileName(const QString &title, const QString &pathIn,
104                             const QString &filter = QString(), QString *selectedFilter = 0);
105     QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
106                                          const QString &filter);
107     QString getSaveAsFileName(IFile *file, const QString &filter = QString(),
108                               QString *selectedFilter = 0);
109
110     QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files);
111     QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
112                                      bool *cancelled = 0,
113                                      const QString &message = QString(),
114                                      const QString &alwaysSaveMessage = QString(),
115                                      bool *alwaysSave = 0);
116
117
118     // Helper to display a message dialog when encountering a read-only
119     // file, prompting the user about how to make it writeable.
120     enum ReadOnlyAction { RO_Cancel, RO_OpenVCS, RO_MakeWriteable, RO_SaveAs };
121     static ReadOnlyAction promptReadOnlyFile(const QString &fileName,
122                                              const IVersionControl *versionControl,
123                                              QWidget *parent,
124                                              bool displaySaveAsButton = false);
125
126     QString fileDialogLastVisitedDirectory() const;
127     void setFileDialogLastVisitedDirectory(const QString &);
128
129     QString fileDialogInitialDirectory() const;
130
131     bool useProjectsDirectory() const;
132     void setUseProjectsDirectory(bool);
133
134     QString projectsDirectory() const;
135     void setProjectsDirectory(const QString &);
136
137 public slots:
138     /* Used to notify e.g. the code model to update the given files. Does *not*
139        lead to any editors to reload or any other editor manager actions. */
140     void notifyFilesChangedInternally(const QStringList &files);
141
142 signals:
143     void currentFileChanged(const QString &filePath);
144     /* Used to notify e.g. the code model to update the given files. Does *not*
145        lead to any editors to reload or any other editor manager actions. */
146     void filesChangedInternally(const QStringList &files);
147
148 private slots:
149     void fileDestroyed(QObject *obj);
150     void checkForNewFileName();
151     void checkForReload();
152     void changedFile(const QString &file);
153     void mainWindowActivated();
154     void syncWithEditor(Core::IContext *context);
155
156 private:
157     void readSettings();
158     void dump();
159     void addFileInfo(IFile *file);
160     void addFileInfo(const QString &fileName, IFile *file, bool isLink);
161     void removeFileInfo(IFile *file);
162
163     void updateFileInfo(IFile *file);
164     void updateExpectedState(const QString &fileName);
165
166     QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
167                                bool *cancelled, bool silently,
168                                const QString &message,
169                                const QString &alwaysSaveMessage = QString(),
170                                bool *alwaysSave = 0);
171
172     Internal::FileManagerPrivate *d;
173 };
174
175 /*! The FileChangeBlocker blocks all change notifications to all IFile * that
176     match the given filename. And unblocks in the destructor.
177
178     To also reload the IFile in the destructor class set modifiedReload to true
179
180   */
181 class CORE_EXPORT FileChangeBlocker
182 {
183 public:
184     explicit FileChangeBlocker(const QString &fileName);
185     ~FileChangeBlocker();
186 private:
187     const QString m_fileName;
188     Q_DISABLE_COPY(FileChangeBlocker)
189 };
190
191 } // namespace Core
192
193 Q_DECLARE_METATYPE(Core::FileManager::RecentFile)
194
195 #endif // FILEMANAGER_H