]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fixed bug for selecting files with --select parameter.
authorChirag Anand <anand.chirag@gmail.com>
Thu, 22 Sep 2011 12:38:49 +0000 (18:08 +0530)
committerChirag Anand <anand.chirag@gmail.com>
Thu, 22 Sep 2011 12:38:49 +0000 (18:08 +0530)
Files selected via --select parameter did not get current item focus.
And if files were deleted while being current item, updating the view
would select the next item instead of the first item in the list.

BUG: 257805
CCMAIL: peter.penz19@gmail.com
CCMAIL: frank78ac@googlemail.com

src/dolphinmainwindow.cpp
src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/views/dolphinview.cpp
src/views/dolphinview.h

index 3def8d88cc1ce3d78404f9dbd3584525d6322d36..6ca6e59f7900233268a63773c20956222ada038a 100644 (file)
@@ -330,8 +330,10 @@ void DolphinMainWindow::openFiles(const QList<KUrl>& files)
     const int tabCount = m_viewTab.count();
     for (int i = 0; i < tabCount; ++i) {
         m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
+        m_viewTab[i].primaryView->view()->markUrlAsCurrent(files.at(0));
         if (m_viewTab[i].secondaryView) {
             m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
+            m_viewTab[i].secondaryView->view()->markUrlAsCurrent(files.at(0));
         }
     }
 }
index 9b96d7eac5983b0264b83412bbdbd84797954495..a36ca0cdff0776e53dde04a798caee38097c2a02 100644 (file)
@@ -263,6 +263,13 @@ int KFileItemModel::index(const KFileItem& item) const
     return m_items.value(item.url(), -1);
 }
 
+int KFileItemModel::index(const KUrl& url) const
+{
+    KUrl urlToFind = url;
+    urlToFind.adjustPath(KUrl::RemoveTrailingSlash);
+    return m_items.value(urlToFind, -1);
+}
+
 KFileItem KFileItemModel::rootItem() const
 {
     const KDirLister* dirLister = m_dirLister.data();
index b79eec4eeb25e2859f0ff98e6859fa15f065d9f2..3c8cdba2c16d8f86513394b6efaff22e86d96845 100644 (file)
@@ -105,6 +105,12 @@ public:
      */
     int index(const KFileItem& item) const;
 
+    /**
+     * @return The index for the URL \a url. -1 is returned if no file-item
+     *         is found. The runtime complexity of this call is O(1).
+     */
+    int index(const KUrl& url) const;
+
     /**
      * @return Root item of all items.
      */
index 2fa9196bfa9a0ad1c0c1e82e0fa3fada0f95369b..71c67b1cf977b27809feb9d2b57123a27b32af21 100644 (file)
@@ -90,7 +90,7 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
     m_container(0),
     m_toolTipManager(0),
     m_selectionChangedTimer(0),
-    m_currentItemIndex(-1),
+    m_currentItemUrl(),
     m_restoredContentsPosition(),
     m_createdItemUrl(),
     m_selectedItems(),
@@ -925,7 +925,7 @@ bool DolphinView::itemsExpandable() const
 void DolphinView::restoreState(QDataStream& stream)
 {
     // Restore the current item that had the keyboard focus
-    stream >> m_currentItemIndex;
+    stream >> m_currentItemUrl;
 
     // Restore the view position
     stream >> m_restoredContentsPosition;
@@ -939,7 +939,14 @@ void DolphinView::restoreState(QDataStream& stream)
 void DolphinView::saveState(QDataStream& stream)
 {
     // Save the current item that has the keyboard focus
-    stream << m_container->controller()->selectionManager()->currentItem();
+    const int currentIndex = m_container->controller()->selectionManager()->currentItem();
+    if (currentIndex != -1) {
+        KFileItem item = fileItemModel()->fileItem(currentIndex);
+        KUrl currentItemUrl = item.url();
+        stream << currentItemUrl;
+    } else {
+        stream << KUrl();
+    }
 
     // Save view position
     const qreal x = m_container->horizontalScrollBar()->value();
@@ -993,10 +1000,15 @@ void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
 
 void DolphinView::updateViewState()
 {
-    if (m_currentItemIndex >= 0) {
+    if (m_currentItemUrl != KUrl()) {
         KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
-        selectionManager->setCurrentItem(m_currentItemIndex);
-        m_currentItemIndex =-1;
+        const int currentIndex = fileItemModel()->index(m_currentItemUrl);
+        if (currentIndex != -1) {
+            selectionManager->setCurrentItem(currentIndex);
+        } else {
+            selectionManager->setCurrentItem(0);
+        }
+        m_currentItemUrl = KUrl();
     }
 
     if (!m_restoredContentsPosition.isNull()) {
@@ -1301,4 +1313,9 @@ DolphinView::Sorting DolphinView::sortingForSortRole(const QByteArray& sortRole)
     return sortHash.value(sortRole);
 }
 
+void DolphinView::markUrlAsCurrent(const KUrl& url)
+{
+    m_currentItemUrl = url;
+}
+
 #include "dolphinview.moc"
index cc2e25b495538fb6e7e49a7cdc091d471c6de995..74cec7dcc0a31e58c643946a4f33940dfa1dc67b 100644 (file)
@@ -186,6 +186,12 @@ public:
      */
     void markUrlsAsSelected(const QList<KUrl>& urls);
 
+    /**
+     * Marks the item indicated by \p url as the current item after the
+     * directory DolphinView::url() has been loaded.
+     */
+    void markUrlAsCurrent(const KUrl& url);
+
     /**
      * All items that match to the pattern \a pattern will get selected
      * if \a enabled is true and deselected if  \a enabled is false.
@@ -757,7 +763,7 @@ private:
 
     QTimer* m_selectionChangedTimer;
 
-    int m_currentItemIndex;
+    KUrl m_currentItemUrl;
     QPoint m_restoredContentsPosition;
     KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu
     KFileItemList m_selectedItems; // this is used for making the View to remember selections after F5