forked from qt-creator/qt-creator
Introduced IFile::checkPermission() and use it to reduce the number of calls to isWritable().
Done with: mae
This commit is contained in:
@@ -1173,6 +1173,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 =
|
||||
@@ -1242,6 +1244,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);
|
||||
@@ -1250,6 +1253,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,17 +150,8 @@ bool BaseTextDocument::isReadOnly() const
|
||||
|
||||
const QFileInfo fi(m_fileName);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
// Check for permissions on NTFS file systems
|
||||
qt_ntfs_permission_lookup++;
|
||||
#endif
|
||||
return m_fileIsReadOnly;
|
||||
|
||||
const bool ro = !fi.isWritable();
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
qt_ntfs_permission_lookup--;
|
||||
#endif
|
||||
return ro;
|
||||
}
|
||||
|
||||
bool BaseTextDocument::isModified() const
|
||||
@@ -167,11 +159,33 @@ 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++;
|
||||
#endif
|
||||
|
||||
m_fileIsReadOnly = !fi.isWritable();
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
qt_ntfs_permission_lookup--;
|
||||
#endif
|
||||
|
||||
} else {
|
||||
m_fileIsReadOnly = false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@@ -1312,15 +1312,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;
|
||||
|
@@ -128,9 +128,6 @@ public:
|
||||
#endif
|
||||
void setupDocumentSignals(BaseTextDocument *document);
|
||||
void updateLineSelectionColor();
|
||||
#ifndef TEXTEDITOR_STANDALONE
|
||||
bool needMakeWritableCheck() const;
|
||||
#endif
|
||||
|
||||
void print(QPrinter *printer);
|
||||
|
||||
|
Reference in New Issue
Block a user