[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 \
"/" 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.</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't cause that.<br><br>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?<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 <<a \
href="mailto:Ch.Ehrlicher@gmx.de">Ch.Ehrlicher@gmx.de</a>> 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 "boo.txt", it appears<br>
"text/boo.txt".<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>
Index: plugins/findinfiles/kategrepthread.h<br>
===================================================================<br>
--- plugins/findinfiles/kategrepthread.h (revision \
795790)<br>
+++ plugins/findinfiles/kategrepthread.h (working \
copy)<br> @@ -51,7 +51,7 @@<br>
void grepInFile (const QString &fileName, const QString \
&baseName);<br> Q_SIGNALS:<br>
- void foundMatch (const QString &filename, int line, int \
column,<br> const QString &basename, const QString &lineContent, QWidget \
*parentTab);<br> + void foundMatch (const QString &filename, const \
QString &relname,<br> int line, int column, const QString &basename, const \
QString<br> &lineContent, QWidget *parentTab); private:<br>
QWidget* m_parentTab;<br>
@@ -60,6 +60,7 @@<br>
bool m_recursive;<br>
QStringList m_fileWildcards;<br>
QList<QRegExp> m_searchPattern;<br>
+ QString m_dir;<br>
};<br>
#endif<br>
Index: plugins/findinfiles/kategrepdialog.cpp<br>
===================================================================<br>
--- plugins/findinfiles/kategrepdialog.cpp (revision 795790)<br>
+++ plugins/findinfiles/kategrepdialog.cpp (working copy)<br>
@@ -296,8 +296,8 @@<br>
connect(lbResult, SIGNAL(destroyed()), m_grepThread, SLOT(cancel()));<br>
connect(lbResult, SIGNAL(destroyed()), this, SLOT(searchFinished()));<br>
connect (m_grepThread, SIGNAL(finished()), this,<br>
SLOT(searchFinished())); - connect (m_grepThread, SIGNAL(foundMatch<br>
(const QString &, int, int, const QString &, const QString &, QWidget<br>
*)), - this, SLOT(searchMatchFound(const QString \
&, int, int,<br> const QString &, const QString &, QWidget *))); + \
connect (m_grepThread,<br> SIGNAL(foundMatch (const QString &, const \
QString &, int, int, const<br> QString &, const QString &, QWidget *)), + \
this,<br> SLOT(searchMatchFound(const QString \
&, const QString &, int, int, const<br> QString &, const QString &, \
QWidget *))); // grep<br> m_grepThread->start();<br>
@@ -369,7 +369,7 @@<br>
}<br>
}<br>
-void KateGrepDialog::searchMatchFound(const QString &filename, int \
line,<br> int column, const QString &basename, const QString &lineContent, \
QWidget<br>
*parentTab) +void KateGrepDialog::searchMatchFound(const QString<br>
&filename, const QString &relname, int line, int column, const QString<br>
&basename, const QString &lineContent, QWidget *parentTab) {<br>
// should never happen<br>
if(lbResult->indexOf(parentTab) < 0)<br>
@@ -379,7 +379,7 @@<br>
QTreeWidgetItem* item = new QTreeWidgetItem(w);<br>
// visible text<br>
- item->setText(0, basename);<br>
+ item->setText(0, relname);<br>
item->setText(1, QString::number (line + 1));<br>
item->setText(2, lineContent.trimmed());<br>
Index: plugins/findinfiles/kategrepdialog.h<br>
===================================================================<br>
--- plugins/findinfiles/kategrepdialog.h (revision \
795790)<br>
+++ plugins/findinfiles/kategrepdialog.h (working \
copy)<br> @@ -63,7 +63,7 @@<br>
void slotClear();<br>
void patternTextChanged( const QString &);<br>
void searchFinished ();<br>
- void searchMatchFound(const QString &filename, int line, int \
column,<br> const QString &basename, const QString &lineContent, QWidget \
*parentTab);<br> + void searchMatchFound(const QString &filename, \
const QString<br> &relname, int line, int column, const QString &basename, \
const QString<br> &lineContent, QWidget *parentTab); void syncDir();<br>
private:<br>
Index: plugins/findinfiles/kategrepthread.cpp<br>
===================================================================<br>
--- plugins/findinfiles/kategrepthread.cpp (revision 795790)<br>
+++ plugins/findinfiles/kategrepthread.cpp (working copy)<br>
@@ -36,6 +36,8 @@<br>
, m_searchPattern (searchPattern)<br>
{<br>
m_workQueue << dir;<br>
+ QDir baseDir(dir);<br>
+ m_dir = baseDir.absolutePath() + '/';<br>
</blockquote>
<br>
Does this work on Windows, too?<br>
<br>
</blockquote></div></div>
Yes, why not :)<br>
In Qt all internal paths have '/' 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