2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-11-10 11:36:51 +01:00
|
|
|
#include <coreplugin/id.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QPair>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2013-03-27 08:29:38 +01:00
|
|
|
class QStringList;
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2014-12-21 21:54:30 +02:00
|
|
|
namespace Utils { class FileName; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Core {
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
class IDocument;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
class DocumentManagerPrivate;
|
|
|
|
|
class MainWindow;
|
|
|
|
|
}
|
2013-06-25 13:37:21 +02:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
class CORE_EXPORT DocumentManager : public QObject
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2017-08-21 14:46:38 +02:00
|
|
|
enum ResolveMode {
|
2010-11-23 12:47:45 +01:00
|
|
|
ResolveLinks,
|
|
|
|
|
KeepLinks
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-10 11:36:51 +01:00
|
|
|
typedef QPair<QString, Id> RecentFile;
|
2010-12-09 11:37:58 +01:00
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
static DocumentManager *instance();
|
2010-11-26 16:01:34 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// file pool to monitor
|
2012-02-14 16:43:51 +01:00
|
|
|
static void addDocuments(const QList<IDocument *> &documents, bool addWatcher = true);
|
|
|
|
|
static void addDocument(IDocument *document, bool addWatcher = true);
|
|
|
|
|
static bool removeDocument(IDocument *document);
|
|
|
|
|
static QList<IDocument *> modifiedDocuments();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static void renamedFile(const QString &from, const QString &to);
|
2010-05-11 14:13:38 +02:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static void expectFileChange(const QString &fileName);
|
|
|
|
|
static void unexpectFileChange(const QString &fileName);
|
2010-01-22 16:49:57 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// recent files
|
2014-07-01 11:08:26 +02:00
|
|
|
static void addToRecentFiles(const QString &fileName, Id editorId = Id());
|
2011-06-20 11:01:23 +02:00
|
|
|
Q_SLOT void clearRecentFiles();
|
2012-01-19 23:23:43 +01:00
|
|
|
static QList<RecentFile> recentFiles();
|
2011-06-20 11:01:23 +02:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static void saveSettings();
|
2010-05-11 14:13:38 +02:00
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
// helper functions
|
2017-08-21 14:46:38 +02:00
|
|
|
static QString cleanAbsoluteFilePath(const QString &filePath, ResolveMode resolveMode);
|
|
|
|
|
static QString filePathKey(const QString &filePath, ResolveMode resolveMode);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-09-29 11:42:26 +02:00
|
|
|
static bool saveDocument(IDocument *document,
|
|
|
|
|
const QString &fileName = QString(),
|
|
|
|
|
bool *isReadOnly = nullptr);
|
2011-03-30 12:38:12 +02:00
|
|
|
|
2017-11-01 15:46:00 +01:00
|
|
|
static QString allDocumentFactoryFiltersString(QString *allFilesFilter);
|
|
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static QStringList getOpenFileNames(const QString &filters,
|
2014-05-20 08:58:08 +03:00
|
|
|
const QString &path = QString(),
|
2017-09-29 11:42:26 +02:00
|
|
|
QString *selectedFilter = nullptr);
|
|
|
|
|
static QString getSaveFileName(const QString &title,
|
|
|
|
|
const QString &pathIn,
|
|
|
|
|
const QString &filter = QString(),
|
|
|
|
|
QString *selectedFilter = nullptr);
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
|
2010-09-07 11:55:52 +02:00
|
|
|
const QString &filter);
|
2016-11-03 12:04:31 +01:00
|
|
|
static QString getSaveAsFileName(const IDocument *document);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-09-29 11:42:26 +02:00
|
|
|
static bool saveAllModifiedDocumentsSilently(bool *canceled = nullptr,
|
|
|
|
|
QList<IDocument *> *failedToClose = nullptr);
|
|
|
|
|
static bool saveModifiedDocumentsSilently(const QList<IDocument *> &documents,
|
|
|
|
|
bool *canceled = nullptr,
|
|
|
|
|
QList<IDocument *> *failedToClose = nullptr);
|
|
|
|
|
static bool saveModifiedDocumentSilently(IDocument *document,
|
|
|
|
|
bool *canceled = nullptr,
|
|
|
|
|
QList<IDocument *> *failedToClose = nullptr);
|
|
|
|
|
|
|
|
|
|
static bool saveAllModifiedDocuments(const QString &message = QString(),
|
|
|
|
|
bool *canceled = nullptr,
|
2014-01-21 13:25:19 +01:00
|
|
|
const QString &alwaysSaveMessage = QString(),
|
2017-09-29 11:42:26 +02:00
|
|
|
bool *alwaysSave = nullptr,
|
|
|
|
|
QList<IDocument *> *failedToClose = nullptr);
|
2014-01-21 13:25:19 +01:00
|
|
|
static bool saveModifiedDocuments(const QList<IDocument *> &documents,
|
2017-09-29 11:42:26 +02:00
|
|
|
const QString &message = QString(),
|
|
|
|
|
bool *canceled = nullptr,
|
2014-01-21 13:25:19 +01:00
|
|
|
const QString &alwaysSaveMessage = QString(),
|
2017-09-29 11:42:26 +02:00
|
|
|
bool *alwaysSave = nullptr,
|
|
|
|
|
QList<IDocument *> *failedToClose = nullptr);
|
2014-01-21 13:25:19 +01:00
|
|
|
static bool saveModifiedDocument(IDocument *document,
|
2017-09-29 11:42:26 +02:00
|
|
|
const QString &message = QString(),
|
|
|
|
|
bool *canceled = nullptr,
|
2011-02-25 15:27:13 +01:00
|
|
|
const QString &alwaysSaveMessage = QString(),
|
2017-09-29 11:42:26 +02:00
|
|
|
bool *alwaysSave = nullptr,
|
|
|
|
|
QList<IDocument *> *failedToClose = nullptr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString fileDialogLastVisitedDirectory();
|
|
|
|
|
static void setFileDialogLastVisitedDirectory(const QString &);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString fileDialogInitialDirectory();
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2015-01-16 17:47:11 +01:00
|
|
|
static QString defaultLocationForNewFiles();
|
|
|
|
|
static void setDefaultLocationForNewFiles(const QString &location);
|
|
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static bool useProjectsDirectory();
|
|
|
|
|
static void setUseProjectsDirectory(bool);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2017-09-18 12:30:56 +02:00
|
|
|
static Utils::FileName projectsDirectory();
|
|
|
|
|
static void setProjectsDirectory(const Utils::FileName &directory);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2012-10-05 21:34:09 +10:00
|
|
|
static QString buildDirectory();
|
|
|
|
|
static void setBuildDirectory(const QString &directory);
|
|
|
|
|
|
2009-12-21 11:08:20 +01:00
|
|
|
/* 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. */
|
2012-01-19 23:23:43 +01:00
|
|
|
static void notifyFilesChangedInternally(const QStringList &files);
|
2009-12-21 11:08:20 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
2009-12-21 11:08:20 +01:00
|
|
|
/* 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 filesChangedInternally(const QStringList &files);
|
2012-03-12 16:56:25 +01:00
|
|
|
/// emitted if all documents changed their name e.g. due to the file changing on disk
|
|
|
|
|
void allDocumentsRenamed(const QString &from, const QString &to);
|
|
|
|
|
/// emitted if one document changed its name e.g. due to save as
|
|
|
|
|
void documentRenamed(Core::IDocument *document, const QString &from, const QString &to);
|
2017-09-18 13:39:35 +02:00
|
|
|
void projectsDirectoryChanged(const Utils::FileName &directory);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-06-10 15:28:26 +02:00
|
|
|
protected:
|
|
|
|
|
bool eventFilter(QObject *obj, QEvent *e);
|
|
|
|
|
|
2013-06-25 13:37:21 +02:00
|
|
|
private:
|
2014-01-06 10:56:30 +01:00
|
|
|
explicit DocumentManager(QObject *parent);
|
2013-08-29 17:56:28 +02:00
|
|
|
~DocumentManager();
|
2013-06-25 13:37:21 +02:00
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
void documentDestroyed(QObject *obj);
|
|
|
|
|
void checkForNewFileName();
|
|
|
|
|
void checkForReload();
|
|
|
|
|
void changedFile(const QString &file);
|
2014-12-21 21:54:30 +02:00
|
|
|
void filePathChanged(const Utils::FileName &oldName, const Utils::FileName &newName);
|
|
|
|
|
|
2013-06-25 13:37:21 +02:00
|
|
|
friend class Core::Internal::MainWindow;
|
2016-02-02 09:10:54 +02:00
|
|
|
friend class Core::Internal::DocumentManagerPrivate;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
/*! The FileChangeBlocker blocks all change notifications to all IDocument * that
|
2009-06-18 14:30:04 +02:00
|
|
|
match the given filename. And unblocks in the destructor.
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
To also reload the IDocument in the destructor class set modifiedReload to true
|
2009-06-18 14:30:04 +02:00
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
class CORE_EXPORT FileChangeBlocker
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-09-16 14:59:05 +02:00
|
|
|
explicit FileChangeBlocker(const QString &fileName);
|
2009-06-18 14:30:04 +02:00
|
|
|
~FileChangeBlocker();
|
|
|
|
|
private:
|
2010-09-16 14:59:05 +02:00
|
|
|
const QString m_fileName;
|
2009-07-28 11:37:16 +02:00
|
|
|
Q_DISABLE_COPY(FileChangeBlocker)
|
2009-06-18 14:30:04 +02:00
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace Core
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::DocumentManager::RecentFile)
|