| 1 | Index: lib/Padre/Search.pm |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- lib/Padre/Search.pm (revision 9142) |
|---|
| 4 | +++ lib/Padre/Search.pm (working copy) |
|---|
| 5 | @@ -330,6 +330,8 @@ |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | + |
|---|
| 10 | + |
|---|
| 11 | ##################################################################### |
|---|
| 12 | # Core Search |
|---|
| 13 | |
|---|
| 14 | @@ -388,6 +390,25 @@ |
|---|
| 15 | return ( @$pair, @matches ); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | +sub match_lines { |
|---|
| 19 | + my ($self,$selected_text,$regex) = @_; |
|---|
| 20 | + |
|---|
| 21 | + # Searches run in unicode |
|---|
| 22 | + my $text = Encode::encode( 'utf-8', $selected_text ); |
|---|
| 23 | + my @lines = split (/\n/, $text ); |
|---|
| 24 | + |
|---|
| 25 | + my @matches; |
|---|
| 26 | + foreach my $lineNumber (0 .. (scalar(@lines)-1)) { |
|---|
| 27 | + |
|---|
| 28 | + if ($lines[$lineNumber] =~ /$regex/){ |
|---|
| 29 | + push (@matches, ({lineNumber=>($lineNumber +1), line=>$lines[$lineNumber]})); |
|---|
| 30 | + } |
|---|
| 31 | + |
|---|
| 32 | + } |
|---|
| 33 | + return @matches; |
|---|
| 34 | + |
|---|
| 35 | +} |
|---|
| 36 | + |
|---|
| 37 | 1; |
|---|
| 38 | |
|---|
| 39 | =pod |
|---|
| 40 | Index: lib/Padre/Wx/Dialog/Find.pm |
|---|
| 41 | =================================================================== |
|---|
| 42 | --- lib/Padre/Wx/Dialog/Find.pm (revision 9142) |
|---|
| 43 | +++ lib/Padre/Wx/Dialog/Find.pm (working copy) |
|---|
| 44 | @@ -24,6 +24,7 @@ |
|---|
| 45 | use Padre::Wx (); |
|---|
| 46 | use Padre::Wx::Role::MainChild (); |
|---|
| 47 | use Padre::Wx::History::ComboBox (); |
|---|
| 48 | +use Padre::Wx::FindResult (); |
|---|
| 49 | |
|---|
| 50 | our $VERSION = '0.50'; |
|---|
| 51 | our @ISA = qw{ |
|---|
| 52 | @@ -138,17 +139,17 @@ |
|---|
| 53 | ); |
|---|
| 54 | $self->{button_find}->SetDefault; |
|---|
| 55 | |
|---|
| 56 | - # The "Count All" button |
|---|
| 57 | - $self->{button_count} = Wx::Button->new( |
|---|
| 58 | + # The "Find All" button |
|---|
| 59 | + $self->{findall_button} = Wx::Button->new( |
|---|
| 60 | $self, |
|---|
| 61 | -1, |
|---|
| 62 | - Wx::gettext("&Count All"), |
|---|
| 63 | + Wx::gettext("Find &All"), |
|---|
| 64 | ); |
|---|
| 65 | Wx::Event::EVT_BUTTON( |
|---|
| 66 | $self, |
|---|
| 67 | - $self->{button_count}, |
|---|
| 68 | + $self->{findall_button}, |
|---|
| 69 | sub { |
|---|
| 70 | - $_[0]->count_button; |
|---|
| 71 | + $_[0]->findall_button; |
|---|
| 72 | }, |
|---|
| 73 | ); |
|---|
| 74 | |
|---|
| 75 | @@ -220,7 +221,7 @@ |
|---|
| 76 | # Sizer for the buttons |
|---|
| 77 | my $bottom = Wx::BoxSizer->new(Wx::wxHORIZONTAL); |
|---|
| 78 | $bottom->Add( $self->{button_find}, 0, Wx::wxGROW | Wx::wxLEFT, 5 ); |
|---|
| 79 | - $bottom->Add( $self->{button_count}, 0, Wx::wxGROW, 5 ); |
|---|
| 80 | + $bottom->Add( $self->{findall_button}, 0, Wx::wxGROW, 5 ); |
|---|
| 81 | $bottom->Add( $self->{button_cancel}, 0, Wx::wxGROW | Wx::wxRIGHT, 5 ); |
|---|
| 82 | |
|---|
| 83 | # Fill the sizer for the overall dialog |
|---|
| 84 | @@ -358,33 +359,35 @@ |
|---|
| 85 | |
|---|
| 86 | =head2 count_button |
|---|
| 87 | |
|---|
| 88 | - $self->count_button |
|---|
| 89 | + $self->findall_button |
|---|
| 90 | |
|---|
| 91 | -Count and announce the number of matches in the document. |
|---|
| 92 | +Find all lines with matching text and display in a list. |
|---|
| 93 | |
|---|
| 94 | =cut |
|---|
| 95 | |
|---|
| 96 | -sub count_button { |
|---|
| 97 | +sub findall_button { |
|---|
| 98 | my $self = shift; |
|---|
| 99 | my $main = $self->main; |
|---|
| 100 | my $config = $self->save; |
|---|
| 101 | - |
|---|
| 102 | - # Generate the search object |
|---|
| 103 | + # Generate the search object |
|---|
| 104 | my $search = $self->as_search; |
|---|
| 105 | + |
|---|
| 106 | unless ($search) { |
|---|
| 107 | $main->error( Wx::gettext("Not a valid search") ); |
|---|
| 108 | return; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | - # Find the number of matches |
|---|
| 112 | + |
|---|
| 113 | + |
|---|
| 114 | my $editor = $self->current->editor or return; |
|---|
| 115 | - my $matches = $search->editor_count_all($editor); |
|---|
| 116 | - $main->message( |
|---|
| 117 | - sprintf( |
|---|
| 118 | - Wx::gettext("Found %d matching occurrences"), |
|---|
| 119 | - $matches, |
|---|
| 120 | - ) |
|---|
| 121 | + my @matches = $search->match_lines ( |
|---|
| 122 | + $editor->GetTextRange( 0, $editor->GetLength ), |
|---|
| 123 | + $search->search_regex, |
|---|
| 124 | + $editor->GetSelection |
|---|
| 125 | ); |
|---|
| 126 | + |
|---|
| 127 | + Padre::Wx::FindResult->new($main, \@matches,$editor); |
|---|
| 128 | + $self->Hide; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | |
|---|