Commit 12e27549 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced IFile::checkPermission() and use it to reduce the number of calls to isWritable().

Done with: mae
parent cc3f7961
......@@ -1201,6 +1201,8 @@ bool EditorManager::saveFile(IEditor *editor)
return false;
IFile *file = editor->file();
file->checkPermissions();
const QString &fileName = file->fileName();
if (!fileName.isEmpty() && file->isReadOnly()) {
MakeWritableResult answer =
......@@ -1270,6 +1272,7 @@ EditorManager::makeEditorWritable(IEditor *editor)
QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with SCC."));
return Failed;
}
file->checkPermissions();
return OpenedWithVersionControl;
case RO_MakeWriteable: {
const bool permsOk = QFile::setPermissions(fileName, QFile::permissions(fileName) | QFile::WriteUser);
......@@ -1278,6 +1281,7 @@ EditorManager::makeEditorWritable(IEditor *editor)
return Failed;
}
}
file->checkPermissions();
return MadeWritable;
case RO_SaveAs :
return saveFileAs(editor) ? SavedAs : Failed;
......
......@@ -60,6 +60,8 @@ public:
virtual void modified(ReloadBehavior *behavior) = 0;
virtual void checkPermissions() {}
signals:
void changed();
};
......
......@@ -70,6 +70,7 @@ BaseTextDocument::BaseTextDocument()
{
m_documentMarker = new DocumentMarker(m_document);
m_lineTerminatorMode = NativeLineTerminator;
m_fileIsReadOnly = false;
m_isBinaryData = false;
m_codec = QTextCodec::codecForLocale();
m_hasDecodingError = false;
......@@ -149,22 +150,34 @@ bool BaseTextDocument::isReadOnly() const
const QFileInfo fi(m_fileName);
return m_fileIsReadOnly;
}
bool BaseTextDocument::isModified() const
{
return m_document->isModified();
}
void BaseTextDocument::checkPermissions()
{
if (!m_fileName.isEmpty()) {
const QFileInfo fi(m_fileName);
#ifdef Q_OS_WIN
// Check for permissions on NTFS file systems
qt_ntfs_permission_lookup++;
// Check for permissions on NTFS file systems
qt_ntfs_permission_lookup++;
#endif
const bool ro = !fi.isWritable();
m_fileIsReadOnly = !fi.isWritable();
#ifdef Q_OS_WIN
qt_ntfs_permission_lookup--;
qt_ntfs_permission_lookup--;
#endif
return ro;
}
bool BaseTextDocument::isModified() const
{
return m_document->isModified();
} else {
m_fileIsReadOnly = false;
}
}
bool BaseTextDocument::open(const QString &fileName)
......@@ -172,6 +185,7 @@ bool BaseTextDocument::open(const QString &fileName)
QString title = tr("untitled");
if (!fileName.isEmpty()) {
const QFileInfo fi(fileName);
m_fileIsReadOnly = !fi.isWritable();
m_fileName = fi.absoluteFilePath();
QFile file(fileName);
......
......@@ -83,6 +83,7 @@ public:
virtual bool isReadOnly() const;
virtual bool isModified() const;
virtual bool isSaveAsAllowed() const { return true; }
virtual void checkPermissions();
virtual void modified(Core::IFile::ReloadBehavior *behavior);
virtual QString mimeType() const;
void setMimeType(const QString &mt);
......@@ -141,6 +142,7 @@ private:
LineTerminatorMode m_lineTerminatorMode;
QTextCodec *m_codec;
bool m_fileIsReadOnly;
bool m_isBinaryData;
bool m_hasDecodingError;
QByteArray m_decodingErrorSample;
......
......@@ -1332,15 +1332,6 @@ void BaseTextEditorPrivate::setupDocumentSignals(BaseTextDocument *document)
q->slotUpdateExtraAreaWidth();
}
#ifndef TEXTEDITOR_STANDALONE
bool BaseTextEditorPrivate::needMakeWritableCheck() const
{
return !m_document->isModified()
&& !m_document->fileName().isEmpty()
&& m_document->isReadOnly();
}
#endif
bool Parenthesis::hasClosingCollapse(const Parentheses &parentheses)
{
return closeCollapseAtPos(parentheses) >= 0;
......
......@@ -142,9 +142,6 @@ public:
#endif
void setupDocumentSignals(BaseTextDocument *document);
void updateLineSelectionColor();
#ifndef TEXTEDITOR_STANDALONE
bool needMakeWritableCheck() const;
#endif
void print(QPrinter *printer);
......
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