From 9b82d98ededb90badf50e5c35aff8f11d41958b1 Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
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 7b01f88626d..27116010458 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -698,9 +698,9 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
         if (cancelled)
             return false;
         if (!list.isEmpty()) {
+            closingFailed = true;
             QSet<IEditor*> skipSet = editorsForFiles(list).toSet();
             acceptedEditors = acceptedEditors.toSet().subtract(skipSet).toList();
-            closingFailed = false;
         }
     }
     if (acceptedEditors.isEmpty())
@@ -1203,23 +1203,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;
-    }
 
-    if (file->isReadOnly() || fileName.isEmpty())
-        return saveFileAs(editor);
+        file->checkPermissions();
+
+        m_d->m_core->fileManager()->blockFileChange(file);
+        success = file->save(fileName);
+        m_d->m_core->fileManager()->unblockFileChange(file);
+    }
 
-    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;
 }
 
@@ -1241,7 +1253,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();
@@ -1310,6 +1322,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 b42611b2217..a851fa792df 100644
--- a/src/plugins/coreplugin/filemanager.cpp
+++ b/src/plugins/coreplugin/filemanager.cpp
@@ -394,6 +394,7 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &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 3c552a83aae..3ddf4fc75c2 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<IFile*> 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;
     }
-- 
GitLab