add errorString output argument to IFile::reload() & IEditor::open()

add/unify read error handling in all affected classes
This commit is contained in:
Oswald Buddenhagen
2011-04-04 15:24:13 +02:00
parent f1f9904d35
commit fae7dc9584
44 changed files with 204 additions and 134 deletions

View 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

View 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);

View 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;
}

View 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)

View 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();