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 **************************************************************************/
36 #include <coreplugin/core_global.h>
38 #include <QtCore/QObject>
39 #include <QtCore/QStringList>
40 #include <QtCore/QPair>
41 #include <QtCore/QVariant>
52 class IVersionControl;
55 struct FileManagerPrivate;
58 class CORE_EXPORT FileManager : public QObject
67 typedef QPair<QString, QString> RecentFile;
69 explicit FileManager(QMainWindow *ew);
70 virtual ~FileManager();
72 static FileManager *instance();
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;
80 void renamedFile(const QString &from, const QString &to);
82 void blockFileChange(IFile *file);
83 void unblockFileChange(IFile *file);
85 void expectFileChange(const QString &fileName);
86 void unexpectFileChange(const QString &fileName);
89 void addToRecentFiles(const QString &fileName, const QString &editorId = QString());
90 QList<RecentFile> recentFiles() const;
94 void setCurrentFile(const QString &filePath);
95 QString currentFile() const;
98 static QString fixFileName(const QString &fileName, FixMode fixmode);
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);
110 QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files);
111 QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
113 const QString &message = QString(),
114 const QString &alwaysSaveMessage = QString(),
115 bool *alwaysSave = 0);
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,
124 bool displaySaveAsButton = false);
126 QString fileDialogLastVisitedDirectory() const;
127 void setFileDialogLastVisitedDirectory(const QString &);
129 QString fileDialogInitialDirectory() const;
131 bool useProjectsDirectory() const;
132 void setUseProjectsDirectory(bool);
134 QString projectsDirectory() const;
135 void setProjectsDirectory(const QString &);
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);
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);
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);
159 void addFileInfo(IFile *file);
160 void addFileInfo(const QString &fileName, IFile *file, bool isLink);
161 void removeFileInfo(IFile *file);
163 void updateFileInfo(IFile *file);
164 void updateExpectedState(const QString &fileName);
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);
172 Internal::FileManagerPrivate *d;
175 /*! The FileChangeBlocker blocks all change notifications to all IFile * that
176 match the given filename. And unblocks in the destructor.
178 To also reload the IFile in the destructor class set modifiedReload to true
181 class CORE_EXPORT FileChangeBlocker
184 explicit FileChangeBlocker(const QString &fileName);
185 ~FileChangeBlocker();
187 const QString m_fileName;
188 Q_DISABLE_COPY(FileChangeBlocker)
193 Q_DECLARE_METATYPE(Core::FileManager::RecentFile)
195 #endif // FILEMANAGER_H