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
|
|
|
|
2020-06-17 09:14:47 +02:00
|
|
|
#include <coreplugin/core_global.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
|
2021-05-18 13:55:23 +02:00
|
|
|
#include <utils/fileutils.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
#include <utils/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
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
namespace Utils { class FilePath; }
|
2014-12-21 21:54:30 +02:00
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-08 14:34:05 +02:00
|
|
|
using RecentFile = QPair<Utils::FilePath, Utils::Id>;
|
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
|
|
|
|
2021-06-11 14:34:34 +02:00
|
|
|
static void renamedFile(const Utils::FilePath &from, const Utils::FilePath &to);
|
2010-05-11 14:13:38 +02:00
|
|
|
|
2021-06-09 09:59:37 +02:00
|
|
|
static void expectFileChange(const Utils::FilePath &filePath);
|
|
|
|
|
static void unexpectFileChange(const Utils::FilePath &filePath);
|
2010-01-22 16:49:57 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// recent files
|
2021-06-08 14:34:05 +02:00
|
|
|
static void addToRecentFiles(const Utils::FilePath &filePath, Utils::Id editorId = {});
|
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
|
2021-06-11 10:08:28 +02:00
|
|
|
static Utils::FilePath filePathKey(const Utils::FilePath &filePath, ResolveMode resolveMode);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-09-29 11:42:26 +02:00
|
|
|
static bool saveDocument(IDocument *document,
|
2021-05-18 13:55:23 +02:00
|
|
|
const Utils::FilePath &filePath = Utils::FilePath(),
|
2017-09-29 11:42:26 +02:00
|
|
|
bool *isReadOnly = nullptr);
|
2011-03-30 12:38:12 +02:00
|
|
|
|
2017-11-01 15:46:00 +01:00
|
|
|
static QString allDocumentFactoryFiltersString(QString *allFilesFilter);
|
|
|
|
|
|
2021-07-23 10:33:02 +02:00
|
|
|
static Utils::FilePaths getOpenFileNames(const QString &filters,
|
|
|
|
|
const Utils::FilePath &path = {},
|
|
|
|
|
QString *selectedFilter = nullptr);
|
2021-09-21 06:36:32 +02:00
|
|
|
static Utils::FilePath getSaveFileName(const QString &title,
|
|
|
|
|
const Utils::FilePath &pathIn,
|
|
|
|
|
const QString &filter = {},
|
|
|
|
|
QString *selectedFilter = nullptr);
|
|
|
|
|
static Utils::FilePath getSaveFileNameWithExtension(const QString &title,
|
|
|
|
|
const Utils::FilePath &pathIn,
|
|
|
|
|
const QString &filter);
|
|
|
|
|
static Utils::FilePath 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);
|
2019-05-28 13:49:26 +02:00
|
|
|
static void showFilePropertiesDialog(const Utils::FilePath &filePath);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2021-09-21 06:36:32 +02:00
|
|
|
static Utils::FilePath fileDialogLastVisitedDirectory();
|
|
|
|
|
static void setFileDialogLastVisitedDirectory(const Utils::FilePath &);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2021-09-21 06:36:32 +02:00
|
|
|
static Utils::FilePath fileDialogInitialDirectory();
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2021-09-21 06:36:32 +02:00
|
|
|
static Utils::FilePath defaultLocationForNewFiles();
|
|
|
|
|
static void setDefaultLocationForNewFiles(const Utils::FilePath &location);
|
2015-01-16 17:47:11 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static bool useProjectsDirectory();
|
|
|
|
|
static void setUseProjectsDirectory(bool);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static Utils::FilePath projectsDirectory();
|
|
|
|
|
static void setProjectsDirectory(const Utils::FilePath &directory);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
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. */
|
2021-06-22 08:57:36 +02:00
|
|
|
static void notifyFilesChangedInternally(const Utils::FilePaths &filePaths);
|
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. */
|
2021-06-22 08:57:36 +02:00
|
|
|
void filesChangedInternally(const Utils::FilePaths &filePaths);
|
2012-03-12 16:56:25 +01:00
|
|
|
/// emitted if all documents changed their name e.g. due to the file changing on disk
|
2021-06-11 14:34:34 +02:00
|
|
|
void allDocumentsRenamed(const Utils::FilePath &from, const Utils::FilePath &to);
|
2012-03-12 16:56:25 +01:00
|
|
|
/// emitted if one document changed its name e.g. due to save as
|
2021-06-11 14:34:34 +02:00
|
|
|
void documentRenamed(Core::IDocument *document,
|
|
|
|
|
const Utils::FilePath &from,
|
|
|
|
|
const Utils::FilePath &to);
|
2019-05-28 13:49:26 +02:00
|
|
|
void projectsDirectoryChanged(const Utils::FilePath &directory);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2021-09-03 17:14:54 +02:00
|
|
|
void filesChangedExternally(const QSet<Utils::FilePath> &filePaths);
|
|
|
|
|
|
2013-06-25 13:37:21 +02:00
|
|
|
private:
|
2014-01-06 10:56:30 +01:00
|
|
|
explicit DocumentManager(QObject *parent);
|
2018-05-07 15:00:03 +02:00
|
|
|
~DocumentManager() override;
|
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);
|
2019-05-28 13:49:26 +02:00
|
|
|
void filePathChanged(const Utils::FilePath &oldName, const Utils::FilePath &newName);
|
2020-03-19 15:19:11 +02:00
|
|
|
void updateSaveAll();
|
|
|
|
|
static void registerSaveAllAction();
|
2014-12-21 21:54:30 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2009-06-18 14:30:04 +02:00
|
|
|
class CORE_EXPORT FileChangeBlocker
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-06-09 09:59:37 +02:00
|
|
|
explicit FileChangeBlocker(const Utils::FilePath &filePath);
|
2009-06-18 14:30:04 +02:00
|
|
|
~FileChangeBlocker();
|
|
|
|
|
private:
|
2021-06-09 09:59:37 +02:00
|
|
|
const Utils::FilePath m_filePath;
|
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)
|