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