forked from qt-creator/qt-creator
		
	add/unify i/o error handling
lots of use of Utils::FileSaver and Utils::FileReader Task-number: QTCREATORBUG-1619
This commit is contained in:
		@@ -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;
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    // 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;
 | 
			
		||||
    }
 | 
			
		||||
    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);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user