~ubuntu-branches/ubuntu/saucy/padre/saucy-proposed

« back to all changes in this revision

Viewing changes to lib/Padre/Wx/Dialog/RegexEditor.pm

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont, gregor herrmann, Dominique Dumont
  • Date: 2012-01-04 12:04:20 UTC
  • mfrom: (1.3.3)
  • Revision ID: package-import@ubuntu.com-20120104120420-i5oybqwf91m1d3il
Tags: 0.92.ds1-1
[ gregor herrmann ]
* Remove debian/source/local-options; abort-on-upstream-changes
  and unapply-patches are default in dpkg-source since 1.16.1.
* Swap order of alternative (build) dependencies after the perl
  5.14 transition.

[ Dominique Dumont ]
* Imported Upstream version 0.92.ds1
* removed fix-spelling patch (applied upstream)
* lintian-override: use wildcard to avoid listing a gazillion files
* updated size of some 'not-real-man-page' entries
* rules: remove dekstop cruft (replaced by a file provided in debian
  directory)
* control: removed Breaks statement. Add /me to uploaders. Updated
  dependencies
* rules: make sure that non-DFSG file (i.e. the cute butterfly, sigh)
  is not distributed

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
# RichTextCtrl
13
13
use Wx::RichText ();
14
14
 
15
 
our $VERSION = '0.90';
 
15
our $VERSION = '0.92';
16
16
our @ISA     = qw{
17
17
        Padre::Wx::Role::Main
18
18
        Wx::Dialog
31
31
                $parent,
32
32
                -1,
33
33
                Wx::gettext('Regex Editor'),
34
 
                Wx::wxDefaultPosition,
35
 
                Wx::wxDefaultSize,
36
 
                Wx::wxDEFAULT_FRAME_STYLE,
 
34
                Wx::DefaultPosition,
 
35
                Wx::DefaultSize,
 
36
                Wx::DEFAULT_FRAME_STYLE,
37
37
        );
38
38
 
39
39
        # Set basic dialog properties
41
41
        $self->SetMinSize( [ 380, 500 ] );
42
42
 
43
43
        # create sizer that will host all controls
44
 
        my $sizer = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
 
44
        my $sizer = Wx::BoxSizer->new(Wx::HORIZONTAL);
45
45
        $self->{sizer} = $sizer;
46
46
 
47
47
        # Create the controls
168
168
        # Regex text field
169
169
        my $regex_label = Wx::StaticText->new( $self, -1, Wx::gettext('&Regular expression:') );
170
170
        $self->{regex} = Wx::TextCtrl->new(
171
 
                $self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
172
 
                Wx::wxRE_MULTILINE | Wx::wxWANTS_CHARS # Otherwise arrows will not work on win32
 
171
                $self, -1, '', Wx::DefaultPosition, Wx::DefaultSize,
 
172
                Wx::RE_MULTILINE | Wx::WANTS_CHARS # Otherwise arrows will not work on win32
173
173
        );
174
174
 
175
175
        my %regex_groups = $self->_regex_groups;
218
218
 
219
219
        # Describe-the-regex text field
220
220
        $self->{description_text} = Wx::TextCtrl->new(
221
 
                $self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
222
 
                Wx::wxTE_MULTILINE | Wx::wxNO_FULL_REPAINT_ON_RESIZE
 
221
                $self, -1, '', Wx::DefaultPosition, Wx::DefaultSize,
 
222
                Wx::TE_MULTILINE | Wx::NO_FULL_REPAINT_ON_RESIZE
223
223
        );
224
224
 
225
225
        # Description is hidden by default
228
228
        # Original input text field
229
229
        my $original_label = Wx::StaticText->new( $self, -1, Wx::gettext('&Original text:') );
230
230
        $self->{original_text} = Wx::TextCtrl->new(
231
 
                $self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
232
 
                Wx::wxTE_MULTILINE | Wx::wxNO_FULL_REPAINT_ON_RESIZE
 
231
                $self, -1, '', Wx::DefaultPosition, Wx::DefaultSize,
 
232
                Wx::TE_MULTILINE | Wx::NO_FULL_REPAINT_ON_RESIZE
233
233
        );
234
234
 
235
235
        # Matched readonly text field
236
236
        my $matched_label = Wx::StaticText->new( $self, -1, Wx::gettext('Matched text:') );
237
237
        $self->{matched_text} = Wx::RichTextCtrl->new(
238
 
                $self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
239
 
                Wx::wxRE_MULTILINE | Wx::wxRE_READONLY | Wx::wxWANTS_CHARS # Otherwise arrows will not work on win32
 
238
                $self, -1, '', Wx::DefaultPosition, Wx::DefaultSize,
 
239
                Wx::RE_MULTILINE | Wx::RE_READONLY | Wx::WANTS_CHARS # Otherwise arrows will not work on win32
240
240
        );
241
241
 
242
242
        # Toggle the visibility of the replace (substitution) fields
249
249
        # Replace regex text field
250
250
        $self->{replace_label} = Wx::StaticText->new( $self, -1, Wx::gettext('&Replace text with:') );
251
251
        $self->{replace_text} = Wx::TextCtrl->new(
252
 
                $self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
253
 
                Wx::wxTE_MULTILINE | Wx::wxNO_FULL_REPAINT_ON_RESIZE
 
252
                $self, -1, '', Wx::DefaultPosition, Wx::DefaultSize,
 
253
                Wx::TE_MULTILINE | Wx::NO_FULL_REPAINT_ON_RESIZE
254
254
        );
255
255
 
256
256
        $self->{replace_label}->Hide;
259
259
        # Result from replace text field
260
260
        $self->{result_label} = Wx::StaticText->new( $self, -1, Wx::gettext('&Result from replace:') );
261
261
        $self->{result_text} = Wx::RichTextCtrl->new(
262
 
                $self, -1, '', Wx::wxDefaultPosition, Wx::wxDefaultSize,
263
 
                Wx::wxRE_MULTILINE | Wx::wxRE_READONLY | Wx::wxWANTS_CHARS # Otherwise arrows will not work on win32
 
262
                $self, -1, '', Wx::DefaultPosition, Wx::DefaultSize,
 
263
                Wx::RE_MULTILINE | Wx::RE_READONLY | Wx::WANTS_CHARS # otherwise arrows will not work on win32
264
264
        );
265
265
 
266
266
        $self->{result_label}->Hide;
267
267
        $self->{result_text}->Hide;
268
268
 
269
 
        # Insert regex into current document button_name
 
269
        # Insert regex into current document
270
270
        $self->{insert_button} = Wx::Button->new(
271
271
                $self, -1, Wx::gettext('Insert'),
272
272
        );
273
273
 
274
274
        # Close button
275
275
        $self->{close_button} = Wx::Button->new(
276
 
                $self, Wx::wxID_CANCEL, Wx::gettext('&Close'),
 
276
                $self, Wx::ID_CANCEL, Wx::gettext('&Close'),
277
277
        );
278
278
 
279
 
        my $buttons = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
 
279
        my $buttons = Wx::BoxSizer->new(Wx::HORIZONTAL);
280
280
        $buttons->AddStretchSpacer;
281
 
        $buttons->Add( $self->{insert_button}, 0, Wx::wxALL, 1 );
282
 
        $buttons->Add( $self->{close_button},  0, Wx::wxALL, 1 );
 
281
        $buttons->Add( $self->{insert_button}, 0, Wx::ALL, 1 );
 
282
        $buttons->Add( $self->{close_button},  0, Wx::ALL, 1 );
283
283
        $buttons->AddStretchSpacer;
284
284
 
285
285
        # Modifiers
296
296
 
297
297
        # Dialog Layout
298
298
 
299
 
        my $modifiers = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
300
 
        $modifiers->AddStretchSpacer;
301
 
        $modifiers->Add( $self->{ignore_case}, 0, Wx::wxALL, 1 );
302
 
        $modifiers->Add( $self->{single_line}, 0, Wx::wxALL, 1 );
303
 
        $modifiers->Add( $self->{multi_line},  0, Wx::wxALL, 1 );
304
 
        $modifiers->Add( $self->{extended},    0, Wx::wxALL, 1 );
305
 
        $modifiers->Add( $self->{global},      0, Wx::wxALL, 1 );
306
 
 
307
 
        $modifiers->AddStretchSpacer;
308
 
 
309
 
        my $regex = Wx::BoxSizer->new(Wx::wxVERTICAL);
310
 
        $regex->Add( $self->{regex}, 1, Wx::wxALL | Wx::wxEXPAND, 1 );
311
 
 
312
 
        my $regex_groups = Wx::BoxSizer->new(Wx::wxVERTICAL);
 
299
        my $modifiers = Wx::BoxSizer->new(Wx::HORIZONTAL);
 
300
        $modifiers->AddStretchSpacer;
 
301
        $modifiers->Add( $self->{ignore_case}, 0, Wx::ALL, 1 );
 
302
        $modifiers->Add( $self->{single_line}, 0, Wx::ALL, 1 );
 
303
        $modifiers->Add( $self->{multi_line},  0, Wx::ALL, 1 );
 
304
        $modifiers->Add( $self->{extended},    0, Wx::ALL, 1 );
 
305
        $modifiers->Add( $self->{global},      0, Wx::ALL, 1 );
 
306
 
 
307
        $modifiers->AddStretchSpacer;
 
308
 
 
309
        my $regex = Wx::BoxSizer->new(Wx::VERTICAL);
 
310
        $regex->Add( $self->{regex}, 1, Wx::ALL | Wx::EXPAND, 1 );
 
311
 
 
312
        my $regex_groups = Wx::BoxSizer->new(Wx::VERTICAL);
313
313
        foreach my $code ( sort keys %regex_groups ) {
314
314
                my $button_name = $code . '_button';
315
 
                $regex_groups->Add( $self->{$button_name}, 0, Wx::wxEXPAND, 1 );
 
315
                $regex_groups->Add( $self->{$button_name}, 0, Wx::EXPAND, 1 );
316
316
        }
317
317
 
318
 
        my $combined = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
319
 
        $combined->Add( $regex,        2, Wx::wxALL | Wx::wxEXPAND, 0 );
320
 
        $combined->Add( $regex_groups, 0, Wx::wxALL | Wx::wxEXPAND, 0 );
 
318
        my $combined = Wx::BoxSizer->new(Wx::HORIZONTAL);
 
319
        $combined->Add( $regex,        2, Wx::ALL | Wx::EXPAND, 0 );
 
320
        $combined->Add( $regex_groups, 0, Wx::ALL | Wx::EXPAND, 0 );
321
321
 
322
322
        # Vertical layout of the left hand side
323
 
        my $left = Wx::BoxSizer->new(Wx::wxVERTICAL);
324
 
        $left->Add( $modifiers, 0, Wx::wxALL | Wx::wxEXPAND, 2 );
325
 
        $left->AddSpacer(5);
326
 
        $left->Add( $regex_label, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
327
 
        $left->Add( $combined,    0, Wx::wxALL | Wx::wxEXPAND, 2 );
328
 
 
329
 
        $left->Add( $self->{description_checkbox}, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
330
 
        $left->Add( $self->{description_text},     2, Wx::wxALL | Wx::wxEXPAND, 1 );
331
 
 
332
 
        $left->Add( $original_label,        0, Wx::wxALL | Wx::wxEXPAND, 1 );
333
 
        $left->Add( $self->{original_text}, 1, Wx::wxALL | Wx::wxEXPAND, 1 );
334
 
        $left->Add( $matched_label,         0, Wx::wxALL | Wx::wxEXPAND, 1 );
335
 
        $left->Add( $self->{matched_text},  1, Wx::wxALL | Wx::wxEXPAND, 1 );
336
 
 
337
 
        $left->Add( $self->{replace_checkbox}, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
338
 
        $left->Add( $self->{replace_label},    0, Wx::wxALL | Wx::wxEXPAND, 1 );
339
 
        $left->Add( $self->{replace_text},     1, Wx::wxALL | Wx::wxEXPAND, 1 );
340
 
        $left->Add( $self->{result_label},     0, Wx::wxALL | Wx::wxEXPAND, 1 );
341
 
        $left->Add( $self->{result_text},      1, Wx::wxALL | Wx::wxEXPAND, 1 );
342
 
 
343
 
        $left->AddSpacer(5);
344
 
        $left->Add( $buttons, 0, Wx::wxALL | Wx::wxEXPAND, 1 );
 
323
        my $left = Wx::BoxSizer->new(Wx::VERTICAL);
 
324
        $left->Add( $modifiers, 0, Wx::ALL | Wx::EXPAND, 2 );
 
325
        $left->AddSpacer(5);
 
326
        $left->Add( $regex_label, 0, Wx::ALL | Wx::EXPAND, 1 );
 
327
        $left->Add( $combined,    0, Wx::ALL | Wx::EXPAND, 2 );
 
328
 
 
329
        $left->Add( $self->{description_checkbox}, 0, Wx::ALL | Wx::EXPAND, 1 );
 
330
        $left->Add( $self->{description_text},     2, Wx::ALL | Wx::EXPAND, 1 );
 
331
 
 
332
        $left->Add( $original_label,        0, Wx::ALL | Wx::EXPAND, 1 );
 
333
        $left->Add( $self->{original_text}, 1, Wx::ALL | Wx::EXPAND, 1 );
 
334
        $left->Add( $matched_label,         0, Wx::ALL | Wx::EXPAND, 1 );
 
335
        $left->Add( $self->{matched_text},  1, Wx::ALL | Wx::EXPAND, 1 );
 
336
 
 
337
        $left->Add( $self->{replace_checkbox}, 0, Wx::ALL | Wx::EXPAND, 1 );
 
338
        $left->Add( $self->{replace_label},    0, Wx::ALL | Wx::EXPAND, 1 );
 
339
        $left->Add( $self->{replace_text},     1, Wx::ALL | Wx::EXPAND, 1 );
 
340
        $left->Add( $self->{result_label},     0, Wx::ALL | Wx::EXPAND, 1 );
 
341
        $left->Add( $self->{result_text},      1, Wx::ALL | Wx::EXPAND, 1 );
 
342
 
 
343
        $left->AddSpacer(5);
 
344
        $left->Add( $buttons, 0, Wx::ALL | Wx::EXPAND, 1 );
345
345
 
346
346
        # Main sizer
347
 
        $sizer->Add( $left, 1, Wx::wxALL | Wx::wxEXPAND, 5 );
 
347
        $sizer->Add( $left, 1, Wx::ALL | Wx::EXPAND, 5 );
348
348
}
349
349
 
350
350
sub _bind_events {
359
359
                $self,
360
360
                sub {
361
361
                        my ($key_event) = $_[1];
362
 
                        $self->Hide if $key_event->GetKeyCode == Wx::WXK_ESCAPE;
 
362
                        $self->Hide if $key_event->GetKeyCode == Wx::K_ESCAPE;
363
363
                        return;
364
364
                }
365
365
        );
421
421
                $self->{matched_text},
422
422
                sub {
423
423
                        my ($key_event) = $_[1];
424
 
                        $self->Hide if $key_event->GetKeyCode == Wx::WXK_ESCAPE;
 
424
                        $self->Hide if $key_event->GetKeyCode == Wx::K_ESCAPE;
425
425
                        return;
426
426
                }
427
427
        );
430
430
                $self->{result_text},
431
431
                sub {
432
432
                        my ($key_event) = $_[1];
433
 
                        $self->Hide if $key_event->GetKeyCode == Wx::WXK_ESCAPE;
 
433
                        $self->Hide if $key_event->GetKeyCode == Wx::K_ESCAPE;
434
434
                        return;
435
435
                }
436
436
        );
454
454
        my ($modifiers) = $self->_get_modifier_settings;
455
455
 
456
456
        my $editor = $self->current->editor or return;
457
 
        $editor->InsertText( $editor->GetCurrentPos, "s/$match_part/$replace_part/$modifiers" );
 
457
        if ( $self->{replace_checkbox}->IsChecked ) {
 
458
                $editor->InsertText( $editor->GetCurrentPos, "s/$match_part/$replace_part/$modifiers" );
 
459
        } else {
 
460
                $editor->InsertText( $editor->GetCurrentPos, "m/$match_part/$modifiers" );
 
461
        }
458
462
 
459
463
        return;
460
464
}
645
649
 
646
650
        # TODO what about white space only regexes?
647
651
        if ( $regex eq '' ) {
648
 
                $self->{matched_text}->BeginTextColour(Wx::wxRED);
 
652
                $self->{matched_text}->BeginTextColour(Wx::RED);
649
653
                $self->{matched_text}->SetValue( Wx::gettext('Empty regex') );
650
654
                $self->{matched_text}->EndTextColour;
651
655
                return;
655
659
 
656
660
        $self->{matched_text}->Clear;
657
661
 
658
 
        $self->{matched_text}->BeginTextColour(Wx::wxBLACK);
 
662
        $self->{matched_text}->BeginTextColour(Wx::BLACK);
659
663
 
660
664
        my $match;
661
665
        my $match_start;
671
675
        my $code = "\$result = \$original_text =~ /\$regex/$active; (\$match_start, \$match_end) = (\$-[0], \$+[0])";
672
676
        eval $code;
673
677
        if ($@) {
674
 
                $self->{matched_text}->BeginTextColour(Wx::wxRED);
 
678
                $self->{matched_text}->BeginTextColour(Wx::RED);
675
679
                $self->{matched_text}->SetValue( sprintf( Wx::gettext('Match failure in %s:  %s'), $regex, $@ ) );
676
680
                $self->{matched_text}->EndTextColour;
677
681
                return;
682
686
        }
683
687
 
684
688
        if ($warning) {
685
 
                $self->{matched_text}->BeginTextColour(Wx::wxRED);
 
689
                $self->{matched_text}->BeginTextColour(Wx::RED);
686
690
                $self->{matched_text}->SetValue( sprintf( Wx::gettext('Match warning in %s:  %s'), $regex, $warning ) );
687
691
                $self->{matched_text}->EndTextColour;
688
692
                return;
690
694
 
691
695
        if ( defined $match ) {
692
696
                if ( $match_start == $match_end ) {
693
 
                        $self->{matched_text}->BeginTextColour(Wx::wxRED);
 
697
                        $self->{matched_text}->BeginTextColour(Wx::RED);
694
698
                        $self->{matched_text}
695
699
                                ->SetValue( sprintf( Wx::gettext('Match with 0 width at character %s'), $match_start ) );
696
700
                        $self->{matched_text}->EndTextColour;
699
703
                        my $pos = 0;
700
704
                        foreach my $char (@chars) {
701
705
                                if ( $pos == $match_start ) {
702
 
                                        $self->{matched_text}->BeginTextColour(Wx::wxRED);
 
706
                                        $self->{matched_text}->BeginTextColour(Wx::BLUE);
703
707
                                        $self->{matched_text}->BeginUnderline;
704
708
                                } elsif ( $pos == $match_end ) {
705
709
                                        $self->{matched_text}->EndTextColour;
710
714
                        }
711
715
                }
712
716
        } else {
713
 
                $self->{matched_text}->BeginTextColour(Wx::wxRED);
 
717
                $self->{matched_text}->BeginTextColour(Wx::RED);
714
718
                $self->{matched_text}->SetValue( Wx::gettext('No match') );
715
719
                $self->{matched_text}->EndTextColour;
716
720
        }
717
721
        $self->{matched_text}->EndTextColour;
718
722
 
719
 
 
720
723
        $self->replace;
721
724
 
722
725
        $self->{description_text}->SetValue( $self->_dump_regex($regex) ) if $self->{description_text}->IsShown;
726
729
        #       foreach my $element (@elements) {
727
730
        #               my $class_name = $element->element->class;
728
731
        #               if ($class_name eq 'PPIx::Regexp::Token::CharClass::Simple') {
729
 
        #                       $self->{regex}->BeginTextColour(Wx::wxRED);
 
732
        #                       $self->{regex}->BeginTextColour(Wx::RED);
730
733
        #               } elsif( $class_name eq 'PPIx::Regexp::Token::Quantifier') {
731
 
        #                       $self->{regex}->BeginTextColour(Wx::wxBLUE);
 
734
        #                       $self->{regex}->BeginTextColour(Wx::BLUE);
732
735
        #               } elsif( $class_name eq 'PPIx::Regexp::Token::Operator') {
733
 
        #                       $self->{regex}->BeginTextColour(Wx::wxLIGHT_GREY);
 
736
        #                       $self->{regex}->BeginTextColour(Wx::LIGHT_GREY);
734
737
        #               } elsif( $class_name eq 'PPIx::Regexp::Structure::Capture') {
735
 
        #                       $self->{regex}->BeginTextColour(Wx::wxCYAN);
 
738
        #                       $self->{regex}->BeginTextColour(Wx::CYAN);
736
739
        #               }
737
740
        #               $self->{regex}->AppendText($element->content);
738
741
        #       $self->{regex}->EndTextColour;
756
759
        my $code = "\$result_text =~ s{\$regex}{$replace}$active";
757
760
        eval $code;
758
761
        if ($@) {
759
 
                $self->{result_text}->BeginTextColour(Wx::wxRED);
 
762
                $self->{result_text}->BeginTextColour(Wx::RED);
760
763
                $self->{result_text}->AppendText( sprintf( Wx::gettext('Replace failure in %s:  %s'), $regex, $@ ) );
761
764
                $self->{result_text}->EndTextColour;
762
765
                return;