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;
......
......@@ -58,7 +58,6 @@ public:
virtual QString mimeType() const;
virtual bool isModified() const;
virtual bool isReadOnly() const;
virtual bool isSaveAsAllowed() const;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
......
......@@ -211,11 +211,6 @@ bool Qt4PriFile::isModified() const
return false;
}
bool Qt4PriFile::isReadOnly() const
{
return false;
}
bool Qt4PriFile::isSaveAsAllowed() const
{
return false;
......
......@@ -230,7 +230,6 @@ public:
virtual QString mimeType() const;
virtual bool isModified() const;
virtual bool isReadOnly() const;
virtual bool isSaveAsAllowed() const;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
......
......@@ -97,7 +97,6 @@ public:
virtual QString mimeType() const;
bool isModified() const;
bool isReadOnly() const;
bool isSaveAsAllowed() const;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
......@@ -283,12 +282,6 @@ bool Qt4ProjectFile::isModified() const
return false; // we save after changing anyway
}
bool Qt4ProjectFile::isReadOnly() const
{
QFileInfo fi(m_filePath);
return !fi.isWritable();
}
bool Qt4ProjectFile::isSaveAsAllowed() const
{
return false;
......
......@@ -218,15 +218,6 @@ bool ResourceEditorFile::isModified() const
return m_parent->m_resourceEditor->isDirty();
}
bool ResourceEditorFile::isReadOnly() const
{
const QString fileName = m_parent->m_resourceEditor->fileName();
if (fileName.isEmpty())
return false;
const QFileInfo fi(fileName);
return !fi.isWritable();
}
bool ResourceEditorFile::isSaveAsAllowed() const
{
return true;
......
......@@ -65,7 +65,6 @@ public:
QString fileName() const;
bool shouldAutoSave() const;
bool isModified() const;
bool isReadOnly() const;
bool isSaveAsAllowed() const;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
QString defaultPath() const;
......
......@@ -81,11 +81,6 @@ bool TaskFile::isModified() const
return false;
}
bool TaskFile::isReadOnly() const
{
return true;
}
bool TaskFile::isSaveAsAllowed() const
{
return false;
......
......@@ -56,7 +56,6 @@ public:
QString mimeType() const;
bool isModified() const;
bool isReadOnly() const;
bool isSaveAsAllowed() const;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
......
......@@ -411,8 +411,6 @@ void BaseTextDocument::rename(const QString &newName)
bool BaseTextDocument::isReadOnly() const
{
if (hasDecodingError())
return true;
if (d->m_fileName.isEmpty()) //have no corresponding file, so editing is ok
return false;
return d->m_fileIsReadOnly;
......
......@@ -51,7 +51,6 @@ public:
bool isModified() const { return m_modified; }
QString mimeType() const;
bool isReadOnly() const { return false; }
bool isSaveAsAllowed() const { return false; }
bool save(QString *errorString, const QString &fileName, bool autoSave);
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
......
......@@ -11,7 +11,6 @@ HEADERS += vcsbase_global.h \
vcsbaseplugin.h \
baseannotationhighlighter.h \
diffhighlighter.h \
vcsbasetextdocument.h \
vcsbaseeditor.h \
vcsbasesubmiteditor.h \
basevcseditorfactory.h \
......@@ -40,7 +39,6 @@ SOURCES += vcsplugin.cpp \
corelistener.cpp \
baseannotationhighlighter.cpp \
diffhighlighter.cpp \
vcsbasetextdocument.cpp \
vcsbaseeditor.cpp \
vcsbasesubmiteditor.cpp \
basevcseditorfactory.cpp \
......
......@@ -33,7 +33,6 @@
#include "vcsbaseeditor.h"
#include "diffhighlighter.h"
#include "baseannotationhighlighter.h"
#include "vcsbasetextdocument.h"
#include "vcsbaseconstants.h"
#include "vcsbaseoutputwindow.h"
#include "vcsbaseplugin.h"
......@@ -50,6 +49,7 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/basetextdocumentlayout.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorconstants.h>
......@@ -663,7 +663,6 @@ VcsBaseEditorWidget::VcsBaseEditorWidget(const VcsBaseEditorParameters *type, QW
d(new Internal::VcsBaseEditorWidgetPrivate(this, type))
{
viewport()->setMouseTracking(true);
setBaseTextDocument(new Internal::VcsBaseTextDocument);
setMimeType(QLatin1String(d->m_parameters->mimeType));
}
......@@ -696,21 +695,12 @@ VcsBaseEditorWidget::~VcsBaseEditorWidget()
void VcsBaseEditorWidget::setForceReadOnly(bool b)
{
Internal::VcsBaseTextDocument *vbd = qobject_cast<Internal::VcsBaseTextDocument*>(baseTextDocument());
VcsBaseEditor *eda = qobject_cast<VcsBaseEditor *>(editor());
QTC_ASSERT(vbd != 0 && eda != 0, return);
QTC_ASSERT(eda != 0, return);
setReadOnly(b);
vbd->setForceReadOnly(b);
eda->setTemporary(b);
}
bool VcsBaseEditorWidget::isForceReadOnly() const
{
const Internal::VcsBaseTextDocument *vbd = qobject_cast<const Internal::VcsBaseTextDocument*>(baseTextDocument());
QTC_ASSERT(vbd, return false);
return vbd->isForceReadOnly();
}
QString VcsBaseEditorWidget::source() const
{
return d->m_source;
......
......@@ -113,7 +113,6 @@ public:
* by default since it should not trigger when patches are opened as
* files. */
void setForceReadOnly(bool b);
bool isForceReadOnly() const;
QString source() const;
void setSource(const QString &source);
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "vcsbasetextdocument.h"
using namespace VcsBase::Internal;
VcsBaseTextDocument::VcsBaseTextDocument() :
m_forceReadOnly(false)
{
}
bool VcsBaseTextDocument::isReadOnly() const
{
return m_forceReadOnly ?
true :
TextEditor::BaseTextDocument::isReadOnly();
}
bool VcsBaseTextDocument::isModified() const
{
return m_forceReadOnly ?
false :
TextEditor::BaseTextDocument::isModified();
}
void VcsBaseTextDocument::setForceReadOnly(bool b)
{
m_forceReadOnly = b;
}
bool VcsBaseTextDocument::isForceReadOnly() const
{
return m_forceReadOnly;
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef VCSBASETEXTDOCUMENT_H
#define VCSBASETEXTDOCUMENT_H
#include <texteditor/basetextdocument.h>
namespace VcsBase {
namespace Internal {
// A read-only text document.
class VcsBaseTextDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
VcsBaseTextDocument();
bool isReadOnly() const;
bool isModified() const;
void setForceReadOnly(bool b);
bool isForceReadOnly() const;
private:
bool m_forceReadOnly;
};
} // namespace Internal
} // namespace VcsBase
#endif // VCSBASETEXTDOCUMENT_H