aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/documentmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/coreplugin/documentmanager.cpp')
-rw-r--r--src/plugins/coreplugin/documentmanager.cpp56
1 files changed, 47 insertions, 9 deletions
diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp
index f7a8340d9e..d66ff8453c 100644
--- a/src/plugins/coreplugin/documentmanager.cpp
+++ b/src/plugins/coreplugin/documentmanager.cpp
@@ -30,6 +30,9 @@
#include "idocumentfactory.h"
#include "coreconstants.h"
+#include <coreplugin/actionmanager/actioncontainer.h>
+#include <coreplugin/actionmanager/actionmanager.h>
+#include <coreplugin/actionmanager/command.h>
#include <coreplugin/diffservice.h>
#include <coreplugin/dialogs/filepropertiesdialog.h>
#include <coreplugin/dialogs/readonlyfilesdialog.h>
@@ -71,9 +74,10 @@ static Q_LOGGING_CATEGORY(log, "qtc.core.documentmanager", QtWarningMsg)
/*!
\class Core::DocumentManager
+ \inheaderfile coreplugin/documentmanager.h
\ingroup mainclasses
\inmodule QtCreator
- \inheaderfile documentmanager.h
+
\brief The DocumentManager class manages a set of documents.
The DocumentManager service monitors a set of IDocument objects.
@@ -165,6 +169,8 @@ public:
void checkOnNextFocusChange();
void onApplicationFocusChange();
+ void registerSaveAllAction();
+
QMap<QString, FileState> m_states; // filePathKey -> FileState
QSet<QString> m_changedFiles; // watched file paths collected from file watcher notifications
QList<IDocument *> m_documentsWithoutWatch;
@@ -188,6 +194,8 @@ public:
// signal
// That makes the code easier
IDocument *m_blockedIDocument = nullptr;
+
+ QAction *m_saveAllAction;
};
static DocumentManager *m_instance;
@@ -231,7 +239,20 @@ void DocumentManagerPrivate::onApplicationFocusChange()
m_instance->checkForReload();
}
-DocumentManagerPrivate::DocumentManagerPrivate()
+void DocumentManagerPrivate::registerSaveAllAction()
+{
+ ActionContainer *mfile = ActionManager::actionContainer(Constants::M_FILE);
+ Command *cmd = ActionManager::registerAction(m_saveAllAction, Constants::SAVEALL);
+ cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? QString() : tr("Ctrl+Shift+S")));
+ mfile->addAction(cmd, Constants::G_FILE_SAVE);
+ m_saveAllAction->setEnabled(false);
+ connect(m_saveAllAction, &QAction::triggered, []() {
+ DocumentManager::saveAllModifiedDocumentsSilently();
+ });
+}
+
+DocumentManagerPrivate::DocumentManagerPrivate() :
+ m_saveAllAction(new QAction(tr("Save A&ll"), this))
{
// we do not want to do too much directly in the focus change event, so queue the connection
connect(qApp,
@@ -255,7 +276,7 @@ DocumentManager::DocumentManager(QObject *parent)
m_instance = this;
connect(Utils::GlobalFileChangeBlocker::instance(), &Utils::GlobalFileChangeBlocker::stateChanged,
- this, [this](bool blocked) {
+ this, [](bool blocked) {
d->m_postponeAutoReload = blocked;
if (!blocked)
QTimer::singleShot(500, m_instance, &DocumentManager::checkForReload);
@@ -348,6 +369,7 @@ void DocumentManager::addDocuments(const QList<IDocument *> &documents, bool add
m_instance, &DocumentManager::documentDestroyed);
connect(document, &IDocument::filePathChanged,
m_instance, &DocumentManager::filePathChanged);
+ connect(document, &IDocument::changed, m_instance, &DocumentManager::updateSaveAll);
d->m_documentsWithoutWatch.append(document);
}
}
@@ -360,6 +382,7 @@ void DocumentManager::addDocuments(const QList<IDocument *> &documents, bool add
connect(document, &QObject::destroyed, m_instance, &DocumentManager::documentDestroyed);
connect(document, &IDocument::filePathChanged,
m_instance, &DocumentManager::filePathChanged);
+ connect(document, &IDocument::changed, m_instance, &DocumentManager::updateSaveAll);
addFileInfo(document);
}
}
@@ -473,6 +496,11 @@ void DocumentManager::filePathChanged(const FilePath &oldName, const FilePath &n
emit m_instance->documentRenamed(doc, oldName.toString(), newName.toString());
}
+void DocumentManager::updateSaveAll()
+{
+ d->m_saveAllAction->setEnabled(!modifiedDocuments().empty());
+}
+
/*!
Adds \a document to the collection. If \a addWatcher is \c true
(the default), the document's file is added to a file system watcher
@@ -509,6 +537,7 @@ bool DocumentManager::removeDocument(IDocument *document)
disconnect(document, &IDocument::changed, m_instance, &DocumentManager::checkForNewFileName);
}
disconnect(document, &QObject::destroyed, m_instance, &DocumentManager::documentDestroyed);
+ disconnect(document, &IDocument::changed, m_instance, &DocumentManager::updateSaveAll);
return addWatcher;
}
@@ -640,7 +669,7 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
QList<IDocument *> modifiedDocuments;
foreach (IDocument *document, documents) {
- if (document && document->isModified()) {
+ if (document && document->isModified() && !document->isTemporary()) {
QString name = document->filePath().toString();
if (name.isEmpty())
name = document->fallbackSaveAsFileName();
@@ -739,6 +768,7 @@ bool DocumentManager::saveDocument(IDocument *document, const QString &fileName,
addDocument(document, addWatcher);
unexpectFileChange(effName);
+ m_instance->updateSaveAll();
return ret;
}
@@ -788,14 +818,15 @@ QString DocumentManager::getSaveFileName(const QString &title, const QString &pa
// first one from the filter is appended.
if (selectedFilter && *selectedFilter != Utils::allFilesFilterString()) {
// Mime database creates filter strings like this: Anything here (*.foo *.bar)
- QRegExp regExp(QLatin1String(".*\\s+\\((.*)\\)$"));
- const int index = regExp.lastIndexIn(*selectedFilter);
- if (index != -1) {
+ const QRegularExpression regExp(QLatin1String(".*\\s+\\((.*)\\)$"));
+ QRegularExpressionMatchIterator matchIt = regExp.globalMatch(*selectedFilter);
+ if (matchIt.hasNext()) {
bool suffixOk = false;
- QString caption = regExp.cap(1);
+ const QRegularExpressionMatch match = matchIt.next();
+ QString caption = match.captured(1);
caption.remove(QLatin1Char('*'));
const QVector<QStringRef> suffixes = caption.splitRef(QLatin1Char(' '));
- foreach (const QStringRef &suffix, suffixes)
+ for (const QStringRef &suffix : suffixes)
if (fileName.endsWith(suffix)) {
suffixOk = true;
break;
@@ -1501,11 +1532,18 @@ void DocumentManager::notifyFilesChangedInternally(const QStringList &files)
emit m_instance->filesChangedInternally(files);
}
+void DocumentManager::registerSaveAllAction()
+{
+ d->registerSaveAllAction();
+}
+
// -------------- FileChangeBlocker
/*!
\class Core::FileChangeBlocker
+ \inheaderfile coreplugin/documentmanager.h
\inmodule QtCreator
+
\brief The FileChangeBlocker class blocks all change notifications to all
IDocument objects that match the given filename.