~ubuntu-branches/ubuntu/wily/padre/wily

« back to all changes in this revision

Viewing changes to lib/Padre/Wx/Panel/TaskList.pm

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont
  • Date: 2012-05-12 12:40:00 UTC
  • mfrom: (1.3.5)
  • Revision ID: package-import@ubuntu.com-20120512124000-lpfuc4ny1eo3ecvx
Tags: 0.96+dfsg1-1
* new upstream version
* control: 
   * updated dependencies versions
   - removed  libformat-human-bytes-perl
   * cleanup unneeded version dependencies 
   - removed provides on padre-plugin-api-2. The only remaining packages
     depending on this meta package are already incompatible with new 
     padre  (and broken upstream)
   * no need to depend on libtest-warn-perl 0.24, 0.23 is enough
* patches:
   - removed hack-missing-context-menu (obsolete)
   + Skip upstream test that broke with new DBI. See patch header 
     for more details
   + fix spellings reported by lintian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Padre::Wx::Panel::TaskList;
 
2
 
 
3
use 5.008;
 
4
use strict;
 
5
use warnings;
 
6
use Padre::Role::Task        ();
 
7
use Padre::Wx::Role::Idle    ();
 
8
use Padre::Wx::Role::View    ();
 
9
use Padre::Wx::Role::Context ();
 
10
use Padre::Wx::FBP::TaskList ();
 
11
 
 
12
our $VERSION    = '0.96';
 
13
our $COMPATIBLE = '0.95';
 
14
our @ISA        = qw{
 
15
        Padre::Role::Task
 
16
        Padre::Wx::Role::Idle
 
17
        Padre::Wx::Role::View
 
18
        Padre::Wx::Role::Context
 
19
        Padre::Wx::FBP::TaskList
 
20
};
 
21
 
 
22
 
 
23
 
 
24
 
 
25
 
 
26
######################################################################
 
27
# Constructor
 
28
 
 
29
sub new {
 
30
        my $class = shift;
 
31
        my $main  = shift;
 
32
        my $panel = shift || $main->bottom;
 
33
        my $self  = $class->SUPER::new($panel);
 
34
 
 
35
        # Temporary store for the task list.
 
36
        $self->{model} = [];
 
37
 
 
38
        # Remember the last document we were looking at
 
39
        $self->{document} = '';
 
40
 
 
41
        # Create the image list even though we don't use much of it
 
42
        my $images = Wx::ImageList->new( 16, 16 );
 
43
        $self->{images} = {
 
44
                folder => $images->Add(
 
45
                        Wx::ArtProvider::GetBitmap(
 
46
                                'wxART_FOLDER',
 
47
                                'wxART_OTHER_C',
 
48
                                [ 16, 16 ],
 
49
                        ),
 
50
                ),
 
51
                file => $images->Add(
 
52
                        Wx::ArtProvider::GetBitmap(
 
53
                                'wxART_NORMAL_FILE',
 
54
                                'wxART_OTHER_C',
 
55
                                [ 16, 16 ],
 
56
                        ),
 
57
                ),
 
58
                result => $images->Add(
 
59
                        Wx::ArtProvider::GetBitmap(
 
60
                                'wxART_GO_FORWARD',
 
61
                                'wxART_OTHER_C',
 
62
                                [ 16, 16 ],
 
63
                        ),
 
64
                ),
 
65
        };
 
66
        $self->{tree}->AssignImageList($images);
 
67
 
 
68
        Wx::Event::EVT_TREE_ITEM_ACTIVATED(
 
69
                $self,
 
70
                $self->{tree},
 
71
                sub {
 
72
                        $_[0]->idle_method( item_clicked => $_[1]->GetItem );
 
73
                },
 
74
        );
 
75
 
 
76
        # Register for refresh calls
 
77
        $main->add_refresh_listener($self);
 
78
 
 
79
        $self->context_bind;
 
80
 
 
81
        return $self;
 
82
}
 
83
 
 
84
 
 
85
 
 
86
 
 
87
 
 
88
######################################################################
 
89
# Padre::Wx::Role::View Methods
 
90
 
 
91
sub view_panel {
 
92
        return 'bottom';
 
93
}
 
94
 
 
95
sub view_label {
 
96
        Wx::gettext('Task List');
 
97
}
 
98
 
 
99
sub view_close {
 
100
        $_[0]->task_reset;
 
101
        $_[0]->main->show_tasks(0);
 
102
}
 
103
 
 
104
 
 
105
 
 
106
 
 
107
 
 
108
######################################################################
 
109
# Padre::Wx::Role::Context Methods
 
110
 
 
111
sub context_menu {
 
112
        my $self = shift;
 
113
        my $menu = shift;
 
114
 
 
115
        $self->context_append_options( $menu => 'main_tasks_panel' );
 
116
 
 
117
        return;
 
118
}
 
119
 
 
120
 
 
121
 
 
122
 
 
123
 
 
124
######################################################################
 
125
# Refresh and Search
 
126
 
 
127
sub refresh {
 
128
        my $self     = shift;
 
129
        my $current  = shift or return;
 
130
        my $document = $current->document;
 
131
        my $search   = $self->{search};
 
132
        my $tree     = $self->{tree};
 
133
 
 
134
        # Flush and hide the list if there is no active document
 
135
        unless ($document) {
 
136
                my $lock = $self->lock_update;
 
137
                $search->Hide;
 
138
                $tree->Hide;
 
139
                $tree->Clear;
 
140
                $self->{model}    = [];
 
141
                $self->{document} = '';
 
142
                return;
 
143
        }
 
144
 
 
145
        # Ensure the widget is visible
 
146
        $search->Show(1);
 
147
        $tree->Show(1);
 
148
 
 
149
        # Clear search when it is a different document
 
150
        my $id = Scalar::Util::refaddr($document);
 
151
        if ( $id ne $self->{document} ) {
 
152
                $search->ChangeValue('');
 
153
                $self->{document} = $id;
 
154
        }
 
155
 
 
156
        # Unlike the Function List widget we copied to make this,
 
157
        # don't bother with a background task, since this is much quicker.
 
158
        my $regexp = $current->config->main_tasks_regexp;
 
159
        my $text   = $document->text_get;
 
160
        my @items  = ();
 
161
        SCOPE: {
 
162
                local $@;
 
163
                eval {
 
164
                        while ( $text =~ /$regexp/gim )
 
165
                        {
 
166
                                push @items, { text => $1 || '<no text>', 'pos' => pos($text) };
 
167
                        }
 
168
                };
 
169
                $self->main->error(
 
170
                        sprintf(
 
171
                                Wx::gettext('%s in TODO regex, check your config.'),
 
172
                                $@,
 
173
                        )
 
174
                ) if $@;
 
175
        }
 
176
        while ( $text =~ /#\s*(Ticket #\d+.*?)$/gim ) {
 
177
                push @items, { text => $1, 'pos' => pos($text) };
 
178
        }
 
179
 
 
180
        if ( @items == 0 ) {
 
181
                $tree->Clear;
 
182
                $self->{model} = [];
 
183
                return;
 
184
        }
 
185
 
 
186
        # Update the model and rerender
 
187
        $self->{model} = \@items;
 
188
        $self->render;
 
189
}
 
190
 
 
191
# Populate the list with search results
 
192
sub render {
 
193
        my $self   = shift;
 
194
        my $model  = $self->{model};
 
195
        my $search = $self->{search};
 
196
        my $tree   = $self->{tree};
 
197
 
 
198
        # Quote the search string to make it safer
 
199
        my $string = $search->GetValue;
 
200
        if ( $string eq '' ) {
 
201
                $string = '.*';
 
202
        } else {
 
203
                $string = quotemeta $string;
 
204
        }
 
205
 
 
206
        # Show the components and populate the function list
 
207
        SCOPE: {
 
208
                my $lock = $self->lock_update;
 
209
                $search->Show(1);
 
210
                $tree->Show(1);
 
211
                $tree->Clear;
 
212
                foreach my $task ( reverse @$model ) {
 
213
                        my $text = $task->{text};
 
214
                        if ( $text =~ /$string/i ) {
 
215
                                $tree->Insert( $text, 0 );
 
216
                        }
 
217
                }
 
218
        }
 
219
 
 
220
        return 1;
 
221
}
 
222
 
 
223
 
 
224
 
 
225
 
 
226
 
 
227
######################################################################
 
228
# General Methods
 
229
 
 
230
sub item_clicked {
 
231
        my $self   = shift;
 
232
        my $item   = shift or return;
 
233
        my $tree   = $self->{tree};
 
234
        my $data   = $tree->GetPlData($item) or return;
 
235
        my $line   = $data->{line} or return;
 
236
        my $editor = $self->current->editor or return;
 
237
        $editor->goto_pos_centerize($line);
 
238
        $editor->SetFocus;
 
239
}
 
240
 
 
241
1;
 
242
 
 
243
# Copyright 2008-2012 The Padre development team as listed in Padre.pm.
 
244
# LICENSE
 
245
# This program is free software; you can redistribute it and/or
 
246
# modify it under the same terms as Perl 5 itself.