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