Bug 72523

Summary: Grep dialog doesn't prepopulate with selected text
Product: [Developer tools] kdevplatform Reporter: Dan Christensen <daniel_l_christensen>
Component: grepviewAssignee: KDevelop Developers <kdevelop-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: 1.3.0   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Patch
Updated patch

Description Dan Christensen 2004-01-13 03:30:38 UTC
Version:           3.0.0b2 (using KDE 3.1.94 (3.2 Beta 2), SuSE)
Compiler:          gcc version 3.3.1 (SuSE Linux)
OS:          Linux (i686) release 2.4.21-144-default

The grep dialog should populate the pattern field with the selected text.
Comment 1 Dan Christensen 2004-01-13 03:31:26 UTC
Created attachment 4132 [details]
Patch

Here is a suggested patch.
Comment 2 Amilcar do Carmo Lucas 2004-01-13 10:33:01 UTC
Nice patch.
But the file is written with four spaces indentention, why did you use three spaces in the patch?

The rule is look at the code surrounding the are you want to patch. And then use the same type (2 spaces, 4 spaces, tabs or whatever)

Thanks for the patch
Comment 3 Amilcar do Carmo Lucas 2004-01-13 10:49:00 UTC
Now in english :)

Nice patch.
But the file is written with four spaces indentention, why did you use three spaces in your patch?

The rule is to look at the code surrounding the area you want to patch. And then use the same type (2 spaces, 4 spaces, tabs or whatever) of indentation.
Comment 4 Dan Christensen 2004-01-13 16:35:25 UTC
Sorry about that. I thought that I had matched the style of the file. I guess I wasn't paying close enough attention. 
Comment 5 Dan Christensen 2004-01-13 18:49:45 UTC
Created attachment 4147 [details]
Updated patch

I've updated the patch to use the correct indentation style
Comment 6 Jens Dagerbo 2004-01-13 21:05:43 UTC
Thanks, we'll commit it as soon as CVS is unfrozen. :)
Comment 7 Jens Dagerbo 2004-01-21 15:25:28 UTC
Subject: kdevelop/parts/grepview

CVS commit by dagerbo: 

Commit suggested patch for bug 72523.

Thanks to Dan Christensen for the patch.

CCMAIL: 72523-done@bugs.kde.org


  M +17 -0     grepviewwidget.cpp   1.26


--- kdevelop/parts/grepview/grepviewwidget.cpp  #1.25:1.26
@@ -17,4 +17,7 @@
 #include <klocale.h>
 #include <kprocess.h>
+#include <kparts/part.h>
+#include <ktexteditor/selectioninterface.h>
+using namespace KTextEditor;
 
 #include "kdevcore.h"
@@ -119,4 +122,18 @@ GrepViewWidget::~GrepViewWidget()
 void GrepViewWidget::showDialog()
 {
+    // Get the selected text if there is any
+    KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*>(m_part->partController()->activePart());
+    if (ro_part)
+    {
+        SelectionInterface *selectIface = dynamic_cast<SelectionInterface*>(ro_part);
+        if(selectIface && selectIface->hasSelection())
+        {
+            QString selText = selectIface->selection();
+            if(!selText.contains('\n'))
+            {
+                grepdlg->setPattern(selText);
+            }
+        }
+    }
     grepdlg->show();
 }