#include "bineditor.h"
#include "bineditorconstants.h"
+#include <coreplugin/icore.h>
+
+#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
#include <QtGui/QMenu>
#include <QtGui/QAction>
#include <QtGui/QMainWindow>
+#include <QtGui/QMessageBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QRegExpValidator>
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;
}
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:
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:
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); }
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)
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);
// 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;
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,
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;
}
// handle the IFiles
+ QStringList errorStrings;
foreach (IFile *file, changedIFiles) {
IFile::ChangeTrigger behavior = IFile::TriggerInternal;
IFile::ChangeType type = IFile::TypePermissions;
// 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
// 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;
}
}
}
}
}
+ 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);
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() {}
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;
}
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
#include <texteditor/plaintexteditor.h>
#include <utils/qtcassert.h>
+#include <utils/fileutils.h>
#include <QtDesigner/QDesignerFormWindowInterface>
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()));
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;
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);
// 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;
void configureXmlEditor() const;
private slots:
- void slotOpen(const QString &fileName);
+ void slotOpen(QString *errorString, const QString &fileName);
private:
void syncXmlEditor(const QString &contents);
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
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;
signals:
// Internal
void saved();
- void reload(const QString &);
+ void reload(QString *errorString, const QString &);
void setDisplayName(const QString &);
public slots:
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;
}
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;
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;
}
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;
};
#include <QtCore/QMap>
#include <QtCore/QFileInfo>
+#include <QtCore/QDir>
#include <QtGui/QWidget>
#include <QtCore/QtDebug>
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
~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;
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);
}
}
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);
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;
}
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);
};
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
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;
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;
}
/*!
// 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();
}
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;
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;
}
/*!
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;
return rc;
}
-bool ResourceEditorW::open(const QString &fileName /* = QString() */)
+bool ResourceEditorW::open(QString *errorString, const QString &fileName /* = QString() */)
{
if (debugResourceEditorW)
qDebug() << "ResourceEditorW::open: " << fileName;
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());
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
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;
// 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; }
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)
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
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);
#include <coreplugin/icore.h>
#include <coreplugin/filemanager.h>
+#include <QtGui/QMainWindow>
+#include <QtGui/QMessageBox>
+
using namespace TaskList::Internal;
// --------------------------------------------------------------------------
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;
}
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())
{
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)
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();
emit changed();
}
-bool BaseTextDocument::open(const QString &fileName)
+bool BaseTextDocument::open(QString *errorString, const QString &fileName)
{
QString title = tr("untitled");
if (!fileName.isEmpty()) {
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();
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
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);
}
}
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);
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);
void setCodec(QTextCodec *c);
QByteArray decodingErrorSample() const;
- void reload(QTextCodec *codec);
+ bool reload(QString *errorString, QTextCodec *codec);
void cleanWhitespace(const QTextCursor &cursor);
signals:
#include <QtGui/QToolBar>
#include <QtGui/QInputDialog>
#include <QtGui/QMenu>
+#include <QtGui/QMessageBox>
//#define DO_FOO
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());
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;
// 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;
//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(); }
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;
}
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);
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;
}
// 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);