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

List:       kwrite-devel
Subject:    Re: [PATCH] Kate Find in Files plugin relative path
From:       "Ivo Anjo" <knuckles () gmail ! com>
Date:       2008-04-15 21:04:50
Message-ID: 557ea2710804151404xdba4eb4wbdebff6d93a66727 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi.

Yes, according to QDir docs:

Qt uses "/" as a universal directory separator in the same way that "/" is
used as a path separator in URLs. If you always use "/" as a directory
separator, Qt will translate your paths to conform to the underlying
operating system.

Also, looking at this again, I realized that using QString::remove might
have the corner case where your path repeats (eg, if scanning /home/user/
and /home/user/stuff/home/user/file.txt matches, it would show up as
stufffile.txt [and I tested it, it does]).

So attached is a new version of the patch that doesn't cause that.

I also just noticed a bug, but couldn't find where it's coming from: the
last line on a file is never matched. E.g. I had created a file with just
"test" inside, and it wasn't matching. Adding two \n to the end of the file
made it match. Should I open the bug on b.k.o?

Ivo

P.s.: Please CC me directly as I have mail delivery for the list off.

On Tue, Apr 15, 2008 at 9:54 PM, Christian Ehrlicher <Ch.Ehrlicher@gmx.de>
wrote:

> Dominik Haumann schrieb:
>
>  Hi,
> >
> > looks good, but one question though, see below.
> >
> > On Monday 14 April 2008, Ivo Anjo wrote:
> >
> > > Hi.
> > >
> > > This patch adds the relative path (from the root folder of the grep)
> > > to
> > > the filename shown on the file in files plugin.
> > > So if I have /somedir/text/boo.txt and I grep with /somedir as root,
> > > and
> > > boo.txt matches, instead of appearing "boo.txt", it appears
> > > "text/boo.txt".
> > >
> > > This is specially useful in java projects, where you have tons of
> > > classes
> > > in different dirs, and this helps to know what things are without
> > > opening
> > > them and looking at the package.
> > >
> > > Ivo Anjo
> > >
> > > P.s.: Please CC me directly as I have mail delivery for the list off.
> > > kate_find_in_files_relpath.patch
> > >  Index: plugins/findinfiles/kategrepthread.h
> > > ===================================================================
> > > --- plugins/findinfiles/kategrepthread.h        (revision 795790)
> > > +++ plugins/findinfiles/kategrepthread.h        (working copy)
> > > @@ -51,7 +51,7 @@
> > >     void grepInFile (const QString &fileName, const QString
> > > &baseName);
> > >     Q_SIGNALS:
> > > -    void foundMatch (const QString &filename, int line, int column,
> > > const QString &basename, const QString &lineContent, QWidget
> > > *parentTab);
> > > +    void foundMatch (const QString &filename, const QString &relname,
> > > int line, int column, const QString &basename, const QString
> > > &lineContent, QWidget *parentTab);   private:
> > >     QWidget* m_parentTab;
> > > @@ -60,6 +60,7 @@
> > >     bool m_recursive;
> > >     QStringList m_fileWildcards;
> > >     QList<QRegExp> m_searchPattern;
> > > +    QString m_dir;
> > >  };
> > >   #endif
> > > Index: plugins/findinfiles/kategrepdialog.cpp
> > > ===================================================================
> > > --- plugins/findinfiles/kategrepdialog.cpp      (revision 795790)
> > > +++ plugins/findinfiles/kategrepdialog.cpp      (working copy)
> > > @@ -296,8 +296,8 @@
> > >   connect(lbResult, SIGNAL(destroyed()), m_grepThread,
> > > SLOT(cancel()));
> > >   connect(lbResult, SIGNAL(destroyed()), this,
> > > SLOT(searchFinished()));
> > >   connect (m_grepThread, SIGNAL(finished()), this,
> > > SLOT(searchFinished())); -  connect (m_grepThread, SIGNAL(foundMatch
> > > (const QString &, int, int, const QString &, const QString &, QWidget
> > > *)), -           this, SLOT(searchMatchFound(const QString &, int,
> > > int,
> > > const QString &, const QString &, QWidget *))); +  connect
> > > (m_grepThread,
> > > SIGNAL(foundMatch (const QString &, const QString &, int, int, const
> > > QString &, const QString &, QWidget *)), +           this,
> > > SLOT(searchMatchFound(const QString &, const QString &, int, int,
> > > const
> > > QString &, const QString &, QWidget *)));   // grep
> > >   m_grepThread->start();
> > > @@ -369,7 +369,7 @@
> > >   }
> > >  }
> > >  -void KateGrepDialog::searchMatchFound(const QString &filename, int
> > > line,
> > > int column, const QString &basename, const QString &lineContent,
> > > QWidget
> > > *parentTab) +void KateGrepDialog::searchMatchFound(const QString
> > > &filename, const QString &relname, int line, int column, const QString
> > > &basename, const QString &lineContent, QWidget *parentTab) {
> > >   // should never happen
> > >   if(lbResult->indexOf(parentTab) < 0)
> > > @@ -379,7 +379,7 @@
> > >     QTreeWidgetItem* item = new QTreeWidgetItem(w);
> > >   // visible text
> > > -  item->setText(0, basename);
> > > +  item->setText(0, relname);
> > >   item->setText(1, QString::number (line + 1));
> > >   item->setText(2, lineContent.trimmed());
> > >  Index: plugins/findinfiles/kategrepdialog.h
> > > ===================================================================
> > > --- plugins/findinfiles/kategrepdialog.h        (revision 795790)
> > > +++ plugins/findinfiles/kategrepdialog.h        (working copy)
> > > @@ -63,7 +63,7 @@
> > >     void slotClear();
> > >     void patternTextChanged( const QString &);
> > >     void searchFinished ();
> > > -    void searchMatchFound(const QString &filename, int line, int
> > > column,
> > > const QString &basename, const QString &lineContent, QWidget
> > > *parentTab);
> > > +    void searchMatchFound(const QString &filename, const QString
> > > &relname, int line, int column, const QString &basename, const QString
> > > &lineContent, QWidget *parentTab); void syncDir();
> > >     private:
> > > Index: plugins/findinfiles/kategrepthread.cpp
> > > ===================================================================
> > > --- plugins/findinfiles/kategrepthread.cpp      (revision 795790)
> > > +++ plugins/findinfiles/kategrepthread.cpp      (working copy)
> > > @@ -36,6 +36,8 @@
> > >     , m_searchPattern (searchPattern)
> > >  {
> > >   m_workQueue << dir;
> > > +  QDir baseDir(dir);
> > > +  m_dir = baseDir.absolutePath() + '/';
> > >
> >
> > Does this work on Windows, too?
> >
> >  Yes, why not :)
> In Qt all internal paths have '/' as path separator.
>
>
> Christian
>

[Attachment #5 (text/html)]

Hi.<br><br>Yes, according to QDir docs:<br><meta name="qrichtext" content="1"><meta \
http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css"> \
p, li { white-space: pre-wrap; } </style>
<p style="margin: 0px; text-indent: 0px;"><span style="color: rgb(0, 0, 0);">Qt uses \
&quot;/&quot; as a universal directory separator in the same way that &quot;/&quot; \
is used as a path separator in URLs. If you always use &quot;/&quot; as a directory \
separator, Qt will translate your paths to conform to the underlying operating \
system.</span></p> <br>Also, <span style="color: rgb(0, 0, 0);">looking at this \
again, I realized that using QString::remove might have the corner case where your \
path repeats (eg, if scanning /home/user/ and /home/user/stuff/home/user/file.txt
matches, it would show up as stufffile.txt [and I tested it, it does]).<br><br>So \
attached is a new version of the patch that doesn&#39;t cause that.<br><br>I also \
just noticed a bug, but couldn&#39;t find where it&#39;s coming from: the last line \
on a file is never matched. E.g. I had created a file with just &quot;test&quot; \
inside, and it wasn&#39;t matching. Adding two \n to the end of the file made it \
match. Should I open the bug on b.k.o?<br> <br>Ivo<br><br></span>P.s.: Please CC me \
directly as I have mail delivery for the list off.<br><br><div class="gmail_quote">On \
Tue, Apr 15, 2008 at 9:54 PM, Christian Ehrlicher &lt;<a \
href="mailto:Ch.Ehrlicher@gmx.de">Ch.Ehrlicher@gmx.de</a>&gt; wrote:<br> <blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;">Dominik Haumann schrieb:<div><div></div><div \
class="Wj3C7c"><br> <blockquote class="gmail_quote" style="border-left: 1px solid \
rgb(204, 204, 204); padding-left: 1ex;"> Hi,<br>
<br>
looks good, but one question though, see below.<br>
<br>
On Monday 14 April 2008, Ivo Anjo wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
padding-left: 1ex;"> Hi.<br>
<br>
This patch adds the relative path (from the root folder of the grep) to<br>
the filename shown on the file in files plugin.<br>
So if I have /somedir/text/boo.txt and I grep with /somedir as root, and<br>
boo.txt matches, instead of appearing &quot;boo.txt&quot;, it appears<br>
&quot;text/boo.txt&quot;.<br>
<br>
This is specially useful in java projects, where you have tons of classes<br>
in different dirs, and this helps to know what things are without opening<br>
them and looking at the package.<br>
<br>
Ivo Anjo<br>
<br>
P.s.: Please CC me directly as I have mail delivery for the list off.<br>
kate_find_in_files_relpath.patch<br>
 &nbsp;Index: plugins/findinfiles/kategrepthread.h<br>
===================================================================<br>
--- plugins/findinfiles/kategrepthread.h &nbsp; &nbsp; &nbsp; &nbsp;(revision \
                795790)<br>
+++ plugins/findinfiles/kategrepthread.h &nbsp; &nbsp; &nbsp; &nbsp;(working \
copy)<br> @@ -51,7 +51,7 @@<br>
 &nbsp; &nbsp; void grepInFile (const QString &amp;fileName, const QString \
&amp;baseName);<br> &nbsp; &nbsp; Q_SIGNALS:<br>
- &nbsp; &nbsp;void foundMatch (const QString &amp;filename, int line, int \
column,<br> const QString &amp;basename, const QString &amp;lineContent, QWidget \
*parentTab);<br> + &nbsp; &nbsp;void foundMatch (const QString &amp;filename, const \
QString &amp;relname,<br> int line, int column, const QString &amp;basename, const \
QString<br> &amp;lineContent, QWidget *parentTab);  &nbsp; private:<br>
 &nbsp; &nbsp; QWidget* m_parentTab;<br>
@@ -60,6 +60,7 @@<br>
 &nbsp; &nbsp; bool m_recursive;<br>
 &nbsp; &nbsp; QStringList m_fileWildcards;<br>
 &nbsp; &nbsp; QList&lt;QRegExp&gt; m_searchPattern;<br>
+ &nbsp; &nbsp;QString m_dir;<br>
&nbsp;};<br>
&nbsp;&nbsp;#endif<br>
Index: plugins/findinfiles/kategrepdialog.cpp<br>
===================================================================<br>
--- plugins/findinfiles/kategrepdialog.cpp &nbsp; &nbsp; &nbsp;(revision 795790)<br>
+++ plugins/findinfiles/kategrepdialog.cpp &nbsp; &nbsp; &nbsp;(working copy)<br>
@@ -296,8 +296,8 @@<br>
 &nbsp; connect(lbResult, SIGNAL(destroyed()), m_grepThread, SLOT(cancel()));<br>
 &nbsp; connect(lbResult, SIGNAL(destroyed()), this, SLOT(searchFinished()));<br>
 &nbsp; connect (m_grepThread, SIGNAL(finished()), this,<br>
SLOT(searchFinished())); - &nbsp;connect (m_grepThread, SIGNAL(foundMatch<br>
(const QString &amp;, int, int, const QString &amp;, const QString &amp;, QWidget<br>
*)), - &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this, SLOT(searchMatchFound(const QString \
&amp;, int, int,<br> const QString &amp;, const QString &amp;, QWidget *))); + \
&nbsp;connect (m_grepThread,<br> SIGNAL(foundMatch (const QString &amp;, const \
QString &amp;, int, int, const<br> QString &amp;, const QString &amp;, QWidget *)), + \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this,<br> SLOT(searchMatchFound(const QString \
&amp;, const QString &amp;, int, int, const<br> QString &amp;, const QString &amp;, \
QWidget *)));  &nbsp; // grep<br>  &nbsp; m_grepThread-&gt;start();<br>
@@ -369,7 +369,7 @@<br>
 &nbsp; }<br>
&nbsp;}<br>
&nbsp;-void KateGrepDialog::searchMatchFound(const QString &amp;filename, int \
line,<br> int column, const QString &amp;basename, const QString &amp;lineContent, \
                QWidget<br>
*parentTab) +void KateGrepDialog::searchMatchFound(const QString<br>
&amp;filename, const QString &amp;relname, int line, int column, const QString<br>
&amp;basename, const QString &amp;lineContent, QWidget *parentTab) {<br>
 &nbsp; // should never happen<br>
 &nbsp; if(lbResult-&gt;indexOf(parentTab) &lt; 0)<br>
@@ -379,7 +379,7 @@<br>
&nbsp; &nbsp; QTreeWidgetItem* item = new QTreeWidgetItem(w);<br>
 &nbsp; // visible text<br>
- &nbsp;item-&gt;setText(0, basename);<br>
+ &nbsp;item-&gt;setText(0, relname);<br>
 &nbsp; item-&gt;setText(1, QString::number (line + 1));<br>
 &nbsp; item-&gt;setText(2, lineContent.trimmed());<br>
&nbsp;Index: plugins/findinfiles/kategrepdialog.h<br>
===================================================================<br>
--- plugins/findinfiles/kategrepdialog.h &nbsp; &nbsp; &nbsp; &nbsp;(revision \
                795790)<br>
+++ plugins/findinfiles/kategrepdialog.h &nbsp; &nbsp; &nbsp; &nbsp;(working \
copy)<br> @@ -63,7 +63,7 @@<br>
 &nbsp; &nbsp; void slotClear();<br>
 &nbsp; &nbsp; void patternTextChanged( const QString &amp;);<br>
 &nbsp; &nbsp; void searchFinished ();<br>
- &nbsp; &nbsp;void searchMatchFound(const QString &amp;filename, int line, int \
column,<br> const QString &amp;basename, const QString &amp;lineContent, QWidget \
*parentTab);<br> + &nbsp; &nbsp;void searchMatchFound(const QString &amp;filename, \
const QString<br> &amp;relname, int line, int column, const QString &amp;basename, \
const QString<br> &amp;lineContent, QWidget *parentTab); void syncDir();<br>
&nbsp; &nbsp; private:<br>
Index: plugins/findinfiles/kategrepthread.cpp<br>
===================================================================<br>
--- plugins/findinfiles/kategrepthread.cpp &nbsp; &nbsp; &nbsp;(revision 795790)<br>
+++ plugins/findinfiles/kategrepthread.cpp &nbsp; &nbsp; &nbsp;(working copy)<br>
@@ -36,6 +36,8 @@<br>
 &nbsp; &nbsp; , m_searchPattern (searchPattern)<br>
&nbsp;{<br>
 &nbsp; m_workQueue &lt;&lt; dir;<br>
+ &nbsp;QDir baseDir(dir);<br>
+ &nbsp;m_dir = baseDir.absolutePath() + &#39;/&#39;;<br>
</blockquote>
<br>
Does this work on Windows, too?<br>
<br>
</blockquote></div></div>
Yes, why not :)<br>
In Qt all internal paths have &#39;/&#39; as path separator.<br><font \
color="#888888"> <br>
<br>
Christian<br>
</font></blockquote></div><br>


["kate_find_in_files_relpath_v2.patch" (text/x-patch)]

Index: plugins/findinfiles/kategrepthread.h
===================================================================
--- plugins/findinfiles/kategrepthread.h	(revision 795790)
+++ plugins/findinfiles/kategrepthread.h	(working copy)
@@ -51,7 +51,7 @@
     void grepInFile (const QString &fileName, const QString &baseName);
 
   Q_SIGNALS:
-    void foundMatch (const QString &filename, int line, int column, const QString \
&basename, const QString &lineContent, QWidget *parentTab); +    void foundMatch \
(const QString &filename, const QString &relname, int line, int column, const QString \
&basename, const QString &lineContent, QWidget *parentTab);  
   private:
     QWidget* m_parentTab;
@@ -60,6 +60,7 @@
     bool m_recursive;
     QStringList m_fileWildcards;
     QList<QRegExp> m_searchPattern;
+    QString m_dir;
 };
 
 #endif
Index: plugins/findinfiles/kategrepdialog.cpp
===================================================================
--- plugins/findinfiles/kategrepdialog.cpp	(revision 795790)
+++ plugins/findinfiles/kategrepdialog.cpp	(working copy)
@@ -296,8 +296,8 @@
   connect(lbResult, SIGNAL(destroyed()), m_grepThread, SLOT(cancel()));
   connect(lbResult, SIGNAL(destroyed()), this, SLOT(searchFinished()));
   connect (m_grepThread, SIGNAL(finished()), this, SLOT(searchFinished()));
-  connect (m_grepThread, SIGNAL(foundMatch (const QString &, int, int, const QString \
                &, const QString &, QWidget *)),
-           this, SLOT(searchMatchFound(const QString &, int, int, const QString &, \
const QString &, QWidget *))); +  connect (m_grepThread, SIGNAL(foundMatch (const \
QString &, const QString &, int, int, const QString &, const QString &, QWidget *)), \
+           this, SLOT(searchMatchFound(const QString &, const QString &, int, int, \
const QString &, const QString &, QWidget *)));  
   // grep
   m_grepThread->start();
@@ -369,7 +369,7 @@
   }
 }
 
-void KateGrepDialog::searchMatchFound(const QString &filename, int line, int column, \
const QString &basename, const QString &lineContent, QWidget *parentTab) +void \
KateGrepDialog::searchMatchFound(const QString &filename, const QString &relname, int \
line, int column, const QString &basename, const QString &lineContent, QWidget \
*parentTab)  {
   // should never happen
   if(lbResult->indexOf(parentTab) < 0)
@@ -379,7 +379,7 @@
 
   QTreeWidgetItem* item = new QTreeWidgetItem(w);
   // visible text
-  item->setText(0, basename);
+  item->setText(0, relname);
   item->setText(1, QString::number (line + 1));
   item->setText(2, lineContent.trimmed());
 
Index: plugins/findinfiles/kategrepdialog.h
===================================================================
--- plugins/findinfiles/kategrepdialog.h	(revision 795790)
+++ plugins/findinfiles/kategrepdialog.h	(working copy)
@@ -63,7 +63,7 @@
     void slotClear();
     void patternTextChanged( const QString &);
     void searchFinished ();
-    void searchMatchFound(const QString &filename, int line, int column, const \
QString &basename, const QString &lineContent, QWidget *parentTab); +    void \
searchMatchFound(const QString &filename, const QString &relname, int line, int \
column, const QString &basename, const QString &lineContent, QWidget *parentTab);  \
void syncDir();  
   private:
Index: plugins/findinfiles/kategrepthread.cpp
===================================================================
--- plugins/findinfiles/kategrepthread.cpp	(revision 795790)
+++ plugins/findinfiles/kategrepthread.cpp	(working copy)
@@ -36,6 +36,8 @@
     , m_searchPattern (searchPattern)
 {
   m_workQueue << dir;
+  QDir baseDir(dir);
+  m_dir = baseDir.absolutePath() + '/';
 }
 
 KateGrepThread::~KateGrepThread ()
@@ -107,7 +109,11 @@
       if (firstColumn != -1)
       {
         kDebug () << "found match: " << fileName << " : " << lineNumber;
-        emit foundMatch (fileName, lineNumber, firstColumn, baseName, lines.at (0), \
m_parentTab); +        QString relName = fileName;
+        if (relName.startsWith(m_dir)) {
+          relName.remove(0, m_dir.size());
+        }
+        emit foundMatch (fileName, relName, lineNumber, firstColumn, baseName, \
lines.at (0), m_parentTab);  }
 
       // remove first line...



_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


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

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