From 9dbac2320e49e2c529da6ee497c43a31699dd379 Mon Sep 17 00:00:00 2001 From: mae Date: Fri, 8 May 2009 17:57:27 +0200 Subject: [PATCH] some work on the save-modified-files logic. We no longer rely on QFileInfo to tell us that a file is not writable, but accept that the attempt to save a file might actually fail (:-) ). This solves the NT network domain issue without the insane slowness. The stuff needs more work. We do not have any UI for failing save operations when closing creator (other than it doesn't close). Bad. --- .../editormanager/editormanager.cpp | 31 +++++++++++++------ src/plugins/coreplugin/filemanager.cpp | 1 + src/plugins/coreplugin/mainwindow.cpp | 4 +-- src/plugins/texteditor/basetextdocument.cpp | 11 ------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 9bc7c468b84..c28a6472f1d 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -678,9 +678,9 @@ bool EditorManager::closeEditors(const QList editorsToClose, bool askA if (cancelled) return false; if (!list.isEmpty()) { + closingFailed = true; QSet skipSet = editorsForFiles(list).toSet(); acceptedEditors = acceptedEditors.toSet().subtract(skipSet).toList(); - closingFailed = false; } } if (acceptedEditors.isEmpty()) @@ -1176,23 +1176,35 @@ bool EditorManager::saveFile(IEditor *editor) file->checkPermissions(); const QString &fileName = file->fileName(); - if (!fileName.isEmpty() && file->isReadOnly()) { + + if (fileName.isEmpty()) + return saveFileAs(editor); + + bool success = false; + + // try saving, no matter what isReadOnly tells us + m_d->m_core->fileManager()->blockFileChange(file); + success = file->save(fileName); + m_d->m_core->fileManager()->unblockFileChange(file); + + if (!success) { MakeWritableResult answer = makeEditorWritable(editor); if (answer == Failed) return false; if (answer == SavedAs) return true; + + file->checkPermissions(); + + m_d->m_core->fileManager()->blockFileChange(file); + success = file->save(fileName); + m_d->m_core->fileManager()->unblockFileChange(file); } - if (file->isReadOnly() || fileName.isEmpty()) - return saveFileAs(editor); - - m_d->m_core->fileManager()->blockFileChange(file); - const bool success = file->save(fileName); - m_d->m_core->fileManager()->unblockFileChange(file); if (success) m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName()); + return success; } @@ -1214,7 +1226,7 @@ EditorManager::ReadOnlyAction QPushButton *saveAsButton = 0; if (displaySaveAsButton) - msgBox.addButton(QObject::tr("Save as ..."), QMessageBox::ActionRole); + saveAsButton = msgBox.addButton(QObject::tr("Save as ..."), QMessageBox::ActionRole); msgBox.setDefaultButton(sccButton ? sccButton : makeWritableButton); msgBox.exec(); @@ -1283,6 +1295,7 @@ bool EditorManager::saveFileAs(IEditor *editor) m_d->m_core->fileManager()->blockFileChange(editor->file()); const bool success = editor->file()->save(absoluteFilePath); m_d->m_core->fileManager()->unblockFileChange(editor->file()); + editor->file()->checkPermissions(); if (success) m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName()); diff --git a/src/plugins/coreplugin/filemanager.cpp b/src/plugins/coreplugin/filemanager.cpp index a13c72accc3..d962bcb3a2c 100644 --- a/src/plugins/coreplugin/filemanager.cpp +++ b/src/plugins/coreplugin/filemanager.cpp @@ -383,6 +383,7 @@ QList FileManager::saveModifiedFiles(const QList &files, if (!fileName.isEmpty()) { blockFileChange(file); ok = file->save(fileName); + file->checkPermissions(); unblockFileChange(file); } if (!ok) diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 446b7544bb3..6a471f9c3f3 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -354,8 +354,8 @@ void MainWindow::closeEvent(QCloseEvent *event) // Save opened files bool cancelled; - fileManager()->saveModifiedFiles(fileManager()->modifiedFiles(), &cancelled); - if (cancelled) { + QList notSaved = fileManager()->saveModifiedFiles(fileManager()->modifiedFiles(), &cancelled); + if (cancelled || !notSaved.isEmpty()) { event->ignore(); return; } diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index 55b9e143792..17141e8cc3d 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -163,18 +163,7 @@ 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; }