Commit f916d38d authored by Eike Ziller's avatar Eike Ziller
Browse files

Make IFile::isReadOnly consistent.



It is supposed to refer to the property of the file on disk (if there is
any).

Task-number: QTCREATORBUG-4998
Change-Id: Iaed62c17d124b364aecec4d1f910046bade42d40
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent d7b0ceac
......@@ -80,11 +80,6 @@ bool AutotoolsProjectFile::isModified() const
return false;
}
bool AutotoolsProjectFile::isReadOnly() const
{
return true;
}
bool AutotoolsProjectFile::isSaveAsAllowed() const
{
return false;
......
......@@ -65,7 +65,6 @@ public:
QString suggestedFileName() const;
QString mimeType() const;
bool isModified() const;
bool isReadOnly() const;
bool isSaveAsAllowed() const;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
void rename(const QString &newName);
......
......@@ -297,7 +297,7 @@ public:
bool isModified() const { return m_editor->isMemoryView() ? false : m_editor->isModified(); }
bool isReadOnly() const {
if (m_editor->isMemoryView())
if (m_editor->isMemoryView() || m_fileName.isEmpty())
return false;
const QFileInfo fi(m_fileName);
return !fi.isWritable();
......
......@@ -780,11 +780,6 @@ bool CMakeFile::isModified() const
return false;
}
bool CMakeFile::isReadOnly() const
{
return true;
}
bool CMakeFile::isSaveAsAllowed() const
{
return false;
......
......@@ -207,7 +207,6 @@ public:
QString mimeType() const;
bool isModified() const;
bool isReadOnly() const;
bool isSaveAsAllowed() const;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
......
......@@ -311,12 +311,15 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
: e.displayName();
case Qt::DecorationRole:
{
bool readOnly = false;
if (e.editor)
readOnly = e.editor->file()->isReadOnly();
else
readOnly = !QFileInfo(e.m_fileName).isWritable();
return readOnly ? d->m_lockedIcon : QIcon();
bool showLock = false;
if (e.editor) {
showLock = e.editor->file()->fileName().isEmpty()
? false
: e.editor->file()->isReadOnly();
} else {
showLock = !QFileInfo(e.m_fileName).isWritable();
}
return showLock ? d->m_lockedIcon : QIcon();
}
case Qt::ToolTipRole:
return e.fileName().isEmpty()
......
......@@ -213,7 +213,8 @@ void OpenEditorsWindow::setEditors(EditorView *mainView, EditorView *view, OpenE
QTreeWidgetItem *item = new QTreeWidgetItem();
if (hi.file->isModified())
title += tr("*");
item->setIcon(0, hi.file->isReadOnly() ? model->lockedIcon() : m_emptyIcon);
item->setIcon(0, !hi.file->fileName().isEmpty() && hi.file->isReadOnly()
? model->lockedIcon() : m_emptyIcon);
item->setText(0, title);
item->setToolTip(0, hi.file->fileName());
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.file.data()));
......@@ -240,7 +241,8 @@ void OpenEditorsWindow::setEditors(EditorView *mainView, EditorView *view, OpenE
QString title = model->displayNameForFile(hi.file);
if (hi.file->isModified())
title += tr("*");
item->setIcon(0, hi.file->isReadOnly() ? model->lockedIcon() : m_emptyIcon);
item->setIcon(0, !hi.file->fileName().isEmpty() && hi.file->isReadOnly()
? model->lockedIcon() : m_emptyIcon);
item->setText(0, title);
item->setToolTip(0, hi.file->fileName());
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.file.data()));
......
......@@ -400,9 +400,13 @@ void EditorToolBar::updateEditorStatus(IEditor *editor)
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
if (editor->file()->isReadOnly()) {
if (editor->file()->fileName().isEmpty()) {
d->m_lockButton->setIcon(QIcon());
d->m_lockButton->setEnabled(false);
d->m_lockButton->setToolTip(QString());
} else if (editor->file()->isReadOnly()) {
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->lockedIcon()));
d->m_lockButton->setEnabled(!editor->file()->fileName().isEmpty());
d->m_lockButton->setEnabled(true);
d->m_lockButton->setToolTip(tr("Make Writable"));
} else {
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->unlockedIcon()));
......
......@@ -607,10 +607,10 @@ static QList<IFile *> saveModifiedFilesHelper(const QList<IFile *> &files,
if (name.isEmpty())
name = file->suggestedFileName();
// There can be several FileInterfaces pointing to the same file
// Select one that is not readonly.
if (!(modifiedFilesMap.key(name, 0)
&& file->isReadOnly()))
// There can be several IFiles pointing to the same file
// Prefer one that is not readonly
// (even though it *should* not happen that the IFiles are inconsistent with readonly)
if (!modifiedFilesMap.key(name, 0) || !file->isReadOnly())
modifiedFilesMap.insert(file, name);
}
}
......
......@@ -35,6 +35,7 @@
#include "infobar.h"
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
namespace Core {
......@@ -66,6 +67,13 @@ bool IFile::shouldAutoSave() const
return false;
}
bool IFile::isReadOnly() const
{
if (fileName().isEmpty())
return false;
return !QFileInfo(fileName()).isWritable();
}
bool IFile::autoSave(QString *errorString, const QString &fileName)
{
if (!save(errorString, fileName, true))
......
......@@ -93,7 +93,7 @@ public:
virtual bool shouldAutoSave() const;
virtual bool isModified() const = 0;
virtual bool isReadOnly() const = 0;
virtual bool isReadOnly() const;
virtual bool isSaveAsAllowed() const = 0;
virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
......
......@@ -137,14 +137,6 @@ bool FormWindowFile::isModified() const
return m_formWindow && m_formWindow->isDirty();
}
bool FormWindowFile::isReadOnly() const
{
if (m_fileName.isEmpty())
return false;
const QFileInfo fi(m_fileName);
return !fi.isWritable();
}
bool FormWindowFile::isSaveAsAllowed() const
{
return true;
......
......@@ -57,7 +57,6 @@ public:
virtual QString fileName() const;
virtual bool shouldAutoSave() const;
virtual bool isModified() const;
virtual bool isReadOnly() const;
virtual bool isSaveAsAllowed() const;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
virtual QString defaultPath() const;
......
......@@ -639,11 +639,6 @@ bool GenericProjectFile::isModified() const
return false;
}
bool GenericProjectFile::isReadOnly() const
{
return true;
}
bool GenericProjectFile::isSaveAsAllowed() const
{
return false;
......
......@@ -172,7 +172,6 @@ public:
virtual QString mimeType() const;
virtual bool isModified() const;
virtual bool isReadOnly() const;
virtual bool isSaveAsAllowed() const;
virtual void rename(const QString &newName);
......
......@@ -116,11 +116,6 @@ bool ImageViewerFile::isModified() const
return false;
}
bool ImageViewerFile::isReadOnly() const
{
return true;
}
bool ImageViewerFile::isSaveAsAllowed() const
{
return false;
......
......@@ -59,7 +59,6 @@ public:
QString mimeType() const;
bool isModified() const;
bool isReadOnly() const;
bool isSaveAsAllowed() const;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
......
......@@ -69,7 +69,6 @@ public:
QString suggestedFileName() const { return QString(); }
QString mimeType() const { return QLatin1String("text/plain"); }
bool isModified() const { return false; }
bool isReadOnly() const { return false; }
bool isSaveAsAllowed() const { return false; }
ReloadBehavior reloadBehavior(ChangeTrigger, ChangeType) const { return BehaviorSilent; }
bool reload(QString *, ReloadFlag, ChangeType) { emit modified(); return true; }
......
......@@ -1078,16 +1078,8 @@ void ProjectExplorerPlugin::unloadProject()
QList<Core::IFile*> filesToSave;
filesToSave << fi;
// check the number of modified files
int readonlycount = 0;
foreach (const Core::IFile *file, filesToSave) {
if (file->isReadOnly())
++readonlycount;
}
bool success = false;
if (readonlycount > 0)
if (fi->isReadOnly())
success = Core::FileManager::saveModifiedFiles(filesToSave).isEmpty();
else
success = Core::FileManager::saveModifiedFilesSilently(filesToSave).isEmpty();
......
......@@ -88,11 +88,6 @@ bool QmlProjectFile::isModified() const
return false;
}
bool QmlProjectFile::isReadOnly() const
{
return true;
}
bool QmlProjectFile::isSaveAsAllowed() const
{
return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment