forked from qt-creator/qt-creator
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: Tobias Hunger <tobias.hunger@nokia.com> Reviewed-by: Daniel Teske <daniel.teske@nokia.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user