1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/***************************************************************************
* Copyright (C) 1999-2001 by Bernd Gehrmann *
* bernd@kdevelop.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "grepviewpart.h"
#include <tqpopupmenu.h>
#include <tqvbox.h>
#include <tqwhatsthis.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <tdeaction.h>
#include <kdialogbase.h>
#include <kiconloader.h>
#include <tdeprocess.h>
#include <kstringhandler.h>
#include <tdetexteditor/document.h>
#include "kdevcore.h"
#include "kdevpartcontroller.h"
#include "kdevmainwindow.h"
#include "kdevplugininfo.h"
#include "kdeveditorutil.h"
#include "grepviewwidget.h"
static const KDevPluginInfo data("kdevgrepview");
K_EXPORT_COMPONENT_FACTORY(libkdevgrepview, GrepViewFactory(data))
GrepViewPart::GrepViewPart( TQObject *parent, const char *name, const TQStringList & )
: KDevPlugin( &data, parent, name ? name : "GrepViewPart" )
{
setInstance(GrepViewFactory::instance());
setXMLFile("kdevgrepview.rc");
connect( core(), TQ_SIGNAL(stopButtonClicked(KDevPlugin*)),
this, TQ_SLOT(stopButtonClicked(KDevPlugin*)) );
connect( core(), TQ_SIGNAL(projectOpened()), this, TQ_SLOT(projectOpened()) );
connect( core(), TQ_SIGNAL(projectClosed()), this, TQ_SLOT(projectClosed()) );
connect( core(), TQ_SIGNAL(contextMenu(TQPopupMenu *, const Context *)),
this, TQ_SLOT(contextMenu(TQPopupMenu *, const Context *)) );
m_widget = new GrepViewWidget(this);
m_widget->setIcon(SmallIcon("grep"));
m_widget->setCaption(i18n("Grep Output"));
TQWhatsThis::add(m_widget, i18n("<b>Find in files</b><p>"
"This window contains the output of a grep "
"command. Clicking on an item in the list "
"will automatically open the corresponding "
"source file and set the cursor to the line "
"with the match."));
mainWindow()->embedOutputView(m_widget, i18n("Find in Files"), i18n("Output of the grep command"));
TDEAction *action;
action = new TDEAction(i18n("Find in Fi&les..."), "grep", CTRL+ALT+Key_F,
this, TQ_SLOT(slotGrep()),
actionCollection(), "edit_grep");
action->setToolTip( i18n("Search for expressions over several files") );
action->setWhatsThis( i18n("<b>Find in files</b><p>"
"Opens the 'Find in files' dialog. There you "
"can enter a regular expression which is then "
"searched for within all files in the directories "
"you specify. Matches will be displayed, you "
"can switch to a match directly.") );
}
GrepViewPart::~GrepViewPart()
{
if ( m_widget )
mainWindow()->removeView( m_widget );
delete m_widget;
}
void GrepViewPart::stopButtonClicked(KDevPlugin* which)
{
if ( which != 0 && which != this )
return;
kdDebug(9001) << "GrepViewPart::stopButtonClicked()" << endl;
m_widget->killJob( SIGHUP );
}
void GrepViewPart::projectOpened()
{
kdDebug(9001) << "GrepViewPart::projectOpened()" << endl;
m_widget->projectChanged(project());
}
void GrepViewPart::projectClosed()
{
m_widget->projectChanged(0);
}
void GrepViewPart::contextMenu(TQPopupMenu *popup, const Context *context)
{
kdDebug(9001) << "context in grepview" << endl;
if (!context->hasType( Context::EditorContext ))
return;
const EditorContext *econtext = static_cast<const EditorContext*>(context);
TQString ident = econtext->currentWord();
if (!ident.isEmpty()) {
m_popupstr = ident;
TQString squeezed = KStringHandler::csqueeze(ident, 30);
int id = popup->insertItem( i18n("Grep: %1").arg(squeezed),
this, TQ_SLOT(slotContextGrep()) );
popup->setWhatsThis(id, i18n("<b>Grep</b><p>Opens the find in files dialog "
"and sets the pattern to the text under the cursor."));
popup->insertSeparator();
}
}
void GrepViewPart::slotGrep()
{
if ( !m_widget->isRunning() )
{
TQString contextString = KDevEditorUtil::currentSelection( dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) );
if ( contextString.isEmpty() )
{
contextString = KDevEditorUtil::currentWord( dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) );
}
m_widget->showDialogWithPattern( contextString );
}
}
void GrepViewPart::slotContextGrep()
{
if ( !m_widget->isRunning() )
{
m_widget->showDialogWithPattern(m_popupstr);
}
}
#include "grepviewpart.moc"
|