From: Chirag Anand Date: Thu, 22 Sep 2011 12:38:49 +0000 (+0530) Subject: Fixed bug for selecting files with --select parameter. X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/9ca11175a4c9e93607131c45b8e5470e1e5014b7?ds=inline Fixed bug for selecting files with --select parameter. 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 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 3def8d88c..6ca6e59f7 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -330,8 +330,10 @@ void DolphinMainWindow::openFiles(const QList& 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)); } } } diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 9b96d7eac..a36ca0cdf 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -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(); diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index b79eec4ee..3c8cdba2c 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -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. */ diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 2fa9196bf..71c67b1cf 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -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" diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index cc2e25b49..74cec7dcc 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -186,6 +186,12 @@ public: */ void markUrlsAsSelected(const QList& 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