[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bkdevplatform=5D_plugins/grepview=3A_Make_next/previ?=
From:       Alexander Dymo <adymo () kdevelop ! org>
Date:       2011-06-06 18:58:45
Message-ID: 20110606185845.BB87DA60A9 () git ! kde ! org
[Download RAW message or body]

Git commit 4eae7c52cda737ef3de1d433dc05b06fb93704eb by Alexander Dymo.
Committed on 06/06/2011 at 20:56.
Pushed by dymo into branch 'master'.

Make next/previous search result actions in find/replace plugin work even
when no result is currently selected in the output.

M  +36   -8    plugins/grepview/grepoutputmodel.cpp     
M  +4    -8    plugins/grepview/grepoutputview.cpp     

http://commits.kde.org/kdevplatform/4eae7c52cda737ef3de1d433dc05b06fb93704eb

diff --git a/plugins/grepview/grepoutputmodel.cpp b/plugins/grepview/grepoutputmodel.cpp
index bca60e3..11194f5 100644
--- a/plugins/grepview/grepoutputmodel.cpp
+++ b/plugins/grepview/grepoutputmodel.cpp
@@ -239,10 +239,24 @@ void GrepOutputModel::activate( const QModelIndex &idx )
 
 QModelIndex GrepOutputModel::previousItemIndex(const QModelIndex &currentIdx) const
 {
-    int row = currentIdx.row();
-    GrepOutputItem* current_item = dynamic_cast<GrepOutputItem*>(itemFromIndex(currentIdx));
-    if(current_item->parent() != 0) //we do nothing if it's the root item
-    {
+    GrepOutputItem* current_item = 0;
+
+    if (!currentIdx.isValid()) {
+        // no item selected, search recursively for the last item in search results
+        QStandardItem *it = item(0,0);
+        while (it) {
+            QStandardItem *child = it->child( it->rowCount() - 1 );
+            if (!child) return it->index();
+            it = child;
+        }
+        return QModelIndex();
+    }
+    else
+        current_item = dynamic_cast<GrepOutputItem*>(itemFromIndex(currentIdx));
+
+    if (current_item->parent() != 0) {
+        int row = currentIdx.row();
+
         if(!current_item->isText()) // the item is a file
         {
             int item_row = current_item->row();
@@ -272,10 +286,24 @@ QModelIndex GrepOutputModel::previousItemIndex(const QModelIndex &currentIdx) co
 
 QModelIndex GrepOutputModel::nextItemIndex(const QModelIndex &currentIdx) const
 {
-    int row = currentIdx.row();
-    GrepOutputItem* current_item = dynamic_cast<GrepOutputItem*>(itemFromIndex(currentIdx));
-    if(current_item->parent() != 0) //we do nothing if it's the root item
-    {
+    GrepOutputItem* current_item = 0;
+
+    if (!currentIdx.isValid()) {
+        QStandardItem *it = item(0,0);
+        if (!it) return QModelIndex();
+        current_item = dynamic_cast<GrepOutputItem*>(it);
+    }
+    else
+        current_item = dynamic_cast<GrepOutputItem*>(itemFromIndex(currentIdx));
+
+    if (current_item->parent() == 0) {
+        // root item with overview of search results
+        if (current_item->rowCount() > 0)
+            return nextItemIndex(current_item->child(0)->index());
+        else
+            return QModelIndex();
+    } else {
+        int row = currentIdx.row();
         if(!current_item->isText()) // the item is a file
         {
             int item_row = current_item->row();
diff --git a/plugins/grepview/grepoutputview.cpp b/plugins/grepview/grepoutputview.cpp
index 767b74d..4c4883a 100644
--- a/plugins/grepview/grepoutputview.cpp
+++ b/plugins/grepview/grepoutputview.cpp
@@ -280,10 +280,8 @@ void GrepOutputView::expandElements(const QModelIndex&)
 
 void GrepOutputView::selectPreviousItem()
 {
-    QModelIndex idx = resultsTreeView->currentIndex();
-    if(idx.isValid())
-    {
-        QModelIndex prev_idx = model()->previousItemIndex(idx);
+    QModelIndex prev_idx = model()->previousItemIndex(resultsTreeView->currentIndex());
+    if (prev_idx.isValid()) {
         resultsTreeView->setCurrentIndex(prev_idx);
         model()->activate(prev_idx);
     }
@@ -291,10 +289,8 @@ void GrepOutputView::selectPreviousItem()
 
 void GrepOutputView::selectNextItem()
 {
-    QModelIndex idx = resultsTreeView->currentIndex();
-    if(idx.isValid())
-    {
-        QModelIndex next_idx = model()->nextItemIndex(idx);
+    QModelIndex next_idx = model()->nextItemIndex(resultsTreeView->currentIndex());
+    if (next_idx.isValid()) {
         resultsTreeView->setCurrentIndex(next_idx);
         model()->activate(next_idx);
     }

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic