forked from qt-creator/qt-creator
Utils: Split user interaction out of FileSaver::finalize()
Change-Id: Ib3b968fe6912b659c150481c8cfea7596dbc200b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -90,16 +90,6 @@ Result<> FileSaverBase::finalize()
|
||||
return m_result;
|
||||
}
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
bool FileSaverBase::finalize(QWidget *parent)
|
||||
{
|
||||
if (finalize())
|
||||
return true;
|
||||
QMessageBox::critical(parent, Tr::tr("File Error"), errorString());
|
||||
return false;
|
||||
}
|
||||
#endif // QT_GUI_LIB
|
||||
|
||||
bool FileSaverBase::write(const char *data, int len)
|
||||
{
|
||||
if (!m_result)
|
||||
@@ -874,6 +864,11 @@ FilePaths usefulExtraSearchPaths()
|
||||
return {};
|
||||
}
|
||||
|
||||
void showError(const QString &errorMessage)
|
||||
{
|
||||
QMessageBox::critical(dialogParent(), Tr::tr("File Error"), errorMessage);
|
||||
}
|
||||
|
||||
} // namespace FileUtils
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
@@ -107,6 +107,9 @@ QTCREATOR_UTILS_EXPORT FilePaths getOpenFilePaths(
|
||||
const QString &filter = {},
|
||||
QString *selectedFilter = nullptr,
|
||||
QFileDialog::Options options = {});
|
||||
|
||||
QTCREATOR_UTILS_EXPORT void showError(const QString &errorMessage);
|
||||
|
||||
#endif
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString fetchQrc(const QString &fileName); // Only for internal resourcesm
|
||||
@@ -160,9 +163,6 @@ public:
|
||||
bool hasError() const { return !m_result; }
|
||||
QString errorString() const { return m_result.error(); }
|
||||
virtual Utils::Result<> finalize();
|
||||
#ifdef QT_GUI_LIB
|
||||
bool finalize(QWidget *parent);
|
||||
#endif
|
||||
|
||||
bool write(const char *data, int len);
|
||||
bool write(const QByteArray &bytes);
|
||||
|
@@ -493,8 +493,10 @@ void CppFileSettingsWidget::slotEdit()
|
||||
FileSaver saver(path, QIODevice::Text);
|
||||
saver.write(
|
||||
Tr::tr(licenseTemplateTemplate).arg(QGuiApplication::applicationDisplayName()).toUtf8());
|
||||
if (!saver.finalize(this))
|
||||
if (const Result<> res = saver.finalize(); !res) {
|
||||
FileUtils::showError(res.error());
|
||||
return;
|
||||
}
|
||||
setLicenseTemplatePath(path);
|
||||
}
|
||||
// Edit (now) existing file with C++
|
||||
|
@@ -1971,7 +1971,8 @@ void DebuggerPluginPrivate::dumpLog()
|
||||
ts << logWindow->combinedContents();
|
||||
saver.setResult(&ts);
|
||||
}
|
||||
saver.finalize(ICore::dialogParent());
|
||||
if (const Result<> res = saver.finalize(); !res)
|
||||
FileUtils::showError(res.error());
|
||||
}
|
||||
|
||||
void DebuggerPluginPrivate::remoteCommand(const QStringList &options)
|
||||
|
@@ -959,7 +959,7 @@ void ExtensionManagerWidget::fetchAndInstallPlugin(const QUrl &url, bool update,
|
||||
TempFileSaver saver(TemporaryDirectory::masterDirectoryPath() + "/XXXXXX-" + filename);
|
||||
|
||||
saver.write(storage->packageData);
|
||||
if (saver.finalize(ICore::dialogParent())) {
|
||||
if (const Result<> res = saver.finalize()) {
|
||||
auto result = executePluginInstallWizard(saver.filePath(), update);
|
||||
switch (result) {
|
||||
case InstallResult::Success:
|
||||
@@ -970,6 +970,8 @@ void ExtensionManagerWidget::fetchAndInstallPlugin(const QUrl &url, bool update,
|
||||
case InstallResult::Error:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
FileUtils::showError(res.error());
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
@@ -319,8 +319,10 @@ bool GenericBuildSystem::saveRawList(const QStringList &rawList, const QString &
|
||||
stream << filePath << '\n';
|
||||
saver.setResult(&stream);
|
||||
}
|
||||
bool result = saver.finalize(ICore::dialogParent());
|
||||
return result;
|
||||
const Result<> result = saver.finalize();
|
||||
if (!result)
|
||||
FileUtils::showError(result.error());
|
||||
return result.has_value();
|
||||
}
|
||||
|
||||
static void insertSorted(QStringList *list, const QString &value)
|
||||
|
@@ -6,8 +6,6 @@
|
||||
#include "helptr.h"
|
||||
#include "localhelpmanager.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/fadingindicator.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
@@ -22,7 +20,9 @@
|
||||
|
||||
#include <QHelpEngine>
|
||||
|
||||
using namespace Help::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Help::Internal {
|
||||
|
||||
struct ExtensionMap {
|
||||
const char *extension;
|
||||
@@ -143,13 +143,15 @@ bool HelpViewer::launchWithExternalApp(const QUrl &url)
|
||||
|
||||
const QString& path = resolvedUrl.path();
|
||||
if (!canOpenPage(path)) {
|
||||
Utils::TempFileSaver saver(Utils::TemporaryDirectory::masterDirectoryPath()
|
||||
TempFileSaver saver(TemporaryDirectory::masterDirectoryPath()
|
||||
+ "/qtchelp_XXXXXX." + QFileInfo(path).completeSuffix());
|
||||
saver.setAutoRemove(false);
|
||||
if (!saver.hasError())
|
||||
saver.write(helpEngine.fileData(resolvedUrl));
|
||||
if (saver.finalize(Core::ICore::dialogParent()))
|
||||
if (const Result<> res = saver.finalize())
|
||||
QDesktopServices::openUrl(QUrl(saver.filePath().toUrlishString()));
|
||||
else
|
||||
FileUtils::showError(res.error());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -256,3 +258,5 @@ bool HelpViewer::handleForwardBackwardMouseButtons(QMouseEvent *event)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // Help::Internal
|
||||
|
@@ -14,8 +14,7 @@
|
||||
#include <QUrl>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
namespace Help::Internal {
|
||||
|
||||
class HelpViewer : public QWidget
|
||||
{
|
||||
@@ -103,5 +102,4 @@ private:
|
||||
void applyZoom(int percentage);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Help
|
||||
} // namespace Help::Internal
|
||||
|
@@ -322,8 +322,10 @@ void LspLogWidget::saveLog()
|
||||
return;
|
||||
FileSaver saver(filePath, QIODevice::Text);
|
||||
saver.write(contents.toUtf8());
|
||||
if (!saver.finalize(this))
|
||||
if (const Result<> res = saver.finalize(); !res) {
|
||||
FileUtils::showError(res.error());
|
||||
saveLog();
|
||||
}
|
||||
}
|
||||
|
||||
class LspInspectorWidget : public QDialog
|
||||
|
@@ -12,6 +12,8 @@
|
||||
#include <QDataStream>
|
||||
#include <QCoreApplication>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Macros::Internal {
|
||||
|
||||
/*!
|
||||
@@ -122,8 +124,10 @@ bool Macro::save(const QString &fileName)
|
||||
}
|
||||
saver.setResult(&stream);
|
||||
}
|
||||
if (!saver.finalize(Core::ICore::dialogParent()))
|
||||
if (const Result<> res = saver.finalize(); !res) {
|
||||
FileUtils::showError(res.error());
|
||||
return false;
|
||||
}
|
||||
d->fileName = fileName;
|
||||
return true;
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@
|
||||
#include <coreplugin/coreplugintr.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
@@ -240,8 +239,10 @@ Result<> ResourceEditorDocument::setContents(const QByteArray &contents)
|
||||
{
|
||||
TempFileSaver saver;
|
||||
saver.write(contents);
|
||||
if (!saver.finalize(ICore::dialogParent()))
|
||||
return ResultError(saver.errorString());
|
||||
if (const Result<> res = saver.finalize(); !res) {
|
||||
FileUtils::showError(res.error());
|
||||
return res;
|
||||
}
|
||||
|
||||
const FilePath originalFileName = m_model.filePath();
|
||||
m_model.setFilePath(saver.filePath());
|
||||
|
@@ -6,8 +6,6 @@
|
||||
#include "texteditorconstants.h"
|
||||
#include "texteditortr.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QFile>
|
||||
@@ -264,7 +262,12 @@ bool ColorScheme::save(const FilePath &filePath) const
|
||||
|
||||
saver.setResult(&w);
|
||||
}
|
||||
return saver.finalize(Core::ICore::dialogParent());
|
||||
|
||||
const Result<> res = saver.finalize();
|
||||
if (!res)
|
||||
FileUtils::showError(res.error());
|
||||
|
||||
return res.has_value();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@@ -252,8 +252,10 @@ void SuppressionDialog::accept()
|
||||
stream << m_suppressionEdit->toPlainText();
|
||||
saver.setResult(&stream);
|
||||
}
|
||||
if (!saver.finalize(this))
|
||||
if (const Result<> res = saver.finalize(); !res) {
|
||||
FileUtils::showError(res.error());
|
||||
return;
|
||||
}
|
||||
|
||||
// Add file to project if there is a project containing this file on the file system.
|
||||
if (!ProjectExplorer::ProjectManager::projectForFile(path)) {
|
||||
|
Reference in New Issue
Block a user