1
package Padre::Wx::Dialog::RegexEditor;
3
# The Regex Editor for Padre
10
use Padre::Wx::Icon ();
12
our $VERSION = '0.50';
13
our @ISA = 'Wx::Dialog';
16
######################################################################
23
# Create the basic object
24
my $self = $class->SUPER::new(
27
Wx::gettext('Regex Editor'),
28
Wx::wxDefaultPosition,
30
Wx::wxDEFAULT_FRAME_STYLE,
33
# Set basic dialog properties
34
$self->SetIcon(Padre::Wx::Icon::PADRE);
35
$self->SetMinSize( [ 750, 550 ] );
39
$self->{regex} = Wx::TextCtrl->new(
40
$self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
41
Wx::wxTE_MULTILINE | Wx::wxNO_FULL_REPAINT_ON_RESIZE
44
$self->{substitute} = Wx::TextCtrl->new(
45
$self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
46
Wx::wxTE_MULTILINE | Wx::wxNO_FULL_REPAINT_ON_RESIZE
49
$self->{original_text} = Wx::TextCtrl->new(
50
$self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
51
Wx::wxTE_MULTILINE | Wx::wxNO_FULL_REPAINT_ON_RESIZE
54
$self->{matched_text} = Wx::TextCtrl->new(
55
$self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
56
Wx::wxTE_MULTILINE | Wx::wxNO_FULL_REPAINT_ON_RESIZE
71
$self->{original_text},
77
foreach my $name ( keys %m ) {
78
$self->{$name} = Wx::CheckBox->new(
83
Wx::Event::EVT_CHECKBOX(
87
$_[0]->box_clicked($name);
92
$self->{matching} = Wx::RadioButton->new(
97
Wx::Event::EVT_RADIOBUTTON( $self, $self->{matching}, sub { $_[0]->run; } );
98
$self->{substituting} = Wx::RadioButton->new(
103
Wx::Event::EVT_RADIOBUTTON( $self, $self->{substituting}, sub { $_[0]->run; } );
106
# $self->{button_match} = Wx::Button->new(
109
# Wx::gettext('&Match'),
111
# Wx::Event::EVT_BUTTON(
113
# $self->{button_match},
115
# $_[0]->button_match;
119
# # Preferences Button
120
# $self->{button_replace} = Wx::Button->new(
123
# Wx::gettext('&Replace'),
125
# Wx::Event::EVT_BUTTON(
127
# $self->{button_replace},
129
# $_[0]->button_replace;
134
$self->{button_close} = Wx::Button->new(
137
Wx::gettext('&Close'),
139
Wx::Event::EVT_BUTTON(
141
$self->{button_close},
149
# Horizontal button sizer
150
my $buttons = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
151
$buttons->AddStretchSpacer;
152
$buttons->Add( $self->{button_match}, 0, Wx::wxALL, 1 );
153
$buttons->Add( $self->{button_replace}, 0, Wx::wxALL, 1 );
154
$buttons->AddStretchSpacer;
155
$buttons->Add( $self->{button_close}, 0, Wx::wxALL, 1 );
156
$buttons->AddStretchSpacer;
159
my $modifiers = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
160
$modifiers->AddStretchSpacer;
161
$modifiers->Add( $self->{ignore_case}, 0, Wx::wxALL, 1 );
162
$modifiers->Add( $self->{single_line}, 0, Wx::wxALL, 1 );
163
$modifiers->Add( $self->{multi_line}, 0, Wx::wxALL, 1 );
164
$modifiers->Add( $self->{extended}, 0, Wx::wxALL, 1 );
166
my $operation = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
167
$operation->AddStretchSpacer;
168
$operation->Add( $self->{matching}, 0, Wx::wxALL, 1 );
169
$operation->Add( $self->{substituting}, 0, Wx::wxALL, 1 );
171
# Vertical layout of the left hand side
172
my $left = Wx::BoxSizer->new(Wx::wxVERTICAL);
173
$left->Add( $modifiers, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
174
$left->Add( $operation, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
178
Wx::wxALL | Wx::wxALIGN_TOP | Wx::wxALIGN_CENTER_HORIZONTAL | Wx::wxEXPAND,
184
Wx::wxALL | Wx::wxALIGN_TOP | Wx::wxALIGN_CENTER_HORIZONTAL | Wx::wxEXPAND,
189
# Vertical layout of the right hand side
190
my $right = Wx::BoxSizer->new(Wx::wxVERTICAL);
192
$self->{original_text},
194
Wx::wxALL | Wx::wxALIGN_TOP | Wx::wxALIGN_CENTER_HORIZONTAL | Wx::wxEXPAND,
198
$self->{matched_text},
200
Wx::wxALL | Wx::wxALIGN_TOP | Wx::wxALIGN_CENTER_HORIZONTAL | Wx::wxEXPAND,
203
$right->Add( $buttons, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
208
my $sizer = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
209
$sizer->Add( $left, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
210
$sizer->Add( $right, 1, Wx::wxALL | Wx::wxEXPAND, 1 );
212
# Tune the size and position it appears
213
$self->SetSizer($sizer);
215
$self->CentreOnParent;
223
ignore_case => { mod => 'i', name => sprintf( Wx::gettext('Ignore case (%s)'), 'i' ) },
224
single_line => { mod => 's', name => sprintf( Wx::gettext('Single-line (%s)'), 's' ) },
225
multi_line => { mod => 'm', name => sprintf( Wx::gettext('Multi-line (%s)'), 'm' ) },
226
extended => { mod => 'x', name => sprintf( Wx::gettext('Extended (%s)'), 'x' ) },
236
$self->{regex}->AppendText("regex");
237
$self->{substitute}->AppendText("substitute");
238
$self->{original_text}->AppendText("Original text");
239
$self->{matching}->SetValue(1);
245
# $self->button_match;
247
# handler called when the Match button has been clicked.
258
my $regex = $self->{regex}->GetRange( 0, $self->{regex}->GetLastPosition );
259
my $original_text = $self->{original_text}->GetRange( 0, $self->{original_text}->GetLastPosition );
260
my $substitute = $self->{substitute}->GetRange( 0, $self->{substitute}->GetLastPosition );
265
my %m = _modifiers();
266
foreach my $name ( keys %m ) {
267
if ( $self->{$name}->IsChecked ) {
268
$start .= $m{$name}{mod};
270
$end .= $m{$name}{mod};
273
my $xism = "$start-$end";
275
$self->{matched_text}->Clear;
277
if ( $self->{matching}->GetValue ) {
280
if ( $original_text =~ /(?$xism:$regex)/ )
282
$match = substr( $original_text, $-[0], $+[0] - $-[0] );
286
my $main = Padre->ide->wx->main;
288
#$main->message("Match failure in $regex: $@");
289
$self->{matched_text}->AppendText("Match failure in $regex: $@");
293
if ( defined $match ) {
294
$self->{matched_text}->AppendText("Matched '$match'");
296
$self->{matched_text}->AppendText("No match");
299
$self->{matched_text}->AppendText("Substitute not yet implemented");
306
# $self->button_replace;
308
# handler called when the Match button has been clicked.
312
my $main = Padre->ide->wx->main;
313
$main->message("Replace");
324
#my $main = Padre->ide->wx->main;
325
#$main->message("Box $box");
331
# $self->button_close;
333
# handler called when the close button has been clicked.
347
Padre::Wx::Dialog::RegexEditor - dialog to make it easy to creat a Regular expression
352
The Regex Editor provides an interface to easily create Regular
353
expressions used in Perl.
355
The user can insert a regex - the surrounding / characters are not
356
needed and a text. The Regex Editor will automatically display the matching
357
text in the bottom right window.
360
At the top of the window the user can select any of the four
374
Implement substitute as well
378
Allow the change/replacement of the // around the regex
380
Highlight the match in the source text instead of in
383
Display the captured groups in a tree hierarchy similar to Rx ?
385
Group Span (character) Value
386
Match 0 (Group 0) 4-7 the actual match
388
Display the various Perl variable containing the relevant values
389
e.g. the @- and @+ arrays, the %+ hash
392
point out what to use instead of $@ and $' and $`
394
English explanation of the regex
396
=head1 COPYRIGHT & LICENSE
398
Copyright 2008-2009 The Padre development team as listed in Padre.pm.
400
This program is free software; you can redistribute it and/or modify it
401
under the same terms as Perl 5 itself.
405
# Copyright 2008-2009 The Padre development team as listed in Padre.pm.
407
# This program is free software; you can redistribute it and/or
408
# modify it under the same terms as Perl 5 itself.