OSDN Git Service

add errorString output argument to IFile::reload() & IEditor::open()
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Mon, 4 Apr 2011 13:24:13 +0000 (15:24 +0200)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Mon, 18 Apr 2011 12:10:13 +0000 (14:10 +0200)
add/unify read error handling in all affected classes

44 files changed:
src/plugins/bineditor/bineditorplugin.cpp
src/plugins/cmakeprojectmanager/cmakeproject.cpp
src/plugins/cmakeprojectmanager/cmakeproject.h
src/plugins/coreplugin/editormanager/editormanager.cpp
src/plugins/coreplugin/editormanager/ieditor.h
src/plugins/coreplugin/filemanager.cpp
src/plugins/coreplugin/ifile.h
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.h
src/plugins/designer/formwindoweditor.cpp
src/plugins/designer/formwindoweditor.h
src/plugins/designer/formwindowfile.cpp
src/plugins/designer/formwindowfile.h
src/plugins/genericprojectmanager/genericproject.cpp
src/plugins/genericprojectmanager/genericproject.h
src/plugins/glsleditor/glsleditor.cpp
src/plugins/glsleditor/glsleditoreditable.h
src/plugins/imageviewer/imageviewer.cpp
src/plugins/imageviewer/imageviewer.h
src/plugins/imageviewer/imageviewerfile.cpp
src/plugins/imageviewer/imageviewerfile.h
src/plugins/qmljseditor/qmljseditor.cpp
src/plugins/qmljseditor/qmljseditoreditable.h
src/plugins/qmlprojectmanager/qmlprojectfile.cpp
src/plugins/qmlprojectmanager/qmlprojectfile.h
src/plugins/qt4projectmanager/qt4nodes.cpp
src/plugins/qt4projectmanager/qt4nodes.h
src/plugins/qt4projectmanager/qt4project.cpp
src/plugins/qt4projectmanager/qt4project.h
src/plugins/resourceeditor/resourceeditorw.cpp
src/plugins/resourceeditor/resourceeditorw.h
src/plugins/tasklist/taskfile.cpp
src/plugins/tasklist/taskfile.h
src/plugins/tasklist/taskfilefactory.cpp
src/plugins/tasklist/tasklistplugin.cpp
src/plugins/tasklist/tasklistplugin.h
src/plugins/texteditor/basetextdocument.cpp
src/plugins/texteditor/basetextdocument.h
src/plugins/texteditor/basetexteditor.cpp
src/plugins/texteditor/basetexteditor.h
src/plugins/vcsbase/submiteditorfile.cpp
src/plugins/vcsbase/submiteditorfile.h
src/plugins/vcsbase/vcsbasesubmiteditor.cpp
src/plugins/vcsbase/vcsbasesubmiteditor.h

index 1b00d8a..38a3cae 100644 (file)
@@ -34,6 +34,9 @@
 #include "bineditor.h"
 #include "bineditorconstants.h"
 
+#include <coreplugin/icore.h>
+
+#include <QtCore/QDir>
 #include <QtCore/QFile>
 #include <QtCore/QFileInfo>
 #include <QtCore/QDebug>
@@ -43,6 +46,7 @@
 #include <QtGui/QMenu>
 #include <QtGui/QAction>
 #include <QtGui/QMainWindow>
+#include <QtGui/QMessageBox>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QLineEdit>
 #include <QtGui/QRegExpValidator>
@@ -219,16 +223,23 @@ public:
         emit changed();
     }
 
-    bool open(const QString &fileName, quint64 offset = 0) {
+    bool open(QString *errorString, const QString &fileName, quint64 offset = 0) {
         QFile file(fileName);
-        if (offset < static_cast<quint64>(file.size())
-            && file.open(QIODevice::ReadOnly)) {
+        if (offset >= static_cast<quint64>(file.size()))
+            return false;
+        if (file.open(QIODevice::ReadOnly)) {
             m_fileName = fileName;
             m_editor->setSizes(offset, file.size());
             m_editor->editor()->setDisplayName(QFileInfo(fileName).fileName());
             file.close();
             return true;
         }
+        QString errStr = tr("Cannot open %1: %2").arg(
+                QDir::toNativeSeparators(fileName), file.errorString());
+        if (errorString)
+            *errorString = errStr;
+        else
+            QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("File Error"), errStr);
         return false;
     }
 
@@ -246,19 +257,23 @@ private slots:
                 data += QByteArray(blockSize - dataSize, 0);
             m_editor->addData(block, data);
             file.close();
+        } else {
+            QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("File Error"),
+                                  tr("Cannot open %1: %2").arg(
+                                        QDir::toNativeSeparators(m_fileName), file.errorString()));
         }
     }
 
     void provideNewRange(Core::IEditor *, quint64 offset) {
-        open(m_fileName, offset);
+        open(0, m_fileName, offset);
     }
 
     void handleStartOfFileRequested(Core::IEditor *) {
-        open(m_fileName, 0);
+        open(0, m_fileName, 0);
     }
 
     void handleEndOfFileRequested(Core::IEditor *) {
-        open(m_fileName, QFileInfo(m_fileName).size() - 1);
+        open(0, m_fileName, QFileInfo(m_fileName).size() - 1);
     }
 
 public:
@@ -295,16 +310,18 @@ public:
         return BehaviorAsk;
     }
 
-    void reload(ReloadFlag flag, ChangeType type) {
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type) {
         if (flag == FlagIgnore)
-            return;
+            return true;
         if (type == TypePermissions) {
             emit changed();
         } else {
             emit aboutToReload();
-            if (open(m_fileName))
-                emit reloaded();
+            if (!open(errorString, m_fileName))
+                return false;
+            emit reloaded();
         }
+        return true;
     }
 
 private:
@@ -357,8 +374,8 @@ public:
         m_file->setFilename(QString());
         return true;
     }
-    bool open(const QString &fileName = QString()) {
-        return m_file->open(fileName);
+    bool open(QString *errorString, const QString &fileName = QString()) {
+        return m_file->open(errorString, fileName);
     }
     Core::IFile *file() { return m_file; }
     QString id() const { return QLatin1String(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID); }
index 3cb0ae4..340fbb4 100644 (file)
@@ -794,10 +794,12 @@ Core::IFile::ReloadBehavior CMakeFile::reloadBehavior(ChangeTrigger state, Chang
     return BehaviorSilent;
 }
 
-void CMakeFile::reload(ReloadFlag flag, ChangeType type)
+bool CMakeFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
+    Q_UNUSED(errorString)
     Q_UNUSED(flag)
     Q_UNUSED(type)
+    return true;
 }
 
 CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeTarget *target)
index d5a536c..028dfb5 100644 (file)
@@ -211,7 +211,7 @@ public:
     bool isSaveAsAllowed() const;
 
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
 
     void rename(const QString &newName);
 
index 26ee9ba..c73262d 100644 (file)
@@ -1217,9 +1217,10 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
     // back to the default editor:
     if (!editor)
         editor = createEditor(QString(), fn);
-    if (!editor || !editor->open(fn)) {
+    QString errorString;
+    if (!editor || !editor->open(&errorString, fn)) {
         QApplication::restoreOverrideCursor();
-        QMessageBox::critical(m_d->m_core->mainWindow(), tr("Opening File"), tr("Cannot open file %1!").arg(QDir::toNativeSeparators(fn)));
+        QMessageBox::critical(m_d->m_core->mainWindow(), tr("File Error"), errorString);
         delete editor;
         editor = 0;
         return 0;
@@ -1843,7 +1844,9 @@ void EditorManager::revertToSaved()
             return;
 
     }
-    currEditor->file()->reload(IFile::FlagReload, IFile::TypeContents);
+    QString errorString;
+    if (!currEditor->file()->reload(&errorString, IFile::FlagReload, IFile::TypeContents))
+        QMessageBox::critical(m_d->m_core->mainWindow(), tr("File Error"), errorString);
 }
 
 void EditorManager::showEditorInfoBar(const QString &id,
index d64b823..09a2ad3 100644 (file)
@@ -50,7 +50,7 @@ public:
     virtual ~IEditor() {}
 
     virtual bool createNew(const QString &contents = QString()) = 0;
-    virtual bool open(const QString &fileName = QString()) = 0;
+    virtual bool open(QString *errorString, const QString &fileName = QString()) = 0;
     virtual IFile *file() = 0;
     virtual QString id() const = 0;
     virtual QString displayName() const = 0;
index 54aa931..5ddb468 100644 (file)
@@ -912,6 +912,7 @@ void FileManager::checkForReload()
     }
 
     // handle the IFiles
+    QStringList errorStrings;
     foreach (IFile *file, changedIFiles) {
         IFile::ChangeTrigger behavior = IFile::TriggerInternal;
         IFile::ChangeType type = IFile::TypePermissions;
@@ -958,21 +959,23 @@ void FileManager::checkForReload()
         // handle it!
         d->m_blockedIFile = file;
 
+        bool success = true;
+        QString errorString;
         // we've got some modification
         // check if it's contents or permissions:
         if (type == IFile::TypePermissions) {
             // Only permission change
-            file->reload(IFile::FlagReload, IFile::TypePermissions);
+            success = file->reload(&errorString, IFile::FlagReload, IFile::TypePermissions);
         // now we know it's a content change or file was removed
         } else if (defaultBehavior == IFile::ReloadUnmodified
                    && type == IFile::TypeContents && !file->isModified()) {
             // content change, but unmodified (and settings say to reload in this case)
-            file->reload(IFile::FlagReload, type);
+            success = file->reload(&errorString, IFile::FlagReload, type);
         // file was removed or it's a content change and the default behavior for
         // unmodified files didn't kick in
         } else if (defaultBehavior == IFile::IgnoreAll) {
             // content change or removed, but settings say ignore
-            file->reload(IFile::FlagIgnore, type);
+            success = file->reload(&errorString, IFile::FlagIgnore, type);
         // either the default behavior is to always ask,
         // or the ReloadUnmodified default behavior didn't kick in,
         // so do whatever the IFile wants us to do
@@ -980,27 +983,27 @@ void FileManager::checkForReload()
             // check if IFile wants us to ask
             if (file->reloadBehavior(behavior, type) == IFile::BehaviorSilent) {
                 // content change or removed, IFile wants silent handling
-                file->reload(IFile::FlagReload, type);
+                success = file->reload(&errorString, IFile::FlagReload, type);
             // IFile wants us to ask
             } else if (type == IFile::TypeContents) {
                 // content change, IFile wants to ask user
                 if (previousAnswer == Utils::ReloadNone) {
                     // answer already given, ignore
-                    file->reload(IFile::FlagIgnore, IFile::TypeContents);
+                    success = file->reload(&errorString, IFile::FlagIgnore, IFile::TypeContents);
                 } else if (previousAnswer == Utils::ReloadAll) {
                     // answer already given, reload
-                    file->reload(IFile::FlagReload, IFile::TypeContents);
+                    success = file->reload(&errorString, IFile::FlagReload, IFile::TypeContents);
                 } else {
                     // Ask about content change
                     previousAnswer = Utils::reloadPrompt(file->fileName(), file->isModified(), QApplication::activeWindow());
                     switch (previousAnswer) {
                     case Utils::ReloadAll:
                     case Utils::ReloadCurrent:
-                        file->reload(IFile::FlagReload, IFile::TypeContents);
+                        success = file->reload(&errorString, IFile::FlagReload, IFile::TypeContents);
                         break;
                     case Utils::ReloadSkipCurrent:
                     case Utils::ReloadNone:
-                        file->reload(IFile::FlagIgnore, IFile::TypeContents);
+                        success = file->reload(&errorString, IFile::FlagIgnore, IFile::TypeContents);
                         break;
                     }
                 }
@@ -1031,12 +1034,21 @@ void FileManager::checkForReload()
                 }
             }
         }
+        if (!success) {
+            if (errorString.isEmpty())
+                errorStrings << tr("Cannot reload %1").arg(QDir::toNativeSeparators(file->fileName()));
+            else
+                errorStrings << errorString;
+        }
 
         // update file info, also handling if e.g. link target has changed
         removeFileInfo(file);
         addFileInfo(file);
         d->m_blockedIFile = 0;
     }
+    if (!errorStrings.isEmpty())
+        QMessageBox::critical(d->m_mainWindow, tr("File Error"),
+                              errorStrings.join(QLatin1String("\n")));
 
     // handle deleted files
     EditorManager::instance()->closeEditors(editorsToClose, false);
index 9983736..b7b91ff 100644 (file)
@@ -95,7 +95,7 @@ public:
     virtual bool isSaveAsAllowed() const = 0;
 
     virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const = 0;
-    virtual void reload(ReloadFlag flag, ChangeType type) = 0;
+    virtual bool reload(QString *errorString, ReloadFlag flag, ChangeType type) = 0;
     virtual void rename(const QString &newName) = 0;
 
     virtual void checkPermissions() {}
index 3054297..6af7361 100644 (file)
@@ -1787,9 +1787,9 @@ QString CPPEditor::id() const
     return QLatin1String(CppEditor::Constants::CPPEDITOR_ID);
 }
 
-bool CPPEditor::open(const QString & fileName)
+bool CPPEditor::open(QString *errorString, const QString & fileName)
 {
-    bool b = TextEditor::BaseTextEditor::open(fileName);
+    bool b = TextEditor::BaseTextEditor::open(errorString, fileName);
     editorWidget()->setMimeType(Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(fileName)).type());
     return b;
 }
index 53f86f0..24888b4 100644 (file)
@@ -152,7 +152,7 @@ public:
     QString id() const;
 
     bool isTemporary() const { return false; }
-    virtual bool open(const QString & fileName);
+    virtual bool open(QString *errorString, const QString & fileName);
 };
 
 class CPPEditorWidget : public TextEditor::BaseTextEditorWidget
index 17f2d59..263ac2b 100644 (file)
@@ -46,6 +46,7 @@
 #include <texteditor/plaintexteditor.h>
 
 #include <utils/qtcassert.h>
+#include <utils/fileutils.h>
 
 #include <QtDesigner/QDesignerFormWindowInterface>
 
@@ -79,7 +80,7 @@ FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditor *editor,
 
     connect(form, SIGNAL(changed()), this, SIGNAL(changed()));
     // Revert to saved/load externally modified files.
-    connect(&d->m_file, SIGNAL(reload(QString)), this, SLOT(slotOpen(QString)));
+    connect(&d->m_file, SIGNAL(reload(QString*,QString)), this, SLOT(slotOpen(QString*,QString)));
     // Force update of open editors model.
     connect(&d->m_file, SIGNAL(saved()), this, SIGNAL(changed()));
     connect(&d->m_file, SIGNAL(changed()), this, SIGNAL(changed()));
@@ -126,12 +127,12 @@ bool FormWindowEditor::createNew(const QString &contents)
     return true;
 }
 
-void FormWindowEditor::slotOpen(const QString &fileName)
+void FormWindowEditor::slotOpen(QString *errorString, const QString &fileName)
 {
-    open(fileName);
+    open(errorString, fileName);
 }
 
-bool FormWindowEditor::open(const QString &fileName)
+bool FormWindowEditor::open(QString *errorString, const QString &fileName)
 {
     if (Designer::Constants::Internal::debug)
         qDebug() << "FormWindowEditor::open" << fileName;
@@ -147,15 +148,14 @@ bool FormWindowEditor::open(const QString &fileName)
     const QFileInfo fi(fileName);
     const QString absfileName = fi.absoluteFilePath();
 
-    QFile file(absfileName);
-    if (!file.open(QIODevice::ReadOnly|QIODevice::Text))
+    Utils::FileReader reader;
+    if (!reader.fetch(absfileName, QIODevice::Text, errorString))
         return false;
 
     form->setFileName(absfileName);
 
-    const QString contents = QString::fromUtf8(file.readAll());
+    const QString contents = QString::fromUtf8(reader.data());
     form->setContents(contents);
-    file.close();
     if (!form->mainContainer())
         return false;
     form->setDirty(false);
index f7304af..dec05b9 100644 (file)
@@ -71,7 +71,7 @@ public:
 
     // IEditor
     virtual bool createNew(const QString &contents = QString());
-    virtual bool open(const QString &fileName = QString());
+    virtual bool open(QString *errorString, const QString &fileName = QString());
     virtual Core::IFile *file();
     virtual QString id() const;
     virtual QString displayName() const;
@@ -100,7 +100,7 @@ public slots:
     void configureXmlEditor() const;
 
 private slots:
-    void slotOpen(const QString &fileName);
+    void slotOpen(QString *errorString, const QString &fileName);
 
 private:
     void syncXmlEditor(const QString &contents);
index 8955eee..714d479 100644 (file)
@@ -141,17 +141,20 @@ Core::IFile::ReloadBehavior FormWindowFile::reloadBehavior(ChangeTrigger state,
     return BehaviorAsk;
 }
 
-void FormWindowFile::reload(ReloadFlag flag, ChangeType type)
+bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
     if (flag == FlagIgnore)
-        return;
+        return true;
     if (type == TypePermissions) {
         emit changed();
     } else {
         emit aboutToReload();
-        emit reload(m_fileName);
+        emit reload(errorString, m_fileName);
+        if (!errorString->isEmpty())
+            return false;
         emit reloaded();
     }
+    return true;
 }
 
 QString FormWindowFile::defaultPath() const
index b120701..4bc1075 100644 (file)
@@ -59,7 +59,7 @@ public:
     virtual bool isReadOnly() const;
     virtual bool isSaveAsAllowed() const;
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
     virtual QString defaultPath() const;
     virtual QString suggestedFileName() const;
     virtual QString mimeType() const;
@@ -75,7 +75,7 @@ public:
 signals:
     // Internal
     void saved();
-    void reload(const QString &);
+    void reload(QString *errorString, const QString &);
     void setDisplayName(const QString &);
 
 public slots:
index c1bab06..ebec74a 100644 (file)
@@ -619,8 +619,10 @@ Core::IFile::ReloadBehavior GenericProjectFile::reloadBehavior(ChangeTrigger sta
     return BehaviorSilent;
 }
 
-void GenericProjectFile::reload(ReloadFlag flag, ChangeType type)
+bool GenericProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
+    Q_UNUSED(errorString)
     Q_UNUSED(flag)
     Q_UNUSED(type)
+    return true;
 }
index ce2746d..4ec07fa 100644 (file)
@@ -172,7 +172,7 @@ public:
     virtual void rename(const QString &newName);
 
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
 
 private:
     GenericProject *m_project;
index d77ad8b..1a45671 100644 (file)
@@ -205,10 +205,10 @@ QString GLSLEditorEditable::id() const
     return QLatin1String(GLSLEditor::Constants::C_GLSLEDITOR_ID);
 }
 
-bool GLSLEditorEditable::open(const QString &fileName)
+bool GLSLEditorEditable::open(QString *errorString, const QString &fileName)
 {
     editorWidget()->setMimeType(Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(fileName)).type());
-    bool b = TextEditor::BaseTextEditor::open(fileName);
+    bool b = TextEditor::BaseTextEditor::open(errorString, fileName);
     return b;
 }
 
index 59823c8..192567b 100644 (file)
@@ -51,7 +51,7 @@ public:
     Core::IEditor *duplicate(QWidget *parent);
     QString id() const;
     bool isTemporary() const { return false; }
-    virtual bool open(const QString &fileName);
+    virtual bool open(QString *errorString, const QString &fileName);
     virtual QString preferredModeType() const;
 };
 
index c6f760a..830f075 100644 (file)
@@ -45,6 +45,7 @@
 
 #include <QtCore/QMap>
 #include <QtCore/QFileInfo>
+#include <QtCore/QDir>
 #include <QtGui/QWidget>
 #include <QtCore/QtDebug>
 
@@ -116,10 +117,12 @@ bool ImageViewer::createNew(const QString &contents)
     return false;
 }
 
-bool ImageViewer::open(const QString &fileName)
+bool ImageViewer::open(QString *errorString, const QString &fileName)
 {
-    if (!d_ptr->imageView->openFile(fileName))
+    if (!d_ptr->imageView->openFile(fileName)) {
+        *errorString = tr("Cannot open image file %1").arg(QDir::toNativeSeparators(fileName));
         return false;
+    }
     setDisplayName(QFileInfo(fileName).fileName());
     d_ptr->file->setFileName(fileName);
     // d_ptr->file->setMimeType
index b1656e5..e2770e6 100644 (file)
@@ -56,7 +56,7 @@ public:
     ~ImageViewer();
 
     bool createNew(const QString &contents = QString());
-    bool open(const QString &fileName = QString());
+    bool open(QString *errorString, const QString &fileName = QString());
     Core::IFile *file();
     QString id() const;
     QString displayName() const;
index a993d00..4d1fa46 100644 (file)
@@ -74,15 +74,17 @@ Core::IFile::ReloadBehavior ImageViewerFile::reloadBehavior(Core::IFile::ChangeT
     return BehaviorAsk;
 }
 
-void ImageViewerFile::reload(Core::IFile::ReloadFlag flag,
+bool ImageViewerFile::reload(QString *errorString,
+                             Core::IFile::ReloadFlag flag,
                              Core::IFile::ChangeType type)
 {
     if (flag == FlagIgnore)
-        return;
+        return true;
     if (type == TypePermissions) {
         emit changed();
+        return true;
     } else {
-        d_ptr->editor->open(d_ptr->fileName);
+        return d_ptr->editor->open(errorString, d_ptr->fileName);
     }
 }
 
index b4ee14b..b449bb1 100644 (file)
@@ -62,7 +62,7 @@ public:
     bool isSaveAsAllowed() const;
 
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
 
     void setMimetype(const QString &mimetype);
     void setFileName(const QString &filename);
index 4fac404..0e6861c 100644 (file)
@@ -740,9 +740,9 @@ QString QmlJSEditorEditable::id() const
     return QLatin1String(QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
 }
 
-bool QmlJSEditorEditable::open(const QString &fileName)
+bool QmlJSEditorEditable::open(QString *errorString, const QString &fileName)
 {
-    bool b = TextEditor::BaseTextEditor::open(fileName);
+    bool b = TextEditor::BaseTextEditor::open(errorString, fileName);
     editorWidget()->setMimeType(Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(fileName)).type());
     return b;
 }
index a947725..adfcd4c 100644 (file)
@@ -50,7 +50,7 @@ public:
     Core::IEditor *duplicate(QWidget *parent);
     QString id() const;
     bool isTemporary() const { return false; }
-    virtual bool open(const QString & fileName);
+    virtual bool open(QString *errorString, const QString & fileName);
     virtual QString preferredModeType() const;
     void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason);
 };
index bcaf532..64a4c72 100644 (file)
@@ -100,10 +100,12 @@ Core::IFile::ReloadBehavior QmlProjectFile::reloadBehavior(ChangeTrigger state,
     return BehaviorSilent;
 }
 
-void QmlProjectFile::reload(ReloadFlag flag, ChangeType type)
+bool QmlProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
+    Q_UNUSED(errorString)
     Q_UNUSED(flag)
     Q_UNUSED(type)
+    return true;
 }
 
 } // namespace Internal
index 9f30d09..e9992fe 100644 (file)
@@ -62,7 +62,7 @@ public:
     virtual bool isSaveAsAllowed() const;
 
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
 
 private:
     QmlProject *m_project;
index 8406644..bd43324 100644 (file)
@@ -231,13 +231,14 @@ Core::IFile::ReloadBehavior Qt4PriFile::reloadBehavior(ChangeTrigger state, Chan
     return BehaviorSilent;
 }
 
-void Qt4PriFile::reload(ReloadFlag flag, ChangeType type)
+bool Qt4PriFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
+    Q_UNUSED(errorString)
     Q_UNUSED(flag)
-    Q_UNUSED(type)
     if (type == TypePermissions)
-        return;
+        return true;
     m_priFile->scheduleUpdate();
+    return true;
 }
 
 /*!
@@ -1130,11 +1131,17 @@ void Qt4PriFileNode::changeFiles(const FileType fileType,
     // So the modification time might not change between those two saves.
     // We manually tell each editor to reload it's file.
     // (The .pro files are notified by the file system watcher.)
+    QStringList errorStrings;
     foreach (Core::IEditor *editor, Core::ICore::instance()->editorManager()->editorsForFileName(m_projectFilePath)) {
         if (Core::IFile *editorFile = editor->file()) {
-            editorFile->reload(Core::IFile::FlagReload, Core::IFile::TypeContents);
+            QString errorString;
+            if (!editorFile->reload(&errorString, Core::IFile::FlagReload, Core::IFile::TypeContents))
+                errorStrings << errorString;
         }
     }
+    if (!errorStrings.isEmpty())
+        QMessageBox::warning(Core::ICore::instance()->mainWindow(), tr("File Error"),
+                             errorStrings.join(QLatin1String("\n")));
 
     includeFile->deref();
 }
index 7edf9ab..ad97338 100644 (file)
@@ -128,7 +128,7 @@ public:
     virtual bool isSaveAsAllowed() const;
 
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
 
 private:
     Qt4PriFileNode *m_priFile;
index 173beba..9af9a70 100644 (file)
@@ -238,10 +238,12 @@ Core::IFile::ReloadBehavior Qt4ProjectFile::reloadBehavior(ChangeTrigger state,
     return BehaviorSilent;
 }
 
-void Qt4ProjectFile::reload(ReloadFlag flag, ChangeType type)
+bool Qt4ProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
+    Q_UNUSED(errorString)
     Q_UNUSED(flag)
     Q_UNUSED(type)
+    return true;
 }
 
 /*!
index 5c9b487..454572f 100644 (file)
@@ -92,7 +92,7 @@ public:
     bool isSaveAsAllowed() const;
 
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
 
 private:
     const QString m_mimeType;
index 65f1f12..d80fda3 100644 (file)
@@ -112,7 +112,7 @@ bool ResourceEditorW::createNew(const QString &contents)
     return rc;
 }
 
-bool ResourceEditorW::open(const QString &fileName /* = QString() */)
+bool ResourceEditorW::open(QString *errorString, const QString &fileName /* = QString() */)
 {
     if (debugResourceEditorW)
         qDebug() <<  "ResourceEditorW::open: " << fileName;
@@ -126,11 +126,10 @@ bool ResourceEditorW::open(const QString &fileName /* = QString() */)
 
     const QString absFileName = fi.absoluteFilePath();
 
-    if (!fi.isReadable())
-        return false;
-
-    if (!m_resourceEditor->load(absFileName))
+    if (!m_resourceEditor->load(absFileName)) {
+        *errorString = m_resourceEditor->errorMessage();
         return false;
+    }
 
     setDisplayName(fi.fileName());
 
@@ -208,17 +207,19 @@ Core::IFile::ReloadBehavior ResourceEditorFile::reloadBehavior(ChangeTrigger sta
     return BehaviorAsk;
 }
 
-void ResourceEditorFile::reload(ReloadFlag flag, ChangeType type)
+bool ResourceEditorFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
     if (flag == FlagIgnore)
-        return;
+        return true;
     if (type == TypePermissions) {
         emit changed();
     } else {
         emit aboutToReload();
-        if (m_parent->open(m_parent->m_resourceEditor->fileName()))
-            emit reloaded();
+        if (!m_parent->open(errorString, m_parent->m_resourceEditor->fileName()))
+            return false;
+        emit reloaded();
     }
+    return true;
 }
 
 QString ResourceEditorFile::defaultPath() const
index 075dece..031079c 100644 (file)
@@ -63,7 +63,7 @@ public:
     bool isReadOnly() const;
     bool isSaveAsAllowed() const;
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
     QString defaultPath() const;
     QString suggestedFileName() const;
     virtual QString mimeType() const;
@@ -86,7 +86,7 @@ public:
 
     // IEditor
     bool createNew(const QString &contents);
-    bool open(const QString &fileName = QString());
+    bool open(QString *errorString, const QString &fileName = QString());
     bool duplicateSupported() const { return false; }
     Core::IEditor *duplicate(QWidget *) { return 0; }
     Core::IFile *file() { return m_resourceFile; }
index 7c0b542..e26a4b6 100644 (file)
@@ -97,15 +97,17 @@ Core::IFile::ReloadBehavior TaskFile::reloadBehavior(ChangeTrigger state, Change
     return BehaviorSilent;
 }
 
-void TaskFile::reload(ReloadFlag flag, ChangeType type)
+bool TaskFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
     Q_UNUSED(flag);
 
     if (type == TypePermissions)
-        return;
-    open(m_fileName);
-    if (type == TypeRemoved)
+        return true;
+    if (type == TypeRemoved) {
         deleteLater();
+        return true;
+    }
+    return open(errorString, m_fileName);
 }
 
 void TaskFile::rename(const QString &newName)
@@ -113,10 +115,10 @@ void TaskFile::rename(const QString &newName)
     Q_UNUSED(newName);
 }
 
-bool TaskFile::open(const QString &fileName)
+bool TaskFile::open(QString *errorString, const QString &fileName)
 {
     m_fileName = fileName;
-    return TaskList::TaskListPlugin::instance()->loadFile(m_context, m_fileName);
+    return TaskList::TaskListPlugin::instance()->loadFile(errorString, m_context, m_fileName);
 }
 
 ProjectExplorer::Project *TaskFile::context() const
index 0626fd6..10638b1 100644 (file)
@@ -60,10 +60,10 @@ public:
     bool isSaveAsAllowed() const;
 
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
     void rename(const QString &newName);
 
-    bool open(const QString &fileName);
+    bool open(QString *errorString, const QString &fileName);
 
     ProjectExplorer::Project *context() const;
     void setContext(ProjectExplorer::Project *context);
index 1a20716..c665570 100644 (file)
@@ -38,6 +38,9 @@
 #include <coreplugin/icore.h>
 #include <coreplugin/filemanager.h>
 
+#include <QtGui/QMainWindow>
+#include <QtGui/QMessageBox>
+
 using namespace TaskList::Internal;
 
 // --------------------------------------------------------------------------
@@ -79,7 +82,9 @@ Core::IFile *TaskFileFactory::open(ProjectExplorer::Project *context, const QStr
     TaskFile *file = new TaskFile(this);
     file->setContext(context);
 
-    if (!file->open(fileName)) {
+    QString errorString;
+    if (!file->open(&errorString, fileName)) {
+        QMessageBox::critical(Core::ICore::instance()->mainWindow(), tr("File Error"), errorString);
         delete file;
         return 0;
     }
index e050a21..7e0e9a1 100644 (file)
@@ -73,11 +73,14 @@ TaskListPlugin *TaskListPlugin::m_instance = 0;
 
 class Internal::TaskListPluginPrivate {
 public:
-    bool parseTaskFile(ProjectExplorer::Project *context, const QString &name)
+    bool parseTaskFile(QString *errorString, ProjectExplorer::Project *context, const QString &name)
     {
         QFile tf(name);
-        if (!tf.open(QIODevice::ReadOnly))
+        if (!tf.open(QIODevice::ReadOnly)) {
+            *errorString = TaskListPlugin::tr("Cannot open task file %1: %2").arg(
+                    QDir::toNativeSeparators(name), tf.errorString());
             return false;
+        }
 
         while (!tf.atEnd())
         {
@@ -211,10 +214,10 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
 void TaskListPlugin::extensionsInitialized()
 { }
 
-bool TaskListPlugin::loadFile(ProjectExplorer::Project *context, const QString &fileName)
+bool TaskListPlugin::loadFile(QString *errorString, ProjectExplorer::Project *context, const QString &fileName)
 {
     clearTasks();
-    return d->parseTaskFile(context, fileName);
+    return d->parseTaskFile(errorString, context, fileName);
 }
 
 bool TaskListPlugin::monitorFile(ProjectExplorer::Project *context, const QString &fileName)
index fe52908..141e73d 100644 (file)
@@ -58,7 +58,7 @@ public:
 
     void extensionsInitialized();
 
-    bool loadFile(ProjectExplorer::Project *context, const QString &fileName);
+    bool loadFile(QString *errorString, ProjectExplorer::Project *context, const QString &fileName);
     bool monitorFile(ProjectExplorer::Project *context, const QString &fileName);
 
     void stopMonitoring();
index f555cd5..e8ee9fa 100644 (file)
@@ -454,7 +454,7 @@ void BaseTextDocument::checkPermissions()
         emit changed();
 }
 
-bool BaseTextDocument::open(const QString &fileName)
+bool BaseTextDocument::open(QString *errorString, const QString &fileName)
 {
     QString title = tr("untitled");
     if (!fileName.isEmpty()) {
@@ -462,16 +462,16 @@ bool BaseTextDocument::open(const QString &fileName)
         d->m_fileIsReadOnly = !fi.isWritable();
         d->m_fileName = QDir::cleanPath(fi.absoluteFilePath());
 
-        QFile file(fileName);
-        if (!file.open(QIODevice::ReadOnly))
-            return false;
-
         title = fi.fileName();
 
         QByteArray buf;
         try {
-            buf = file.readAll();
+            Utils::FileReader reader;
+            if (!reader.fetch(fileName, errorString))
+                return false;
+            buf = reader.data();
         } catch (std::bad_alloc) {
+            *errorString = tr("Out of memory");
             return false;
         }
         int bytesRead = buf.size();
@@ -591,20 +591,22 @@ bool BaseTextDocument::open(const QString &fileName)
     return true;
 }
 
-void BaseTextDocument::reload(QTextCodec *codec)
+bool BaseTextDocument::reload(QString *errorString, QTextCodec *codec)
 {
-    QTC_ASSERT(codec, return);
+    QTC_ASSERT(codec, return false);
     d->m_codec = codec;
-    reload();
+    return reload(errorString);
 }
 
-void BaseTextDocument::reload()
+bool BaseTextDocument::reload(QString *errorString)
 {
     emit aboutToReload();
     documentClosing(); // removes text marks non-permanently
 
-    if (open(d->m_fileName))
-        emit reloaded();
+    if (!open(errorString, d->m_fileName))
+        return false;
+    emit reloaded();
+    return true;
 }
 
 Core::IFile::ReloadBehavior BaseTextDocument::reloadBehavior(ChangeTrigger state, ChangeType type) const
@@ -619,14 +621,15 @@ Core::IFile::ReloadBehavior BaseTextDocument::reloadBehavior(ChangeTrigger state
     return BehaviorAsk;
 }
 
-void BaseTextDocument::reload(ReloadFlag flag, ChangeType type)
+bool BaseTextDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
     if (flag == FlagIgnore)
-        return;
+        return true;
     if (type == TypePermissions) {
         checkPermissions();
+        return true;
     } else {
-        reload();
+        return reload(errorString);
     }
 }
 
index f08c1dd..bc59daa 100644 (file)
@@ -77,7 +77,7 @@ public:
     virtual bool isSaveAsAllowed() const;
     virtual void checkPermissions();
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
     virtual QString mimeType() const;
     void setMimeType(const QString &mt);
     virtual void rename(const QString &newName);
@@ -88,8 +88,8 @@ public:
     void setDefaultPath(const QString &defaultPath);
     void setSuggestedFileName(const QString &suggestedFileName);
 
-    virtual bool open(const QString &fileName = QString());
-    virtual void reload();
+    virtual bool open(QString *errorString, const QString &fileName = QString());
+    virtual bool reload(QString *errorString);
 
     QTextDocument *document() const;
     void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
@@ -100,7 +100,7 @@ public:
     void setCodec(QTextCodec *c);
     QByteArray decodingErrorSample() const;
 
-    void reload(QTextCodec *codec);
+    bool reload(QString *errorString, QTextCodec *codec);
     void cleanWhitespace(const QTextCursor &cursor);
 
 signals:
index ffb6567..b6117a8 100644 (file)
@@ -90,6 +90,7 @@
 #include <QtGui/QToolBar>
 #include <QtGui/QInputDialog>
 #include <QtGui/QMenu>
+#include <QtGui/QMessageBox>
 
 //#define DO_FOO
 
@@ -520,14 +521,18 @@ void BaseTextEditorWidget::selectEncoding()
     CodecSelector codecSelector(this, doc);
 
     switch (codecSelector.exec()) {
-    case CodecSelector::Reload:
-        doc->reload(codecSelector.selectedCodec());
+    case CodecSelector::Reload: {
+        QString errorString;
+        if (!doc->reload(&errorString, codecSelector.selectedCodec())) {
+            QMessageBox::critical(this, tr("File Error"), errorString);
+            break;
+        }
         setReadOnly(d->m_document->hasDecodingError());
         if (doc->hasDecodingError())
             currentEditorChanged(Core::EditorManager::instance()->currentEditor());
         else
             Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String(Constants::SELECT_ENCODING));
-        break;
+        break; }
     case CodecSelector::Save:
         doc->setCodec(codecSelector.selectedCodec());
         Core::EditorManager::instance()->saveEditor(editor());
@@ -555,9 +560,9 @@ bool BaseTextEditorWidget::createNew(const QString &contents)
     return true;
 }
 
-bool BaseTextEditorWidget::open(const QString &fileName)
+bool BaseTextEditorWidget::open(QString *errorString, const QString &fileName)
 {
-    if (d->m_document->open(fileName)) {
+    if (d->m_document->open(errorString, fileName)) {
         moveCursor(QTextCursor::Start);
         setReadOnly(d->m_document->hasDecodingError());
         return true;
index 61727fd..a83072b 100644 (file)
@@ -138,7 +138,7 @@ public:
     // EditorInterface
     Core::IFile * file();
     bool createNew(const QString &contents);
-    virtual bool open(const QString &fileName = QString());
+    virtual bool open(QString *errorString, const QString &fileName = QString());
     QByteArray saveState() const;
     bool restoreState(const QByteArray &state);
     QString displayName() const;
@@ -560,7 +560,7 @@ public:
     //QWidget *widget() { return e; }
     Core::IFile * file() { return e->file(); }
     bool createNew(const QString &contents) { return e->createNew(contents); }
-    bool open(const QString &fileName = QString()) { return e->open(fileName); }
+    bool open(QString *errorString, const QString &fileName = QString()) { return e->open(errorString, fileName); }
     QString displayName() const { return e->displayName(); }
     void setDisplayName(const QString &title) { e->setDisplayName(title); emit changed(); }
 
index 6555131..1c95dfd 100644 (file)
@@ -88,8 +88,10 @@ Core::IFile::ReloadBehavior SubmitEditorFile::reloadBehavior(ChangeTrigger state
     return BehaviorSilent;
 }
 
-void SubmitEditorFile::reload(ReloadFlag flag, ChangeType type)
+bool SubmitEditorFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
 {
+    Q_UNUSED(errorString)
     Q_UNUSED(flag)
     Q_UNUSED(type)
+    return true;
 }
index 9987c71..554d46f 100644 (file)
@@ -55,7 +55,7 @@ public:
     bool isSaveAsAllowed() const { return false; }
     bool save(QString *errorString, const QString &fileName);
     ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
-    void reload(ReloadFlag flag, ChangeType type);
+    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
     void rename(const QString &newName);
 
     void setFileName(const QString name);
index 66eb7e9..645131c 100644 (file)
@@ -330,26 +330,20 @@ bool VCSBaseSubmitEditor::createNew(const QString &contents)
     return true;
 }
 
-bool VCSBaseSubmitEditor::open(const QString &fileName)
+bool VCSBaseSubmitEditor::open(QString *errorString, const QString &fileName)
 {
     if (fileName.isEmpty())
         return false;
 
-    const QFileInfo fi(fileName);
-    if (!fi.isFile() || !fi.isReadable())
+    Utils::FileReader reader;
+    if (!reader.fetch(fileName, QIODevice::Text, errorString))
         return false;
 
-    QFile file(fileName);
-    if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
-        qWarning("Unable to open %s: %s", qPrintable(fileName), qPrintable(file.errorString()));
-        return false;
-    }
-
-    const QString text = QString::fromLocal8Bit(file.readAll());
+    const QString text = QString::fromLocal8Bit(reader.data());
     if (!createNew(text))
         return false;
 
-    m_d->m_file->setFileName(fi.absoluteFilePath());
+    m_d->m_file->setFileName(QFileInfo(fileName).absoluteFilePath());
     return true;
 }
 
index 1273a00..3e4f7ea 100644 (file)
@@ -119,7 +119,7 @@ public:
 
     // Core::IEditor
     virtual bool createNew(const QString &contents);
-    virtual bool open(const QString &fileName);
+    virtual bool open(QString *errorString, const QString &fileName);
     virtual Core::IFile *file();
     virtual QString displayName() const;
     virtual void setDisplayName(const QString &title);