]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Update Dolphin version to 2.1.85 for KDE 4.10 Beta 2
[dolphin.git] / src / views / dolphinview.cpp
index 9051d9827a8667338d5b1c66f150c09ff5334805..e677613bac2ca45714e2d763f250aa027e8e1cd8 100644 (file)
@@ -154,6 +154,7 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
 
     connect(m_model, SIGNAL(directoryLoadingStarted()),       this, SLOT(slotDirectoryLoadingStarted()));
     connect(m_model, SIGNAL(directoryLoadingCompleted()),     this, SLOT(slotDirectoryLoadingCompleted()));
+    connect(m_model, SIGNAL(directoryLoadingCanceled()),      this, SIGNAL(directoryLoadingCanceled()));
     connect(m_model, SIGNAL(directoryLoadingProgress(int)),   this, SIGNAL(directoryLoadingProgress(int)));
     connect(m_model, SIGNAL(directorySortingProgress(int)),   this, SIGNAL(directorySortingProgress(int)));
     connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
@@ -598,6 +599,8 @@ void DolphinView::setUrl(const KUrl& url)
         return;
     }
 
+    clearSelection();
+
     emit urlAboutToBeChanged(url);
     m_url = url;
 
@@ -628,31 +631,32 @@ void DolphinView::invertSelection()
 
 void DolphinView::clearSelection()
 {
+    m_selectedUrls.clear();
     m_container->controller()->selectionManager()->clearSelection();
 }
 
 void DolphinView::renameSelectedItems()
 {
     const KFileItemList items = selectedItems();
-     if (items.isEmpty()) {
-         return;
-     }
-
-     if (items.count() == 1 && GeneralSettings::renameInline()) {
-         const int index = m_model->index(items.first());
-         m_view->editRole(index, "text");
-     } else {
-         RenameDialog* dialog = new RenameDialog(this, items);
-         dialog->setAttribute(Qt::WA_DeleteOnClose);
-         dialog->show();
-         dialog->raise();
-         dialog->activateWindow();
-     }
-
-     // Assure that the current index remains visible when KFileItemModel
-     // will notify the view about changed items (which might result in
-     // a changed sorting).
-     m_assureVisibleCurrentIndex = true;
+    if (items.isEmpty()) {
+        return;
+    }
+
+    if (items.count() == 1 && GeneralSettings::renameInline()) {
+        const int index = m_model->index(items.first());
+        m_view->editRole(index, "text");
+    } else {
+        RenameDialog* dialog = new RenameDialog(this, items);
+        dialog->setAttribute(Qt::WA_DeleteOnClose);
+        dialog->show();
+        dialog->raise();
+        dialog->activateWindow();
+    }
+
+    // Assure that the current index remains visible when KFileItemModel
+    // will notify the view about changed items (which might result in
+    // a changed sorting).
+    m_assureVisibleCurrentIndex = true;
 }
 
 void DolphinView::trashSelectedItems()
@@ -1178,8 +1182,11 @@ QString DolphinView::viewPropertiesContext() const
 
 void DolphinView::observeCreatedItem(const KUrl& url)
 {
-    markUrlAsCurrent(url);
-    markUrlsAsSelected(QList<KUrl>() << url);
+    if (m_active) {
+        clearSelection();
+        markUrlAsCurrent(url);
+        markUrlsAsSelected(QList<KUrl>() << url);
+    }
 }
 
 void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl)
@@ -1219,20 +1226,18 @@ void DolphinView::updateViewState()
     }
 
     if (!m_selectedUrls.isEmpty()) {
-        clearSelection();
-
         KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
         QSet<int> selectedItems = selectionManager->selectedItems();
 
-        foreach (const KUrl& url, m_selectedUrls) {
-            const int index = m_model->index(url);
+        for (QList<KUrl>::iterator it = m_selectedUrls.begin(); it != m_selectedUrls.end(); ++it) {
+            const int index = m_model->index(*it);
             if (index >= 0) {
                 selectedItems.insert(index);
+                m_selectedUrls.erase(it);
             }
         }
 
         selectionManager->setSelectedItems(selectedItems);
-        m_selectedUrls.clear();
     }
 }
 
@@ -1356,9 +1361,18 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
         if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
             const KUrl oldUrl = oldItem.url();
 
-            QHash<QByteArray, QVariant> data;
-            data.insert(role, value);
-            m_model->setData(index, data);
+            const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName);
+            const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
+            if (!newNameExistsAlready) {
+                // Only change the data in the model if no item with the new name
+                // is in the model yet. If there is an item with the new name
+                // already, calling KonqOperations::rename() will open a dialog
+                // asking for a new name, and KFileItemModel will update the
+                // data when the dir lister signals that the file name has changed.
+                QHash<QByteArray, QVariant> data;
+                data.insert(role, value);
+                m_model->setData(index, data);
+            }
 
             KonqOperations::rename(this, oldUrl, newName);
         }