1
package Padre::Action::Search;
3
# Fully encapsulated Search menu
10
use Padre::Current qw{_CURRENT};
12
use Padre::Wx::Menu ();
14
our $VERSION = '0.50';
18
#####################################################################
19
# Padre::Wx::Menu Methods
25
# Create the empty object as normal, it won't be used usually
26
my $self = bless {}, $class;
28
# Add additional properties
29
$self->{main} = $main;
33
name => 'search.find',
36
label => Wx::gettext('&Find'),
37
comment => Wx::gettext('Find text or regular expressions using a traditional dialog'),
45
name => 'search.find_next',
46
label => Wx::gettext('Find Next'),
48
comment => Wx::gettext('Repeat the last find to find the next match'),
51
my $editor = $_[0]->current->editor;
53
# Handle the obvious case with nothing selected
54
my ( $position1, $position2 ) = $editor->GetSelection;
55
if ( $position1 == $position2 ) {
56
return $_[0]->search_next;
59
# Multiple lines are also done the obvious way
60
my $line1 = $editor->LineFromPosition($position1);
61
my $line2 = $editor->LineFromPosition($position2);
62
unless ( $line1 == $line2 ) {
63
return $_[0]->search_next;
66
# Special case. Make and save a non-regex
67
# case-insensitive search and advance to the next hit.
68
my $search = Padre::Search->new(
72
find_term => $editor->GetTextRange(
73
$position1, $position2,
76
$_[0]->search_next($search);
78
# If we can't find another match, show a message
79
if ( ( $editor->GetSelection )[0] == $position1 ) {
80
$_[0]->error( Wx::gettext("Failed to find any matches") );
86
name => 'search.find_previous',
88
label => Wx::gettext('&Find Previous'),
89
comment => Wx::gettext('Repeat the last find, but backwards to find the previous match'),
90
shortcut => 'Shift-F3',
92
$_[0]->search_previous;
96
# Quick Find: starts search with selected text
98
name => 'search.quick_find',
100
label => Wx::gettext('Quick Find'),
101
menu_method => 'AppendCheckItem',
105
$_[1]->IsChecked ? 1 : 0,
109
checked_default => $main->config->find_quick,
112
# We should be able to remove F4 and shift-F4 and hook this functionality
113
# to F3 and shift-F3 Incremental find (#60)
115
name => 'search.quick_find_next',
117
label => Wx::gettext('Find Next'),
118
comment => Wx::gettext('Find next matching text using a toolbar-like dialog at the bottom of the editor'),
121
$_[0]->fast_find->search('next');
126
name => 'search.quick_find_previous',
128
label => Wx::gettext('Find Previous'),
129
comment => Wx::gettext('Find previous matching text using a toolbar-like dialog at the bottom of the editor'),
130
shortcut => 'Shift-F4',
132
$_[0]->fast_find->search('previous');
138
name => 'search.replace',
140
label => Wx::gettext('Replace'),
141
comment => Wx::gettext('Find a text and replace it'),
142
shortcut => 'Ctrl-R',
144
$_[0]->replace->find;
150
name => 'search.find_in_files',
151
label => Wx::gettext('Find in Fi&les...'),
152
comment => Wx::gettext('Search for a text in all files below a given directory'),
154
require Padre::Wx::Ack;
155
Padre::Wx::Ack::on_ack(@_);
160
name => 'search.open_resource',
161
label => Wx::gettext('Open Resource'),
162
shortcut => 'Ctrl-Shift-R',
165
#Create and show the dialog
166
my $open_resource_dialog = $_[0]->open_resource;
167
$open_resource_dialog->showIt;
172
name => 'search.quick_menu_access',
173
label => Wx::gettext('Quick Menu Access'),
174
comment => Wx::gettext('Quick access to all menu functions'),
175
shortcut => 'Ctrl-3',
178
#Create and show the dialog
179
require Padre::Wx::Dialog::QuickMenuAccess;
180
Padre::Wx::Dialog::QuickMenuAccess->new($main)->ShowModal;
189
# Copyright 2008-2009 The Padre development team as listed in Padre.pm.
191
# This program is free software; you can redistribute it and/or
192
# modify it under the same terms as Perl 5 itself.