forked from qt-creator/qt-creator
Core::Filemanager: make some methods static
This follows suit to the ICore changes. Change-Id: Iba2de1b1e3f2574fd1459892eae702e6af1cc7dc Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
@@ -266,7 +266,7 @@ void ShortcutSettings::defaultAction()
|
||||
|
||||
void ShortcutSettings::exportAction()
|
||||
{
|
||||
QString fileName = FileManager::instance()->getSaveFileNameWithExtension(
|
||||
QString fileName = FileManager::getSaveFileNameWithExtension(
|
||||
tr("Export Keyboard Mapping Scheme"),
|
||||
ICore::resourcePath() + QLatin1String("/schemes/"),
|
||||
tr("Keyboard Mapping Scheme (*.kms)"));
|
||||
|
||||
@@ -536,7 +536,7 @@ void EditorManager::removeEditor(IEditor *editor)
|
||||
bool isDuplicate = d->m_editorModel->isDuplicate(editor);
|
||||
d->m_editorModel->removeEditor(editor);
|
||||
if (!isDuplicate)
|
||||
FileManager::instance()->removeFile(editor->file());
|
||||
FileManager::removeFile(editor->file());
|
||||
ICore::removeContextObject(editor);
|
||||
}
|
||||
|
||||
@@ -870,8 +870,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
||||
//ask whether to save modified files
|
||||
if (askAboutModifiedEditors) {
|
||||
bool cancelled = false;
|
||||
QList<IFile*> list = ICore::fileManager()->
|
||||
saveModifiedFiles(filesForEditors(acceptedEditors), &cancelled);
|
||||
QList<IFile*> list = FileManager::saveModifiedFiles(filesForEditors(acceptedEditors), &cancelled);
|
||||
if (cancelled)
|
||||
return false;
|
||||
if (!list.isEmpty()) {
|
||||
@@ -1206,10 +1205,9 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
|
||||
if (!isDuplicate) {
|
||||
const bool isTemporary = editor->isTemporary();
|
||||
const bool addWatcher = !isTemporary;
|
||||
ICore::fileManager()->addFile(editor->file(), addWatcher);
|
||||
FileManager::addFile(editor->file(), addWatcher);
|
||||
if (!isTemporary)
|
||||
ICore::fileManager()->addToRecentFiles(editor->file()->fileName(),
|
||||
editor->id());
|
||||
FileManager::addToRecentFiles(editor->file()->fileName(), editor->id());
|
||||
}
|
||||
emit editorOpened(editor);
|
||||
}
|
||||
@@ -1367,8 +1365,7 @@ QStringList EditorManager::getOpenFileNames() const
|
||||
{
|
||||
QString selectedFilter;
|
||||
const QString &fileFilters = ICore::mimeDatabase()->allFiltersString(&selectedFilter);
|
||||
return ICore::fileManager()->getOpenFileNames(fileFilters,
|
||||
QString(), &selectedFilter);
|
||||
return FileManager::getOpenFileNames(fileFilters, QString(), &selectedFilter);
|
||||
}
|
||||
|
||||
|
||||
@@ -1485,7 +1482,7 @@ bool EditorManager::saveFile(IFile *fileParam)
|
||||
bool isReadOnly;
|
||||
|
||||
// try saving, no matter what isReadOnly tells us
|
||||
success = ICore::fileManager()->saveFile(file, QString(), &isReadOnly);
|
||||
success = FileManager::saveFile(file, QString(), &isReadOnly);
|
||||
|
||||
if (!success && isReadOnly) {
|
||||
MakeWritableResult answer =
|
||||
@@ -1497,7 +1494,7 @@ bool EditorManager::saveFile(IFile *fileParam)
|
||||
|
||||
file->checkPermissions();
|
||||
|
||||
success = ICore::fileManager()->saveFile(file);
|
||||
success = FileManager::saveFile(file);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
@@ -1571,7 +1568,7 @@ bool EditorManager::saveFileAs(IFile *fileParam)
|
||||
QString selectedFilter =
|
||||
ICore::mimeDatabase()->findByFile(QFileInfo(file->fileName())).filterString();
|
||||
const QString &absoluteFilePath =
|
||||
ICore::fileManager()->getSaveAsFileName(file, filter, &selectedFilter);
|
||||
FileManager::getSaveAsFileName(file, filter, &selectedFilter);
|
||||
|
||||
if (absoluteFilePath.isEmpty())
|
||||
return false;
|
||||
@@ -1584,7 +1581,7 @@ bool EditorManager::saveFileAs(IFile *fileParam)
|
||||
}
|
||||
}
|
||||
|
||||
const bool success = ICore::fileManager()->saveFile(file, absoluteFilePath);
|
||||
const bool success = FileManager::saveFile(file, absoluteFilePath);
|
||||
file->checkPermissions();
|
||||
|
||||
// @todo: There is an issue to be treated here. The new file might be of a different mime
|
||||
@@ -1614,7 +1611,7 @@ void EditorManager::addFileToRecentFiles(IFile *file)
|
||||
}
|
||||
}
|
||||
if (!isTemporary)
|
||||
ICore::fileManager()->addToRecentFiles(file->fileName(), editorId);
|
||||
FileManager::addToRecentFiles(file->fileName(), editorId);
|
||||
}
|
||||
|
||||
void EditorManager::gotoNextDocHistory()
|
||||
|
||||
@@ -603,12 +603,12 @@ void ExternalToolRunner::run()
|
||||
if (IEditor *editor = EditorManager::instance()->currentEditor()) {
|
||||
m_expectedFileName = editor->file()->fileName();
|
||||
bool cancelled = false;
|
||||
FileManager::instance()->saveModifiedFiles(QList<IFile *>() << editor->file(), &cancelled);
|
||||
FileManager::saveModifiedFiles(QList<IFile *>() << editor->file(), &cancelled);
|
||||
if (cancelled) {
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
FileManager::instance()->expectFileChange(m_expectedFileName);
|
||||
FileManager::expectFileChange(m_expectedFileName);
|
||||
}
|
||||
}
|
||||
m_process = new Utils::QtcProcess(this);
|
||||
@@ -641,7 +641,7 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
|
||||
emit ExternalToolManager::instance()->replaceSelectionRequested(m_processOutput);
|
||||
}
|
||||
if (m_tool->modifiesCurrentDocument()) {
|
||||
FileManager::instance()->unexpectFileChange(m_expectedFileName);
|
||||
FileManager::unexpectFileChange(m_expectedFileName);
|
||||
}
|
||||
}
|
||||
ICore::messageManager()->printToOutputPane(
|
||||
@@ -651,9 +651,8 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
|
||||
|
||||
void ExternalToolRunner::error(QProcess::ProcessError error)
|
||||
{
|
||||
if (m_tool->modifiesCurrentDocument()) {
|
||||
FileManager::instance()->unexpectFileChange(m_expectedFileName);
|
||||
}
|
||||
if (m_tool->modifiesCurrentDocument())
|
||||
FileManager::unexpectFileChange(m_expectedFileName);
|
||||
// TODO inform about errors
|
||||
Q_UNUSED(error);
|
||||
deleteLater();
|
||||
|
||||
@@ -102,6 +102,15 @@ static const char useProjectDirectoryKeyC[] = "UseProjectsDirectory";
|
||||
|
||||
|
||||
namespace Core {
|
||||
|
||||
static void readSettings();
|
||||
|
||||
static QList<IFile *> saveModifiedFilesHelper(const QList<IFile *> &files,
|
||||
bool *cancelled, bool silently,
|
||||
const QString &message,
|
||||
const QString &alwaysSaveMessage = QString(),
|
||||
bool *alwaysSave = 0);
|
||||
|
||||
namespace Internal {
|
||||
|
||||
struct OpenWithEntry
|
||||
@@ -125,12 +134,12 @@ struct FileState
|
||||
};
|
||||
|
||||
|
||||
struct FileManagerPrivate {
|
||||
explicit FileManagerPrivate(FileManager *q, QMainWindow *mw);
|
||||
struct FileManagerPrivate
|
||||
{
|
||||
explicit FileManagerPrivate(QMainWindow *mw);
|
||||
QFileSystemWatcher *fileWatcher();
|
||||
QFileSystemWatcher *linkWatcher();
|
||||
|
||||
static FileManager *m_instance;
|
||||
QMap<QString, FileState> m_states;
|
||||
QSet<QString> m_changedFiles;
|
||||
QList<IFile *> m_filesWithoutWatch;
|
||||
@@ -156,6 +165,9 @@ struct FileManagerPrivate {
|
||||
IFile *m_blockedIFile;
|
||||
};
|
||||
|
||||
static FileManager *m_instance;
|
||||
static Internal::FileManagerPrivate *d;
|
||||
|
||||
QFileSystemWatcher *FileManagerPrivate::fileWatcher()
|
||||
{
|
||||
if (!m_fileWatcher) {
|
||||
@@ -181,9 +193,7 @@ QFileSystemWatcher *FileManagerPrivate::linkWatcher()
|
||||
#endif
|
||||
}
|
||||
|
||||
FileManager *FileManagerPrivate::m_instance = 0;
|
||||
|
||||
FileManagerPrivate::FileManagerPrivate(FileManager *q, QMainWindow *mw) :
|
||||
FileManagerPrivate::FileManagerPrivate(QMainWindow *mw) :
|
||||
m_mainWindow(mw),
|
||||
m_fileWatcher(0),
|
||||
m_linkWatcher(0),
|
||||
@@ -196,7 +206,6 @@ FileManagerPrivate::FileManagerPrivate(FileManager *q, QMainWindow *mw) :
|
||||
#endif
|
||||
m_blockedIFile(0)
|
||||
{
|
||||
m_instance = q;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
@@ -206,10 +215,13 @@ Q_DECLARE_METATYPE(Core::Internal::OpenWithEntry)
|
||||
|
||||
namespace Core {
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
FileManager::FileManager(QMainWindow *mw)
|
||||
: QObject(mw),
|
||||
d(new Internal::FileManagerPrivate(this, mw))
|
||||
: QObject(mw)
|
||||
{
|
||||
d = new FileManagerPrivate(mw);
|
||||
m_instance = this;
|
||||
connect(d->m_mainWindow, SIGNAL(windowActivated()),
|
||||
this, SLOT(mainWindowActivated()));
|
||||
connect(ICore::instance(), SIGNAL(contextChanged(Core::IContext*,Core::Context)),
|
||||
@@ -225,7 +237,46 @@ FileManager::~FileManager()
|
||||
|
||||
FileManager *FileManager::instance()
|
||||
{
|
||||
return Internal::FileManagerPrivate::m_instance;
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
/* only called from addFileInfo(IFile *) */
|
||||
static void addFileInfo(const QString &fileName, IFile *file, bool isLink)
|
||||
{
|
||||
FileStateItem state;
|
||||
if (!fileName.isEmpty()) {
|
||||
const QFileInfo fi(fileName);
|
||||
state.modified = fi.lastModified();
|
||||
state.permissions = fi.permissions();
|
||||
// Add watcher if we don't have that already
|
||||
if (!d->m_states.contains(fileName)) {
|
||||
d->m_states.insert(fileName, FileState());
|
||||
|
||||
}
|
||||
QFileSystemWatcher *watcher = 0;
|
||||
if (isLink)
|
||||
watcher = d->linkWatcher();
|
||||
else
|
||||
watcher = d->fileWatcher();
|
||||
if (!watcher->files().contains(fileName))
|
||||
watcher->addPath(fileName);
|
||||
|
||||
d->m_states[fileName].lastUpdatedState.insert(file, state);
|
||||
}
|
||||
d->m_filesWithWatch[file].append(fileName); // inserts a new QStringList if not already there
|
||||
}
|
||||
|
||||
/* Adds the IFile's file and possibly it's final link target to both m_states
|
||||
(if it's file name is not empty), and the m_filesWithWatch list,
|
||||
and adds a file watcher for each if not already done.
|
||||
(The added file names are guaranteed to be absolute and cleaned.) */
|
||||
static void addFileInfo(IFile *file)
|
||||
{
|
||||
const QString fixedName = FileManager::fixFileName(file->fileName(), FileManager::KeepLinks);
|
||||
const QString fixedResolvedName = FileManager::fixFileName(file->fileName(), FileManager::ResolveLinks);
|
||||
addFileInfo(fixedResolvedName, file, false);
|
||||
if (fixedName != fixedResolvedName)
|
||||
addFileInfo(fixedName, file, true);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -242,7 +293,7 @@ void FileManager::addFiles(const QList<IFile *> &files, bool addWatcher)
|
||||
|
||||
foreach (IFile *file, files) {
|
||||
if (file && !d->m_filesWithoutWatch.contains(file)) {
|
||||
connect(file, SIGNAL(destroyed(QObject *)), this, SLOT(fileDestroyed(QObject *)));
|
||||
connect(file, SIGNAL(destroyed(QObject *)), m_instance, SLOT(fileDestroyed(QObject *)));
|
||||
d->m_filesWithoutWatch.append(file);
|
||||
}
|
||||
}
|
||||
@@ -251,65 +302,51 @@ void FileManager::addFiles(const QList<IFile *> &files, bool addWatcher)
|
||||
|
||||
foreach (IFile *file, files) {
|
||||
if (file && !d->m_filesWithWatch.contains(file)) {
|
||||
connect(file, SIGNAL(changed()), this, SLOT(checkForNewFileName()));
|
||||
connect(file, SIGNAL(destroyed(QObject *)), this, SLOT(fileDestroyed(QObject *)));
|
||||
connect(file, SIGNAL(changed()), m_instance, SLOT(checkForNewFileName()));
|
||||
connect(file, SIGNAL(destroyed(QObject *)), m_instance, SLOT(fileDestroyed(QObject *)));
|
||||
addFileInfo(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Adds the IFile's file and possibly it's final link target to both m_states
|
||||
(if it's file name is not empty), and the m_filesWithWatch list,
|
||||
and adds a file watcher for each if not already done.
|
||||
(The added file names are guaranteed to be absolute and cleaned.) */
|
||||
void FileManager::addFileInfo(IFile *file)
|
||||
{
|
||||
const QString fixedName = fixFileName(file->fileName(), KeepLinks);
|
||||
const QString fixedResolvedName = fixFileName(file->fileName(), ResolveLinks);
|
||||
addFileInfo(fixedResolvedName, file, false);
|
||||
if (fixedName != fixedResolvedName)
|
||||
addFileInfo(fixedName, file, true);
|
||||
}
|
||||
|
||||
/* only called from addFileInfo(IFile *) */
|
||||
void FileManager::addFileInfo(const QString &fileName, IFile *file, bool isLink)
|
||||
/* Removes all occurrences of the IFile from m_filesWithWatch and m_states.
|
||||
If that results in a file no longer being referenced by any IFile, this
|
||||
also removes the file watcher.
|
||||
*/
|
||||
static void removeFileInfo(IFile *file)
|
||||
{
|
||||
Internal::FileStateItem state;
|
||||
if (!fileName.isEmpty()) {
|
||||
const QFileInfo fi(fileName);
|
||||
state.modified = fi.lastModified();
|
||||
state.permissions = fi.permissions();
|
||||
// Add watcher if we don't have that already
|
||||
if (!d->m_states.contains(fileName)) {
|
||||
d->m_states.insert(fileName, Internal::FileState());
|
||||
|
||||
if (!d->m_filesWithWatch.contains(file))
|
||||
return;
|
||||
foreach (const QString &fileName, d->m_filesWithWatch.value(file)) {
|
||||
if (!d->m_states.contains(fileName))
|
||||
continue;
|
||||
d->m_states[fileName].lastUpdatedState.remove(file);
|
||||
if (d->m_states.value(fileName).lastUpdatedState.isEmpty()) {
|
||||
if (d->m_fileWatcher && d->m_fileWatcher->files().contains(fileName))
|
||||
d->m_fileWatcher->removePath(fileName);
|
||||
if (d->m_linkWatcher && d->m_linkWatcher->files().contains(fileName))
|
||||
d->m_linkWatcher->removePath(fileName);
|
||||
d->m_states.remove(fileName);
|
||||
}
|
||||
QFileSystemWatcher *watcher = 0;
|
||||
if (isLink)
|
||||
watcher = d->linkWatcher();
|
||||
else
|
||||
watcher = d->fileWatcher();
|
||||
if (!watcher->files().contains(fileName))
|
||||
watcher->addPath(fileName);
|
||||
|
||||
d->m_states[fileName].lastUpdatedState.insert(file, state);
|
||||
}
|
||||
d->m_filesWithWatch[file].append(fileName); // inserts a new QStringList if not already there
|
||||
d->m_filesWithWatch.remove(file);
|
||||
}
|
||||
|
||||
/// Dumps the state of the file manager's map
|
||||
/// For debugging purposes
|
||||
void FileManager::dump()
|
||||
/*
|
||||
static void dump()
|
||||
{
|
||||
qDebug() << "======== dumping state map";
|
||||
QMap<QString, Internal::FileState>::const_iterator it, end;
|
||||
QMap<QString, FileState>::const_iterator it, end;
|
||||
it = d->m_states.constBegin();
|
||||
end = d->m_states.constEnd();
|
||||
for (; it != end; ++it) {
|
||||
qDebug() << it.key();
|
||||
qDebug() << " expected:" << it.value().expected.modified;
|
||||
|
||||
QMap<IFile *, Internal::FileStateItem>::const_iterator jt, jend;
|
||||
QMap<IFile *, FileStateItem>::const_iterator jt, jend;
|
||||
jt = it.value().lastUpdatedState.constBegin();
|
||||
jend = it.value().lastUpdatedState.constEnd();
|
||||
for (; jt != jend; ++jt) {
|
||||
@@ -327,6 +364,7 @@ void FileManager::dump()
|
||||
if (d->m_linkWatcher)
|
||||
qDebug() << d->m_linkWatcher->files();
|
||||
}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void FileManager::renamedFile(const QString &from, const QString &to)
|
||||
@@ -361,30 +399,6 @@ void FileManager::renamedFile(const QString &from, const QString &to)
|
||||
d->m_blockedIFile = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Removes all occurrences of the IFile from m_filesWithWatch and m_states.
|
||||
If that results in a file no longer being referenced by any IFile, this
|
||||
also removes the file watcher.
|
||||
*/
|
||||
void FileManager::removeFileInfo(IFile *file)
|
||||
{
|
||||
if (!d->m_filesWithWatch.contains(file))
|
||||
return;
|
||||
foreach (const QString &fileName, d->m_filesWithWatch.value(file)) {
|
||||
if (!d->m_states.contains(fileName))
|
||||
continue;
|
||||
d->m_states[fileName].lastUpdatedState.remove(file);
|
||||
if (d->m_states.value(fileName).lastUpdatedState.isEmpty()) {
|
||||
if (d->m_fileWatcher && d->m_fileWatcher->files().contains(fileName))
|
||||
d->m_fileWatcher->removePath(fileName);
|
||||
if (d->m_linkWatcher && d->m_linkWatcher->files().contains(fileName))
|
||||
d->m_linkWatcher->removePath(fileName);
|
||||
d->m_states.remove(fileName);
|
||||
}
|
||||
}
|
||||
d->m_filesWithWatch.remove(file);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool FileManager::addFile(IFile *files, bool addWatcher)
|
||||
|
||||
@@ -421,9 +435,9 @@ bool FileManager::removeFile(IFile *file)
|
||||
if (!d->m_filesWithoutWatch.removeOne(file)) {
|
||||
addWatcher = true;
|
||||
removeFileInfo(file);
|
||||
disconnect(file, SIGNAL(changed()), this, SLOT(checkForNewFileName()));
|
||||
disconnect(file, SIGNAL(changed()), m_instance, SLOT(checkForNewFileName()));
|
||||
}
|
||||
disconnect(file, SIGNAL(destroyed(QObject *)), this, SLOT(fileDestroyed(QObject *)));
|
||||
disconnect(file, SIGNAL(destroyed(QObject *)), m_instance, SLOT(fileDestroyed(QObject *)));
|
||||
return addWatcher;
|
||||
}
|
||||
|
||||
@@ -475,7 +489,7 @@ QString FileManager::fixFileName(const QString &fileName, FixMode fixmode)
|
||||
|
||||
Returns the list of IFile's that have been modified.
|
||||
*/
|
||||
QList<IFile *> FileManager::modifiedFiles() const
|
||||
QList<IFile *> FileManager::modifiedFiles()
|
||||
{
|
||||
QList<IFile *> modifiedFiles;
|
||||
|
||||
@@ -506,6 +520,18 @@ void FileManager::expectFileChange(const QString &fileName)
|
||||
d->m_expectedFileNames.insert(fileName);
|
||||
}
|
||||
|
||||
/* only called from unblock and unexpect file change methods */
|
||||
static void updateExpectedState(const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
if (d->m_states.contains(fileName)) {
|
||||
QFileInfo fi(fileName);
|
||||
d->m_states[fileName].expected.modified = fi.lastModified();
|
||||
d->m_states[fileName].expected.permissions = fi.permissions();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void FileManager::unexpectFileChange(const QString &fileName)
|
||||
|
||||
@@ -530,18 +556,6 @@ void FileManager::unexpectFileChange(const QString &fileName)
|
||||
updateExpectedState(fixedResolvedName);
|
||||
}
|
||||
|
||||
/* only called from unblock and unexpect file change methods */
|
||||
void FileManager::updateExpectedState(const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
if (d->m_states.contains(fileName)) {
|
||||
QFileInfo fi(fileName);
|
||||
d->m_states[fileName].expected.modified = fi.lastModified();
|
||||
d->m_states[fileName].expected.permissions = fi.permissions();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QList<IFile*> FileManager::saveModifiedFilesSilently(const QList<IFile*> &files)
|
||||
|
||||
@@ -550,7 +564,7 @@ void FileManager::updateExpectedState(const QString &fileName)
|
||||
*/
|
||||
QList<IFile *> FileManager::saveModifiedFilesSilently(const QList<IFile *> &files, bool *cancelled)
|
||||
{
|
||||
return saveModifiedFiles(files, cancelled, true, QString());
|
||||
return saveModifiedFilesHelper(files, cancelled, true, QString());
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -570,10 +584,10 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
|
||||
const QString &alwaysSaveMessage,
|
||||
bool *alwaysSave)
|
||||
{
|
||||
return saveModifiedFiles(files, cancelled, false, message, alwaysSaveMessage, alwaysSave);
|
||||
return saveModifiedFilesHelper(files, cancelled, false, message, alwaysSaveMessage, alwaysSave);
|
||||
}
|
||||
|
||||
QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
|
||||
static QList<IFile *> saveModifiedFilesHelper(const QList<IFile *> &files,
|
||||
bool *cancelled,
|
||||
bool silently,
|
||||
const QString &message,
|
||||
@@ -606,7 +620,7 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
|
||||
if (silently) {
|
||||
filesToSave = modifiedFiles;
|
||||
} else {
|
||||
Internal::SaveItemsDialog dia(d->m_mainWindow, modifiedFiles);
|
||||
SaveItemsDialog dia(d->m_mainWindow, modifiedFiles);
|
||||
if (!message.isEmpty())
|
||||
dia.setMessage(message);
|
||||
if (!alwaysSaveMessage.isNull())
|
||||
@@ -865,12 +879,12 @@ void FileManager::checkForReload()
|
||||
QMap<IFile*, QString> filesToSave;
|
||||
|
||||
// collect file information
|
||||
QMap<QString, Internal::FileStateItem> currentStates;
|
||||
QMap<QString, FileStateItem> currentStates;
|
||||
QMap<QString, IFile::ChangeType> changeTypes;
|
||||
QSet<IFile *> changedIFiles;
|
||||
foreach (const QString &fileName, d->m_changedFiles) {
|
||||
IFile::ChangeType type = IFile::TypeContents;
|
||||
Internal::FileStateItem state;
|
||||
FileStateItem state;
|
||||
QFileInfo fi(fileName);
|
||||
if (!fi.exists()) {
|
||||
type = IFile::TypeRemoved;
|
||||
@@ -915,9 +929,9 @@ void FileManager::checkForReload()
|
||||
if (!currentStates.contains(fileName))
|
||||
continue;
|
||||
|
||||
Internal::FileStateItem currentState = currentStates.value(fileName);
|
||||
Internal::FileStateItem expectedState = d->m_states.value(fileName).expected;
|
||||
Internal::FileStateItem lastState = d->m_states.value(fileName).lastUpdatedState.value(file);
|
||||
FileStateItem currentState = currentStates.value(fileName);
|
||||
FileStateItem expectedState = d->m_states.value(fileName).expected;
|
||||
FileStateItem lastState = d->m_states.value(fileName).lastUpdatedState.value(file);
|
||||
|
||||
// did the file actually change?
|
||||
if (lastState.modified == currentState.modified && lastState.permissions == currentState.permissions)
|
||||
@@ -1086,7 +1100,7 @@ void FileManager::addToRecentFiles(const QString &fileName, const Id &editorId)
|
||||
QMutableListIterator<RecentFile > it(d->m_recentFiles);
|
||||
while (it.hasNext()) {
|
||||
RecentFile file = it.next();
|
||||
QString recentUnifiedForm(fixFileName(file.first, KeepLinks));
|
||||
QString recentUnifiedForm(fixFileName(file.first, FileManager::KeepLinks));
|
||||
if (unifiedForm == recentUnifiedForm)
|
||||
it.remove();
|
||||
}
|
||||
@@ -1111,7 +1125,7 @@ void FileManager::clearRecentFiles()
|
||||
|
||||
Returns the list of recent files.
|
||||
*/
|
||||
QList<FileManager::RecentFile> FileManager::recentFiles() const
|
||||
QList<FileManager::RecentFile> FileManager::recentFiles()
|
||||
{
|
||||
return d->m_recentFiles;
|
||||
}
|
||||
@@ -1136,7 +1150,7 @@ void FileManager::saveSettings()
|
||||
s->endGroup();
|
||||
}
|
||||
|
||||
void FileManager::readSettings()
|
||||
void readSettings()
|
||||
{
|
||||
QSettings *s = Core::ICore::settings();
|
||||
d->m_recentFiles.clear();
|
||||
@@ -1151,7 +1165,7 @@ void FileManager::readSettings()
|
||||
if (ids.hasNext()) // guard against old or weird settings
|
||||
editorId = ids.next();
|
||||
if (QFileInfo(fileName).isFile())
|
||||
d->m_recentFiles.append(RecentFile(QDir::fromNativeSeparators(fileName), // from native to guard against old settings
|
||||
d->m_recentFiles.append(FileManager::RecentFile(QDir::fromNativeSeparators(fileName), // from native to guard against old settings
|
||||
Id(editorId)));
|
||||
}
|
||||
|
||||
@@ -1180,7 +1194,7 @@ void FileManager::setCurrentFile(const QString &filePath)
|
||||
if (d->m_currentFile == filePath)
|
||||
return;
|
||||
d->m_currentFile = filePath;
|
||||
emit currentFileChanged(d->m_currentFile);
|
||||
emit m_instance->currentFileChanged(d->m_currentFile);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1191,7 +1205,7 @@ void FileManager::setCurrentFile(const QString &filePath)
|
||||
|
||||
\sa setCurrentFile
|
||||
*/
|
||||
QString FileManager::currentFile() const
|
||||
QString FileManager::currentFile()
|
||||
{
|
||||
return d->m_currentFile;
|
||||
}
|
||||
@@ -1204,7 +1218,7 @@ QString FileManager::currentFile() const
|
||||
\sa setFileDialogLastVisitedDirectory
|
||||
*/
|
||||
|
||||
QString FileManager::fileDialogInitialDirectory() const
|
||||
QString FileManager::fileDialogInitialDirectory()
|
||||
{
|
||||
if (!d->m_currentFile.isEmpty())
|
||||
return QFileInfo(d->m_currentFile).absolutePath();
|
||||
@@ -1218,7 +1232,7 @@ QString FileManager::fileDialogInitialDirectory() const
|
||||
\sa setProjectsDirectory, setUseProjectsDirectory
|
||||
*/
|
||||
|
||||
QString FileManager::projectsDirectory() const
|
||||
QString FileManager::projectsDirectory()
|
||||
{
|
||||
return d->m_projectsDirectory;
|
||||
}
|
||||
@@ -1243,7 +1257,7 @@ void FileManager::setProjectsDirectory(const QString &dir)
|
||||
\sa setProjectsDirectory, setUseProjectsDirectory
|
||||
*/
|
||||
|
||||
bool FileManager::useProjectsDirectory() const
|
||||
bool FileManager::useProjectsDirectory()
|
||||
{
|
||||
return d->m_useProjectsDirectory;
|
||||
}
|
||||
@@ -1268,7 +1282,7 @@ void FileManager::setUseProjectsDirectory(bool useProjectsDirectory)
|
||||
|
||||
*/
|
||||
|
||||
QString FileManager::fileDialogLastVisitedDirectory() const
|
||||
QString FileManager::fileDialogLastVisitedDirectory()
|
||||
{
|
||||
return d->m_lastVisitedDirectory;
|
||||
}
|
||||
@@ -1289,7 +1303,7 @@ void FileManager::setFileDialogLastVisitedDirectory(const QString &directory)
|
||||
|
||||
void FileManager::notifyFilesChangedInternally(const QStringList &files)
|
||||
{
|
||||
emit filesChangedInternally(files);
|
||||
emit m_instance->filesChangedInternally(files);
|
||||
}
|
||||
|
||||
void FileManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
|
||||
@@ -1311,7 +1325,7 @@ void FileManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
|
||||
// Add action to open with this very editor factory
|
||||
QString const actionTitle = editorFactory->displayName();
|
||||
QAction * const action = menu->addAction(actionTitle);
|
||||
Internal::OpenWithEntry entry;
|
||||
OpenWithEntry entry;
|
||||
entry.editorFactory = editorFactory;
|
||||
entry.fileName = fileName;
|
||||
action->setData(qVariantFromValue(entry));
|
||||
@@ -1319,7 +1333,7 @@ void FileManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
|
||||
// Add all suitable external editors
|
||||
foreach (IExternalEditor *externalEditor, externalEditors) {
|
||||
QAction * const action = menu->addAction(externalEditor->displayName());
|
||||
Internal::OpenWithEntry entry;
|
||||
OpenWithEntry entry;
|
||||
entry.externalEditor = externalEditor;
|
||||
entry.fileName = fileName;
|
||||
action->setData(qVariantFromValue(entry));
|
||||
@@ -1334,7 +1348,7 @@ void FileManager::executeOpenWithMenuAction(QAction *action)
|
||||
QTC_ASSERT(action, return);
|
||||
EditorManager *em = EditorManager::instance();
|
||||
const QVariant data = action->data();
|
||||
Internal::OpenWithEntry entry = qVariantValue<Internal::OpenWithEntry>(data);
|
||||
OpenWithEntry entry = qVariantValue<OpenWithEntry>(data);
|
||||
if (entry.editorFactory) {
|
||||
// close any open editors that have this file open, but have a different type.
|
||||
QList<IEditor *> editorsOpenForFile = em->editorsForFileName(entry.fileName);
|
||||
@@ -1354,19 +1368,22 @@ void FileManager::executeOpenWithMenuAction(QAction *action)
|
||||
em->openExternalEditor(entry.fileName, entry.externalEditor->id());
|
||||
}
|
||||
|
||||
void FileManager::slotExecuteOpenWithMenuAction(QAction *action)
|
||||
{
|
||||
executeOpenWithMenuAction(action);
|
||||
}
|
||||
|
||||
// -------------- FileChangeBlocker
|
||||
|
||||
FileChangeBlocker::FileChangeBlocker(const QString &fileName)
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
Core::FileManager *fm = Core::ICore::fileManager();
|
||||
fm->expectFileChange(fileName);
|
||||
FileManager::expectFileChange(fileName);
|
||||
}
|
||||
|
||||
FileChangeBlocker::~FileChangeBlocker()
|
||||
{
|
||||
Core::FileManager *fm = Core::ICore::fileManager();
|
||||
fm->unexpectFileChange(m_fileName);
|
||||
FileManager::unexpectFileChange(m_fileName);
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
@@ -48,15 +48,10 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
|
||||
class ICore;
|
||||
class IContext;
|
||||
class IFile;
|
||||
class IVersionControl;
|
||||
|
||||
namespace Internal {
|
||||
struct FileManagerPrivate;
|
||||
}
|
||||
|
||||
class CORE_EXPORT FileManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -74,44 +69,44 @@ public:
|
||||
static FileManager *instance();
|
||||
|
||||
// file pool to monitor
|
||||
void addFiles(const QList<IFile *> &files, bool addWatcher = true);
|
||||
void addFile(IFile *file, bool addWatcher = true);
|
||||
bool removeFile(IFile *file);
|
||||
QList<IFile *> modifiedFiles() const;
|
||||
static void addFiles(const QList<IFile *> &files, bool addWatcher = true);
|
||||
static void addFile(IFile *file, bool addWatcher = true);
|
||||
static bool removeFile(IFile *file);
|
||||
static QList<IFile *> modifiedFiles();
|
||||
|
||||
void renamedFile(const QString &from, const QString &to);
|
||||
static void renamedFile(const QString &from, const QString &to);
|
||||
|
||||
void expectFileChange(const QString &fileName);
|
||||
void unexpectFileChange(const QString &fileName);
|
||||
static void expectFileChange(const QString &fileName);
|
||||
static void unexpectFileChange(const QString &fileName);
|
||||
|
||||
// recent files
|
||||
void addToRecentFiles(const QString &fileName, const Id &editorId = Id());
|
||||
static void addToRecentFiles(const QString &fileName, const Id &editorId = Id());
|
||||
Q_SLOT void clearRecentFiles();
|
||||
QList<RecentFile> recentFiles() const;
|
||||
static QList<RecentFile> recentFiles();
|
||||
|
||||
void saveSettings();
|
||||
static void saveSettings();
|
||||
|
||||
// current file
|
||||
void setCurrentFile(const QString &filePath);
|
||||
QString currentFile() const;
|
||||
static void setCurrentFile(const QString &filePath);
|
||||
static QString currentFile();
|
||||
|
||||
// helper methods
|
||||
static QString fixFileName(const QString &fileName, FixMode fixmode);
|
||||
|
||||
bool saveFile(IFile *file, const QString &fileName = QString(), bool *isReadOnly = 0);
|
||||
static bool saveFile(IFile *file, const QString &fileName = QString(), bool *isReadOnly = 0);
|
||||
|
||||
QStringList getOpenFileNames(const QString &filters,
|
||||
static QStringList getOpenFileNames(const QString &filters,
|
||||
const QString path = QString(),
|
||||
QString *selectedFilter = 0);
|
||||
QString getSaveFileName(const QString &title, const QString &pathIn,
|
||||
static QString getSaveFileName(const QString &title, const QString &pathIn,
|
||||
const QString &filter = QString(), QString *selectedFilter = 0);
|
||||
QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
|
||||
static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
|
||||
const QString &filter);
|
||||
QString getSaveAsFileName(IFile *file, const QString &filter = QString(),
|
||||
static QString getSaveAsFileName(IFile *file, const QString &filter = QString(),
|
||||
QString *selectedFilter = 0);
|
||||
|
||||
QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files, bool *cancelled = 0);
|
||||
QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
|
||||
static QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files, bool *cancelled = 0);
|
||||
static QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
|
||||
bool *cancelled = 0,
|
||||
const QString &message = QString(),
|
||||
const QString &alwaysSaveMessage = QString(),
|
||||
@@ -126,25 +121,27 @@ public:
|
||||
QWidget *parent,
|
||||
bool displaySaveAsButton = false);
|
||||
|
||||
QString fileDialogLastVisitedDirectory() const;
|
||||
void setFileDialogLastVisitedDirectory(const QString &);
|
||||
static QString fileDialogLastVisitedDirectory();
|
||||
static void setFileDialogLastVisitedDirectory(const QString &);
|
||||
|
||||
QString fileDialogInitialDirectory() const;
|
||||
static QString fileDialogInitialDirectory();
|
||||
|
||||
bool useProjectsDirectory() const;
|
||||
void setUseProjectsDirectory(bool);
|
||||
static bool useProjectsDirectory();
|
||||
static void setUseProjectsDirectory(bool);
|
||||
|
||||
QString projectsDirectory() const;
|
||||
void setProjectsDirectory(const QString &);
|
||||
static QString projectsDirectory();
|
||||
static void setProjectsDirectory(const QString &);
|
||||
|
||||
static void populateOpenWithMenu(QMenu *menu, const QString &fileName);
|
||||
|
||||
public slots:
|
||||
/* Used to notify e.g. the code model to update the given files. Does *not*
|
||||
lead to any editors to reload or any other editor manager actions. */
|
||||
void notifyFilesChangedInternally(const QStringList &files);
|
||||
static void notifyFilesChangedInternally(const QStringList &files);
|
||||
|
||||
void executeOpenWithMenuAction(QAction *action);
|
||||
static void executeOpenWithMenuAction(QAction *action);
|
||||
|
||||
public slots:
|
||||
void slotExecuteOpenWithMenuAction(QAction *action);
|
||||
|
||||
signals:
|
||||
void currentFileChanged(const QString &filePath);
|
||||
@@ -159,23 +156,6 @@ private slots:
|
||||
void changedFile(const QString &file);
|
||||
void mainWindowActivated();
|
||||
void syncWithEditor(Core::IContext *context);
|
||||
|
||||
private:
|
||||
void readSettings();
|
||||
void dump();
|
||||
void addFileInfo(IFile *file);
|
||||
void addFileInfo(const QString &fileName, IFile *file, bool isLink);
|
||||
void removeFileInfo(IFile *file);
|
||||
|
||||
void updateExpectedState(const QString &fileName);
|
||||
|
||||
QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
|
||||
bool *cancelled, bool silently,
|
||||
const QString &message,
|
||||
const QString &alwaysSaveMessage = QString(),
|
||||
bool *alwaysSave = 0);
|
||||
|
||||
Internal::FileManagerPrivate *d;
|
||||
};
|
||||
|
||||
/*! The FileChangeBlocker blocks all change notifications to all IFile * that
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
QWidget *parent = 0);
|
||||
|
||||
static ActionManager *actionManager();
|
||||
static FileManager *fileManager();
|
||||
static QT_DEPRECATED FileManager *fileManager(); // Use FileManager::... directly.
|
||||
static MessageManager *messageManager();
|
||||
static EditorManager *editorManager();
|
||||
static ProgressManager *progressManager();
|
||||
|
||||
@@ -138,7 +138,6 @@ MainWindow::MainWindow() :
|
||||
m_actionManager(new ActionManagerPrivate(this)),
|
||||
m_editorManager(0),
|
||||
m_externalToolManager(0),
|
||||
m_fileManager(new FileManager(this)),
|
||||
m_progressManager(new ProgressManagerPrivate()),
|
||||
m_scriptManager(new ScriptManagerPrivate(this)),
|
||||
m_variableManager(new VariableManager),
|
||||
@@ -171,6 +170,7 @@ MainWindow::MainWindow() :
|
||||
#endif
|
||||
m_toggleSideBarButton(new QToolButton)
|
||||
{
|
||||
(void) new FileManager(this);
|
||||
OutputPaneManager::create();
|
||||
|
||||
setWindowTitle(tr("Qt Creator"));
|
||||
@@ -376,7 +376,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
|
||||
// Save opened files
|
||||
bool cancelled;
|
||||
QList<IFile*> notSaved = fileManager()->saveModifiedFiles(fileManager()->modifiedFiles(), &cancelled);
|
||||
QList<IFile*> notSaved = FileManager::saveModifiedFiles(FileManager::modifiedFiles(), &cancelled);
|
||||
if (cancelled || !notSaved.isEmpty()) {
|
||||
event->ignore();
|
||||
return;
|
||||
@@ -962,18 +962,17 @@ void MainWindow::showNewItemDialog(const QString &title,
|
||||
|
||||
QString path = defaultLocation;
|
||||
if (path.isEmpty()) {
|
||||
const FileManager *fm = m_coreImpl->fileManager();
|
||||
switch (wizard->kind()) {
|
||||
case IWizard::ProjectWizard:
|
||||
// Project wizards: Check for projects directory or
|
||||
// use last visited directory of file dialog. Never start
|
||||
// at current.
|
||||
path = fm->useProjectsDirectory() ?
|
||||
fm->projectsDirectory() :
|
||||
fm->fileDialogLastVisitedDirectory();
|
||||
path = FileManager::useProjectsDirectory() ?
|
||||
FileManager::projectsDirectory() :
|
||||
FileManager::fileDialogLastVisitedDirectory();
|
||||
break;
|
||||
default:
|
||||
path = fm->fileDialogInitialDirectory();
|
||||
path = FileManager::fileDialogInitialDirectory();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -993,7 +992,7 @@ bool MainWindow::showOptionsDialog(const QString &category,
|
||||
|
||||
void MainWindow::saveAll()
|
||||
{
|
||||
m_fileManager->saveModifiedFilesSilently(m_fileManager->modifiedFiles());
|
||||
FileManager::saveModifiedFilesSilently(FileManager::modifiedFiles());
|
||||
emit m_coreImpl->saveSettingsRequested();
|
||||
}
|
||||
|
||||
@@ -1030,7 +1029,7 @@ ActionManager *MainWindow::actionManager() const
|
||||
|
||||
FileManager *MainWindow::fileManager() const
|
||||
{
|
||||
return m_fileManager;
|
||||
return FileManager::instance();
|
||||
}
|
||||
|
||||
MessageManager *MainWindow::messageManager() const
|
||||
@@ -1236,7 +1235,7 @@ void MainWindow::writeSettings()
|
||||
|
||||
m_settings->endGroup();
|
||||
|
||||
m_fileManager->saveSettings();
|
||||
FileManager::saveSettings();
|
||||
m_actionManager->saveSettings(m_settings);
|
||||
m_editorManager->saveSettings();
|
||||
m_navigationWidget->saveSettings(m_settings);
|
||||
@@ -1296,7 +1295,7 @@ void MainWindow::aboutToShowRecentFiles()
|
||||
aci->menu()->clear();
|
||||
|
||||
bool hasRecentFiles = false;
|
||||
foreach (const FileManager::RecentFile &file, m_fileManager->recentFiles()) {
|
||||
foreach (const FileManager::RecentFile &file, FileManager::recentFiles()) {
|
||||
hasRecentFiles = true;
|
||||
QAction *action = aci->menu()->addAction(
|
||||
QDir::toNativeSeparators(Utils::withTildeHomePath(file.first)));
|
||||
@@ -1310,7 +1309,7 @@ void MainWindow::aboutToShowRecentFiles()
|
||||
aci->menu()->addSeparator();
|
||||
QAction *action = aci->menu()->addAction(QCoreApplication::translate(
|
||||
"Core", Core::Constants::TR_CLEAR_MENU));
|
||||
connect(action, SIGNAL(triggered()), m_fileManager, SLOT(clearRecentFiles()));
|
||||
connect(action, SIGNAL(triggered()), FileManager::instance(), SLOT(clearRecentFiles()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,6 @@ private:
|
||||
ActionManagerPrivate *m_actionManager;
|
||||
EditorManager *m_editorManager;
|
||||
ExternalToolManager *m_externalToolManager;
|
||||
FileManager *m_fileManager;
|
||||
MessageManager *m_messageManager;
|
||||
ProgressManagerPrivate *m_progressManager;
|
||||
ScriptManager *m_scriptManager;
|
||||
|
||||
@@ -179,10 +179,9 @@ VcsManager::~VcsManager()
|
||||
void VcsManager::extensionsInitialized()
|
||||
{
|
||||
// Change signal connections
|
||||
FileManager *fileManager = ICore::fileManager();
|
||||
foreach (IVersionControl *versionControl, allVersionControls()) {
|
||||
connect(versionControl, SIGNAL(filesChanged(QStringList)),
|
||||
fileManager, SIGNAL(filesChangedInternally(QStringList)));
|
||||
FileManager::instance(), SIGNAL(filesChangedInternally(QStringList)));
|
||||
connect(versionControl, SIGNAL(repositoryChanged(QString)),
|
||||
this, SIGNAL(repositoryChanged(QString)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user