00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "grepviewpart.h"
00013
00014
#include <qpopupmenu.h>
00015
#include <qvbox.h>
00016
#include <qwhatsthis.h>
00017
#include <kdebug.h>
00018
#include <klocale.h>
00019
#include <kaction.h>
00020
#include <kdialogbase.h>
00021
#include <kiconloader.h>
00022
#include <kprocess.h>
00023
00024
#include "kdevcore.h"
00025
#include "kdevmainwindow.h"
00026
#include "grepviewwidget.h"
00027
00028
static const KAboutData data(
"kdevgrepview",
I18N_NOOP(
"Grep"),
"1.0");
00029
00030
00031
00032 K_EXPORT_COMPONENT_FACTORY(libkdevgrepview,
GrepViewFactory(&data))
00033
00034
00035
00036
GrepViewPart::
GrepViewPart(
QObject *parent, const
char *name, const
QStringList & )
00037 :
KDevPlugin( "GrepView", "grep", parent, name ? name : "
GrepViewPart" )
00038 {
00039 setInstance(GrepViewFactory::instance());
00040
00041 setXMLFile(
"kdevgrepview.rc");
00042
00043 connect( core(), SIGNAL(stopButtonClicked(
KDevPlugin*)),
00044
this, SLOT(stopButtonClicked(
KDevPlugin*)) );
00045 connect( core(), SIGNAL(projectOpened()),
this, SLOT(projectOpened()) );
00046 connect( core(), SIGNAL(projectClosed()),
this, SLOT(projectClosed()) );
00047 connect( core(), SIGNAL(contextMenu(
QPopupMenu *,
const Context *)),
00048
this, SLOT(contextMenu(
QPopupMenu *,
const Context *)) );
00049
00050 m_widget =
new GrepViewWidget(
this);
00051 m_widget->setIcon(SmallIcon(
"find"));
00052 m_widget->setCaption(i18n(
"Grep Output"));
00053 QWhatsThis::add(m_widget, i18n(
"<b>Grep</b><p>"
00054
"This window contains the output of a grep "
00055
"command. Clicking on an item in the list "
00056
"will automatically open the corresponding "
00057
"source file and set the cursor to the line "
00058
"with the match."));
00059
00060 mainWindow()->embedOutputView(m_widget, i18n(
"Grep"), i18n(
"Output of the grep command"));
00061
00062
KAction *action;
00063
00064 action =
new KAction(i18n(
"&Find in Files..."),
"grep", CTRL+ALT+Key_F,
00065
this, SLOT(slotGrep()),
00066 actionCollection(),
"edit_grep");
00067 action->setToolTip( i18n(
"Search for expressions over several files") );
00068 action->setWhatsThis( i18n(
"<b>Find in files</b><p>"
00069
"Opens the 'Search in Files' dialog. There you "
00070
"can enter a regular expression which is then "
00071
"searched for within all files in the directories "
00072
"you specify. Matches will be displayed, you "
00073
"can switch to a match directly.") );
00074 }
00075
00076
00077 GrepViewPart::~GrepViewPart()
00078 {
00079
if (
m_widget )
00080
mainWindow()->
removeView(
m_widget );
00081
delete m_widget;
00082 }
00083
00084
00085 void GrepViewPart::stopButtonClicked(
KDevPlugin* which)
00086 {
00087
if ( which != 0 && which !=
this )
00088
return;
00089
kdDebug(9001) <<
"GrepViewPart::stopButtonClicked()" <<
endl;
00090
m_widget->killJob( SIGHUP );
00091 }
00092
00093
00094 void GrepViewPart::projectOpened()
00095 {
00096
kdDebug(9001) <<
"GrepViewPart::projectOpened()" <<
endl;
00097
m_widget->projectChanged(
project());
00098 }
00099
00100
00101 void GrepViewPart::projectClosed()
00102 {
00103
m_widget->projectChanged(0);
00104 }
00105
00106
00107 void GrepViewPart::contextMenu(
QPopupMenu *popup,
const Context *context)
00108 {
00109
kdDebug(9001) <<
"context in grepview" <<
endl;
00110
if (!context->
hasType( Context::EditorContext ))
00111
return;
00112
00113
const EditorContext *econtext = static_cast<const EditorContext*>(context);
00114
QString ident = econtext->
currentWord();
00115
if (!ident.isEmpty()) {
00116
m_popupstr = ident;
00117
int id = popup->insertItem( i18n(
"Grep: %1").arg(ident),
00118
this, SLOT(
slotContextGrep()) );
00119 popup->setWhatsThis(
id, i18n(
"<b>Grep</b><p>Opens the search in files dialog "
00120
"and sets the pattern to a text under the cursor."));
00121 }
00122 }
00123
00124
00125 void GrepViewPart::slotGrep()
00126 {
00127
if ( !
m_widget->isRunning() )
00128 {
00129
m_widget->showDialog();
00130 }
00131 }
00132
00133
00134 void GrepViewPart::slotContextGrep()
00135 {
00136
if ( !
m_widget->isRunning() )
00137 {
00138
m_widget->showDialogWithPattern(
m_popupstr);
00139 }
00140 }
00141
00142
#include "grepviewpart.moc"