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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include <tqstring.h>
#include <tqregexp.h>
#include <tqlabel.h>
#include <ktrader.h>
#include <kparts/componentfactory.h>
#include <kregexpeditorinterface.h>
#include <kurlrequester.h>
#include <kurlcompletion.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <kdebug.h>
#include "replacedlgimpl.h"
namespace
{
/// @todo This is the same function as in ../grepview/grepviewwidget.cpp and
/// should probably be placed in a common place. For now it seemed like too
/// little code to bother with.
TQString escape(const TQString &str)
{
TQString escaped("[]{}()\\^$?.+-*");
TQString res;
for (uint i=0; i < str.length(); ++i)
{
if (escaped.tqfind(str[i]) != -1)
res += "\\";
res += str[i];
}
return res;
}
}
ReplaceDlgImpl::ReplaceDlgImpl(TQWidget* tqparent, const char* name, bool modal, WFlags fl)
: ReplaceDlg(tqparent,name, modal,fl), _regexp_dialog( 0 )
{
connect( find_button, TQT_SIGNAL( clicked() ), TQT_SLOT( saveComboHistories() ) );
connect( regexp_button, TQT_SIGNAL( clicked() ), TQT_SLOT( showRegExpEditor() ) );
connect( find_combo, TQT_SIGNAL( textChanged( const TQString & ) ),
TQT_SLOT( validateFind( const TQString & ) ) );
connect( regexp_combo, TQT_SIGNAL( textChanged ( const TQString & ) ),
TQT_SLOT( validateExpression( const TQString & ) ) );
connect( strings_regexp_radio, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( toggleExpression( bool ) ) );
// disable the editor button if the regexp editor isn't installed
if ( KTrader::self()->query("KRegExpEditor/KRegExpEditor").isEmpty() )
{
strings_regexp_radio->disconnect( regexp_button );
}
path_urlreq->completionObject()->setMode(KURLCompletion::DirCompletion);
path_urlreq->setMode( KFile::Directory | KFile::LocalOnly );
expression_varning_label->hide();
}
ReplaceDlgImpl::~ReplaceDlgImpl()
{}
void ReplaceDlgImpl::show( TQString const & path )
{
path_urlreq->lineEdit()->setText( path );
find_combo->setCurrentText( "" );
replacement_combo->setCurrentText( "" );
regexp_combo->setCurrentText( "" );
strings_all_radio->setChecked( true );
find_combo->setFocus();
find_button->setEnabled( false );
TQDialog::show();
}
void ReplaceDlgImpl::showRegExpEditor()
{
_regexp_dialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>( "KRegExpEditor/KRegExpEditor" );
if ( _regexp_dialog )
{
KRegExpEditorInterface *editor =
static_cast<KRegExpEditorInterface *>( _regexp_dialog->qt_cast( "KRegExpEditorInterface" ) );
editor->setRegExp( regexp_combo->currentText() );
if ( _regexp_dialog->exec() == TQDialog::Accepted )
{
regexp_combo->setCurrentText( editor->regExp() );
}
}
}
void ReplaceDlgImpl::validateFind( const TQString & )
{
//kdDebug(0) << "ReplaceWidget::validateFind()" << endl;
bool x = find_combo->currentText().isEmpty() && ! strings_regexp_radio->isOn();
find_button->setEnabled( !x );
}
void ReplaceDlgImpl::validateExpression( const TQString & )
{
//kdDebug(0) << "ReplaceWidget::validateExpression()" << endl;
TQString pattern = regexp_combo->currentText();
TQRegExp re( pattern );
if ( pattern.isEmpty() || !re.isValid() )
{
expression_varning_label->show();
find_button->setEnabled( false );
}
else
{
expression_varning_label->hide();
find_button->setEnabled( true );
}
}
void ReplaceDlgImpl::toggleExpression( bool on )
{
if ( on )
{
validateExpression( TQString() );
}
else
{
expression_varning_label->hide();
find_button->setEnabled( true );
}
}
void ReplaceDlgImpl::saveComboHistories()
{
if ( find_combo->isEnabled() && ! find_combo->currentText().isEmpty() )
{
find_combo->addToHistory( find_combo->currentText() );
}
if ( ! replacement_combo->currentText().isEmpty() )
{
replacement_combo->addToHistory( replacement_combo->currentText() );
}
if ( regexp_combo->isEnabled() && ! regexp_combo->currentText().isEmpty() )
{
regexp_combo->addToHistory( regexp_combo->currentText() );
}
}
TQRegExp ReplaceDlgImpl::expressionPattern()
{
TQString pattern = escape( find_combo->currentText() );
TQRegExp re;
re.setCaseSensitive( case_box->isChecked() );
re.setMinimal( true );
if ( strings_wholewords_radio->isChecked() )
{
pattern = "\\b" + pattern + "\\b";
}
else if ( strings_regexp_radio->isChecked() )
{
pattern = regexp_combo->currentText();
}
re.setPattern( pattern );
return re;
}
TQString ReplaceDlgImpl::replacementString()
{
return replacement_combo->currentText();
}
#include "replacedlgimpl.moc"
|