1
package Padre::Wx::FindFast;
10
use Padre::Wx::Icon ();
12
our $VERSION = '0.92';
14
use constant GOOD => Wx::SystemSettings::GetColour( Wx::SYS_COLOUR_WINDOW );
15
use constant BAD => Wx::Colour->new(
17
int( GOOD->Green * 0.5 ),
18
int( GOOD->Blue * 0.5 ),
25
######################################################################
41
my $term = $self->{entry}->GetValue;
42
return '' unless defined $term;
50
######################################################################
56
# initiate/continue searching in $direction.
60
my $direction = shift;
61
my $current = Padre::Current->new;
62
my $editor = $current->editor or return;
64
$self->{backward} = $direction eq 'previous';
65
unless ( $self->{panel} ) {
70
my $pane = $current->main->aui->GetPane('find');
71
if ( $pane->IsShown ) {
82
my $current = Padre::Current->new;
83
my $editor = $current->editor or return;
84
my $lock = $self->lock_update;
86
# Reset the dialog status
89
# Build the search expression
90
my $find_term = $self->{entry}->GetValue;
91
if ( length $find_term ) {
92
require Padre::Search;
93
my $search = Padre::Search->new(
94
find_case => $self->{case}->GetValue,
96
find_reverse => $self->{backward},
97
find_term => $find_term,
100
# Handle restarting the search
101
if ( $self->{restart} ) {
102
$editor->SetSelection( 0, 0 );
103
$self->{restart} = 0;
107
unless ( $current->main->search_next($search) ) {
110
$self->{entry}->SetFocus;
116
# -- GUI related subs
121
# create find panel in aui manager.
125
my $main = Padre::Current->main;
127
# The panel and the boxsizer to place controls
128
$self->{outer} = Wx::BoxSizer->new(Wx::HORIZONTAL);
129
$self->{panel} = Wx::Panel->new( $main, -1, Wx::DefaultPosition, Wx::DefaultSize );
130
$self->{hbox} = Wx::BoxSizer->new(Wx::HORIZONTAL);
133
$self->{close} = Wx::BitmapButton->new(
135
Padre::Wx::Icon::find('actions/x-document-close'),
136
Wx::Point->new( -1, -1 ),
137
Wx::Size->new( -1, -1 ),
140
Wx::Event::EVT_BUTTON( $main, $self->{close}, sub { $self->_hide_panel } );
143
$self->{label} = Wx::StaticText->new( $self->{panel}, -1, Wx::gettext('Find:') );
144
$self->{entry} = Wx::TextCtrl->new( $self->{panel}, -1, '' );
145
$self->{entry}->SetMinSize( Wx::Size->new( 25 * $self->{entry}->GetCharWidth, -1 ) );
146
Wx::Event::EVT_CHAR( $self->{entry}, sub { $self->_on_key_pressed( $_[1] ) } );
147
Wx::Event::EVT_TEXT( $main, $self->{entry}, sub { $self->_on_entry_changed( $_[1] ) } );
150
$self->{previous} = Wx::BitmapButton->new(
152
Padre::Wx::Icon::find('actions/go-previous'),
153
Wx::Point->new( -1, -1 ),
154
Wx::Size->new( -1, -1 ),
158
Wx::Event::EVT_BUTTON( $main, $self->{previous}, sub { $self->search('previous') } );
159
$self->{previous_text} = Wx::Button->new(
161
Wx::gettext('Previ&ous'),
162
Wx::Point->new( -1, -1 ),
163
Wx::Size->new( -1, -1 ),
166
Wx::Event::EVT_BUTTON( $main, $self->{previous_text}, sub { $self->search('previous') } );
169
$self->{next} = Wx::BitmapButton->new(
171
Padre::Wx::Icon::find('actions/go-next'),
172
Wx::Point->new( -1, -1 ),
173
Wx::Size->new( -1, -1 ),
176
Wx::Event::EVT_BUTTON( $main, $self->{next}, sub { $self->search('next') } );
177
$self->{next_text} = Wx::Button->new(
179
Wx::gettext('&Next'),
180
Wx::Point->new( -1, -1 ),
181
Wx::Size->new( -1, -1 ),
184
Wx::Event::EVT_BUTTON( $main, $self->{next_text}, sub { $self->search('next') } );
187
$self->{case} = Wx::CheckBox->new( $self->{panel}, -1, Wx::gettext('Case &sensitive') );
188
Wx::Event::EVT_CHECKBOX( $main, $self->{case}, sub { $self->_on_case_checked } );
191
$self->{hbox}->Add( $self->{close}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::ALL, 5 );
192
$self->{hbox}->Add( $self->{label}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::LEFT, 10 );
193
$self->{hbox}->Add( $self->{entry}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::ALL, 5 );
194
$self->{hbox}->Add( $self->{previous}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::ALL, 5 );
195
$self->{hbox}->Add( $self->{previous_text}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::ALL, 5 );
196
$self->{hbox}->Add( $self->{next}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::ALL, 5 );
197
$self->{hbox}->Add( $self->{next_text}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::ALL, 5 );
198
$self->{hbox}->Add( $self->{case}, 0, Wx::ALIGN_CENTER_VERTICAL | Wx::ALL, 5 );
199
$self->{hbox}->Add( 0, 1, Wx::EXPAND, 5 );
201
$self->{panel}->SetSizer( $self->{hbox} );
202
$self->{panel}->Layout;
203
$self->{hbox}->Fit( $self->{panel} );
205
$self->{outer}->Add( $self->{panel}, 1, Wx::ALIGN_LEFT | Wx::ALL | Wx::EXPAND, 5 );
207
my $width = $main->current->editor->GetSize->GetWidth;
208
my $height = $self->{panel}->GetSize->GetHeight;
209
my $size = Wx::Size->new( $width, $height );
210
$self->{panel}->SetSize($size);
212
# manage the pane in aui
215
Padre::Wx->aui_pane_info(
220
)->Bottom->Fixed->Hide,
230
my $auimngr = Padre->ide->wx->main->aui;
231
$auimngr->GetPane('find')->Hide;
234
$self->{visible} = 0;
236
Padre::Current->editor->SetFocus;
244
# Create the panel if needed
245
unless ( $self->{panel} ) {
246
$self->_create_panel;
249
# Show the panel; pane != panel
250
my $auimngr = Padre->ide->wx->main->aui;
251
$auimngr->GetPane('find')->Show(1);
256
$self->{case}->SetValue(0);
257
$self->{entry}->SetValue('');
258
$self->{entry}->SetFocus;
259
$self->{visible} = 1;
265
$_[0]->{visible} || 0;
273
# called when the "case insensitive" checkbox has changed value. in that
274
# case, we'll restart searching from the start of the document.
276
sub _on_case_checked {
278
$self->{restart} = 1;
279
$self->{entry}->SetFocus;
284
# _on_entry_changed()
286
# called when the entry content has changed (keyboard or other mean). in that
287
# case, we'll start searching from the start of the document.
289
sub _on_entry_changed {
291
$self->{restart} = 1;
298
# called when a key is pressed in the entry. used to trap
300
# return = find again
301
# search, otherwise dispatch event up-stack.
303
sub _on_key_pressed {
306
my $mod = $event->GetModifiers || 0;
307
my $code = $event->GetKeyCode;
309
# Remove the bit ( Wx::MOD_META) set by Num Lock being pressed on Linux
310
$mod = $mod & ( Wx::MOD_ALT + Wx::MOD_CMD + Wx::MOD_SHIFT );
312
if ( $code == Wx::K_ESCAPE ) {
316
if ( $code == Wx::K_RETURN ) {
324
# Set the status visuals as good/bad
326
$_[0]->{entry}->SetBackgroundColour( $_[1] ? GOOD : BAD );
331
my $lock = Wx::WindowUpdateLocker->new( $self->{entry} );
332
my $editor = Padre::Current->editor;
334
$lock = [ $lock, $editor->lock_update ];
341
# Copyright 2008-2011 The Padre development team as listed in Padre.pm.
343
# This program is free software; you can redistribute it and/or
344
# modify it under the same terms as Perl 5 itself.