diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-03-30 15:15:15 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-04-18 14:10:14 +0200 |
commit | 45c9cf7a1298feed925d18596c30ac9c6cd1dac5 (patch) | |
tree | 6f484122011b76a5f3a2f1915b7b308b1f5058ea /src/plugins/cpptools/cppfilesettingspage.cpp | |
parent | fae7dc9584b4e2f2192f8b7a71c428fcaa2ddb70 (diff) | |
download | qt-creator-45c9cf7a1298feed925d18596c30ac9c6cd1dac5.tar.gz |
add/unify i/o error handling
lots of use of Utils::FileSaver and Utils::FileReader
Task-number: QTCREATORBUG-1619
Diffstat (limited to 'src/plugins/cpptools/cppfilesettingspage.cpp')
-rw-r--r-- | src/plugins/cpptools/cppfilesettingspage.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/plugins/cpptools/cppfilesettingspage.cpp b/src/plugins/cpptools/cppfilesettingspage.cpp index 94d64250b8..e864af5153 100644 --- a/src/plugins/cpptools/cppfilesettingspage.cpp +++ b/src/plugins/cpptools/cppfilesettingspage.cpp @@ -41,6 +41,8 @@ #include <extensionsystem/pluginmanager.h> +#include <utils/fileutils.h> + #include <QtCore/QSettings> #include <QtCore/QDebug> #include <QtCore/QFile> @@ -301,25 +303,18 @@ void CppFileSettingsWidget::setSettings(const CppFileSettings &s) void CppFileSettingsWidget::slotEdit() { QString path = licenseTemplatePath(); - // Edit existing file with C++ - if (!path.isEmpty()) { - Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID), - Core::EditorManager::ModeSwitch); - return; - } - // Pick a file name and write new template, edit with C++ - path = QFileDialog::getSaveFileName(this, tr("Choose Location for New License Template File")); - if (path.isEmpty()) - return; - QFile file(path); - if (!file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate)) { - QMessageBox::warning(this, tr("Template write error"), - tr("Cannot write to %1: %2").arg(path, file.errorString())); - return; + if (path.isEmpty()) { + // Pick a file name and write new template, edit with C++ + path = QFileDialog::getSaveFileName(this, tr("Choose Location for New License Template File")); + if (path.isEmpty()) + return; + Utils::FileSaver saver(path, QIODevice::Text); + saver.write(tr(licenseTemplateTemplate).toUtf8()); + if (!saver.finalize(this)) + return; + setLicenseTemplatePath(path); } - file.write(tr(licenseTemplateTemplate).toUtf8()); - file.close(); - setLicenseTemplatePath(path); + // Edit (now) existing file with C++ Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID), Core::EditorManager::ModeSwitch); } |