~ubuntu-branches/debian/sid/padre/sid

« back to all changes in this revision

Viewing changes to lib/Padre/Action/Search.pm

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov, gregor herrmann, Damyan Ivanov
  • Date: 2009-11-18 17:48:27 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20091118174827-srz62scl23gdl88v
Tags: 0.50.ds1-1
[ gregor herrmann ]
* debian/control: change dependency on "libclass-xsaccessor-array-perl
  (>= 1.02)" to "libclass-xsaccessor-perl (>= 1.05-2) |
  libclass-xsaccessor-array-perl (>= 1.02)".

[ Damyan Ivanov ]
* New upstream release
  + copyright: add a new translator
    - describe share/doc/perlopref copyright and licensing
  + update patches:
    - refresh disable-tcp-server.patch
    - drop fix-man-whatis.patch and fix-pod.patch (merged upstream)
    - drop fix-helpprovider-with-no-perlopref.patch: no longer necessary
* repack.sh: in 0.49 padre.exe moved from script/ to bin/
  + perlopref is now properly licensed
* add perl (>= 5.10.1) as a preferred alternative to versioned (build)
  dependencies on libtest-simple-perl and libpod-simple-perl
* update debian/not-real-manual.list for 0.50 (one file added, two files
  changed in size)
* rules: remove cruft from padre.deb
  + license etc from perlopref directory (already present in d/copyright)
  + remove .po files from the .deb (there are .mo files installed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Padre::Action::Search;
 
2
 
 
3
# Fully encapsulated Search menu
 
4
 
 
5
use 5.008;
 
6
use strict;
 
7
use warnings;
 
8
use Padre::Action;
 
9
use Padre::Search ();
 
10
use Padre::Current qw{_CURRENT};
 
11
use Padre::Wx       ();
 
12
use Padre::Wx::Menu ();
 
13
 
 
14
our $VERSION = '0.50';
 
15
 
 
16
 
 
17
 
 
18
#####################################################################
 
19
# Padre::Wx::Menu Methods
 
20
 
 
21
sub new {
 
22
        my $class = shift;
 
23
        my $main  = shift;
 
24
 
 
25
        # Create the empty object as normal, it won't be used usually
 
26
        my $self = bless {}, $class;
 
27
 
 
28
        # Add additional properties
 
29
        $self->{main} = $main;
 
30
 
 
31
        # Search
 
32
        Padre::Action->new(
 
33
                name        => 'search.find',
 
34
                id          => Wx::wxID_FIND,
 
35
                need_editor => 1,
 
36
                label       => Wx::gettext('&Find'),
 
37
                comment     => Wx::gettext('Find text or regular expressions using a traditional dialog'),
 
38
                shortcut    => 'Ctrl-F',
 
39
                menu_event  => sub {
 
40
                        $_[0]->find->find;
 
41
                },
 
42
        );
 
43
 
 
44
        Padre::Action->new(
 
45
                name        => 'search.find_next',
 
46
                label       => Wx::gettext('Find Next'),
 
47
                need_editor => 1,
 
48
                comment     => Wx::gettext('Repeat the last find to find the next match'),
 
49
                shortcut    => 'F3',
 
50
                menu_event  => sub {
 
51
                        my $editor = $_[0]->current->editor;
 
52
 
 
53
                        # Handle the obvious case with nothing selected
 
54
                        my ( $position1, $position2 ) = $editor->GetSelection;
 
55
                        if ( $position1 == $position2 ) {
 
56
                                return $_[0]->search_next;
 
57
                        }
 
58
 
 
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;
 
64
                        }
 
65
 
 
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(
 
69
                                find_case    => 0,
 
70
                                find_regex   => 0,
 
71
                                find_reverse => 0,
 
72
                                find_term    => $editor->GetTextRange(
 
73
                                        $position1, $position2,
 
74
                                ),
 
75
                        );
 
76
                        $_[0]->search_next($search);
 
77
 
 
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") );
 
81
                        }
 
82
                },
 
83
        );
 
84
 
 
85
        Padre::Action->new(
 
86
                name        => 'search.find_previous',
 
87
                need_editor => 1,
 
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',
 
91
                menu_event  => sub {
 
92
                        $_[0]->search_previous;
 
93
                },
 
94
        );
 
95
 
 
96
        # Quick Find: starts search with selected text
 
97
        Padre::Action->new(
 
98
                name        => 'search.quick_find',
 
99
                need_editor => 1,
 
100
                label       => Wx::gettext('Quick Find'),
 
101
                menu_method => 'AppendCheckItem',
 
102
                menu_event  => sub {
 
103
                        $_[0]->config->set(
 
104
                                'find_quick',
 
105
                                $_[1]->IsChecked ? 1 : 0,
 
106
                        );
 
107
                        return;
 
108
                },
 
109
                checked_default => $main->config->find_quick,
 
110
        );
 
111
 
 
112
        # We should be able to remove F4 and shift-F4 and hook this functionality
 
113
        # to F3 and shift-F3 Incremental find (#60)
 
114
        Padre::Action->new(
 
115
                name        => 'search.quick_find_next',
 
116
                need_editor => 1,
 
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'),
 
119
                shortcut    => 'F4',
 
120
                menu_event  => sub {
 
121
                        $_[0]->fast_find->search('next');
 
122
                },
 
123
        );
 
124
 
 
125
        Padre::Action->new(
 
126
                name        => 'search.quick_find_previous',
 
127
                need_editor => 1,
 
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',
 
131
                menu_event => sub {
 
132
                        $_[0]->fast_find->search('previous');
 
133
                },
 
134
        );
 
135
 
 
136
        # Search and Replace
 
137
        Padre::Action->new(
 
138
                name        => 'search.replace',
 
139
                need_editor => 1,
 
140
                label       => Wx::gettext('Replace'),
 
141
                comment     => Wx::gettext('Find a text and replace it'),
 
142
                shortcut    => 'Ctrl-R',
 
143
                menu_event  => sub {
 
144
                        $_[0]->replace->find;
 
145
                },
 
146
        );
 
147
 
 
148
        # Recursive Search
 
149
        Padre::Action->new(
 
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'),
 
153
                menu_event => sub {
 
154
                        require Padre::Wx::Ack;
 
155
                        Padre::Wx::Ack::on_ack(@_);
 
156
                },
 
157
        );
 
158
 
 
159
        Padre::Action->new(
 
160
                name       => 'search.open_resource',
 
161
                label      => Wx::gettext('Open Resource'),
 
162
                shortcut   => 'Ctrl-Shift-R',
 
163
                menu_event => sub {
 
164
 
 
165
                        #Create and show the dialog
 
166
                        my $open_resource_dialog = $_[0]->open_resource;
 
167
                        $open_resource_dialog->showIt;
 
168
                },
 
169
        );
 
170
 
 
171
        Padre::Action->new(
 
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',
 
176
                menu_event => sub {
 
177
 
 
178
                        #Create and show the dialog
 
179
                        require Padre::Wx::Dialog::QuickMenuAccess;
 
180
                        Padre::Wx::Dialog::QuickMenuAccess->new($main)->ShowModal;
 
181
                },
 
182
        );
 
183
 
 
184
        return $self;
 
185
}
 
186
 
 
187
1;
 
188
 
 
189
# Copyright 2008-2009 The Padre development team as listed in Padre.pm.
 
190
# LICENSE
 
191
# This program is free software; you can redistribute it and/or
 
192
# modify it under the same terms as Perl 5 itself.