8
use Padre::Role::Task ();
9
use Padre::Wx::Role::View ();
10
use Padre::Wx::Role::Main ();
9
use Padre::Role::Task ();
10
use Padre::Wx::Role::View ();
11
use Padre::Wx::Role::Main ();
13
use Padre::Wx::FBP::Outline ();
14
our $VERSION = '0.90';
16
our $VERSION = '0.92';
17
19
Padre::Wx::Role::View
18
20
Padre::Wx::Role::Main
21
Padre::Wx::FBP::Outline
32
34
my $panel = shift || $main->right;
35
my $self = $class->SUPER::new($panel);
34
37
# This tool is just a single tree control
35
my $self = $class->SUPER::new(
38
Wx::wxDefaultPosition,
40
Wx::wxTR_HIDE_ROOT | Wx::wxTR_SINGLE | Wx::wxTR_HAS_BUTTONS | Wx::wxTR_LINES_AT_ROOT
44
Wx::Event::EVT_COMMAND_SET_FOCUS(
38
my $tree = $self->{tree};
42
# Prepare the available images
43
my $images = Wx::ImageList->new( 16, 16 );
45
folder => $images->Add(
46
Wx::ArtProvider::GetBitmap(
53
Wx::ArtProvider::GetBitmap(
60
$tree->AssignImageList($images);
47
$self->on_tree_item_set_focus( $_[1] );
51
# Double-click a function name
52
Wx::Event::EVT_TREE_ITEM_ACTIVATED(
70
# Handle char events in search box
55
$self->on_tree_item_activated( $_[1] );
74
my ( $this, $event ) = @_;
76
my $code = $event->GetKeyCode;
77
if ( $code == Wx::K_DOWN or $code == Wx::K_UP or $code == Wx::K_RETURN ) {
79
# Up/Down and return keys focus on the functions lists
80
my $tree = $self->{tree};
82
my $selection = $tree->GetSelection;
83
if ( $selection == -1 and $tree->GetCount > 0 ) {
86
$tree->SelectItem($selection);
87
} elsif ( $code == Wx::K_ESCAPE ) {
89
# Escape key clears search and returns focus
91
$self->{search}->SetValue('');
92
my $editor = $self->current->editor;
93
$editor->SetFocus if $editor;
61
# Cache document metadata for use when changing documents.
62
# By substituting old metadata before we scan for new metadata,
63
# we can make the widget APPEAR to be faster than it is and
64
# offset the cost of doing the PPI parse in the background.
65
# $self->{cache} = {};
101
if (Padre::Feature::STYLE_GUI) {
102
$self->main->theme->apply($self);
79
117
my $event = shift;
81
119
my $menu = Wx::Menu->new;
82
my $pldata = $self->GetPlData( $event->GetItem );
120
my $tree = $self->{tree};
121
my $pldata = $tree->GetPlData( $event->GetItem );
84
123
if ( defined($pldata) && defined( $pldata->{line} ) && $pldata->{line} > 0 ) {
85
124
my $goto = $menu->Append( -1, Wx::gettext('&Go to Element') );
116
155
if ( $show > 0 ) {
117
156
my $x = $event->GetPoint->x;
118
157
my $y = $event->GetPoint->y;
119
$self->PopupMenu( $menu, $x, $y );
158
$tree->PopupMenu( $menu, $x, $y );
130
169
sub on_tree_item_set_focus {
131
170
my $self = shift;
132
171
my $event = shift;
133
my $selection = $self->GetSelection;
172
my $tree = $self->{tree};
173
my $selection = $tree->GetSelection;
134
174
if ( $selection and $selection->IsOk ) {
135
my $item = $self->GetPlData($selection);
175
my $item = $tree->GetPlData($selection);
136
176
if ( defined $item ) {
137
177
$self->select_line_in_editor( $item->{line} );
175
215
my $self = shift;
176
216
my $task = shift;
177
217
my $data = Params::Util::_ARRAY( $task->{data} ) or return;
178
my $lock = $self->main->lock('UPDATE');
218
my $lock = $self->lock_update;
220
# Cache data model for faster searches
221
$self->{data} = $data;
231
my $data = $self->{data};
232
my $search_term = quotemeta $self->{search}->GetValue;
180
234
# Clear any old content
183
237
# Add the hidden unused root
184
my $root = $self->AddRoot(
238
my $tree = $self->{tree};
239
my $images = $self->{images};
240
my $root = $tree->AddRoot(
185
241
Wx::gettext('Outline'),
260
$tree->SetItemImage( $branch, $images->{folder} );
204
262
my @types = qw(classes grammars packages pragmata modules
205
263
attributes methods events roles regexes);
206
264
foreach my $type (@types) {
207
265
$self->add_subtree( $pkg, $type, $branch );
209
$self->Expand($branch);
267
$tree->Expand($branch);
212
270
# Set MIME type specific event handler
213
271
Wx::Event::EVT_TREE_ITEM_RIGHT_CLICK(
216
$_[0]->on_tree_item_right_click( $_[1] );
274
$self->on_tree_item_right_click( $_[1] );
220
# TO DO Expanding all is not acceptable: We need to keep the state
221
# (i.e., keep the pragmata subtree collapsed if it was collapsed
224
278
$self->GetBestSize;
233
287
######################################################################
234
288
# General Methods
290
# Sets the focus on the search field
291
sub focus_on_search {
292
$_[0]->{search}->SetFocus;
236
295
sub gettext_label {
237
296
Wx::gettext('Outline');
241
$_[0]->DeleteAllItems;
300
$_[0]->{tree}->DeleteAllItems;
245
304
TRACE( $_[0] ) if DEBUG;
306
my $current = shift or return;
307
my $document = $current->document;
308
my $lock = $self->lock_update;
309
my $tree = $self->{tree};
248
311
# Cancel any existing outline task
249
312
$self->task_reset;
251
# Shortcut if the document is empty
252
my $document = $self->current->document;
253
unless ( $document and not $document->is_unused ) {
317
# Hide the widgets when no files are open
258
323
# Is there an outline task for this document type
259
324
my $task = $document->task_outline;
330
# Shortcut if there is nothing to search for
331
if ( $document->is_unused ) {
336
# Ensure the search box and tree are visible
265
339
# Trigger the task to fetch the refresh data
266
340
$self->task_request(
347
$_[0]->{search}->Hide;
354
$self->{search}->Show;
357
# Recalculate our layout in case the view geometry
358
# has changed from when we were hidden.
272
362
sub add_subtree {
273
363
my ( $self, $pkg, $type, $root ) = @_;
364
my $tree = $self->{tree};
365
my $search_term = quotemeta $self->{search}->GetValue;
366
my $images = $self->{images};
275
368
my %type_caption = (
276
369
pragmata => Wx::gettext('Pragmata'),
288
381
warn "Type not translated: $type_caption\n";
291
$type_elem = $self->AppendItem(
384
$type_elem = $tree->AppendItem(
296
389
Wx::TreeItemData->new
391
$tree->SetItemImage( $type_elem, $images->{folder} );
299
393
my @sorted_entries = ();
300
394
if ( $type eq 'methods' ) {
321
415
foreach my $item (@sorted_entries) {
416
my $name = $item->{name};
417
next if $name !~ /$search_term/;
418
my $item = $tree->AppendItem(
326
421
Wx::TreeItemData->new(
327
422
{ line => $item->{line},
328
name => $item->{name},
428
$tree->SetItemImage( $item, $images->{file} );
335
432
if ( defined $type_elem ) {
336
if ( $type eq 'methods' ) {
337
$self->Expand($type_elem);
433
if ( length $search_term > 0 ) {
434
$tree->Expand($type_elem);
339
if ( $self->IsExpanded($type_elem) ) {
340
$self->Collapse($type_elem);
436
if ( $type eq 'methods' ) {
437
$tree->Expand($type_elem);
439
if ( $tree->IsExpanded($type_elem) ) {
440
$tree->Collapse($type_elem);