File Coverage

lib/Devel/ebug/Wx/View/Notebook.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Devel::ebug::Wx::View::Notebook;
2              
3 1     1   2732 use Wx::AUI;
  0            
  0            
4              
5             use strict;
6             use base qw(Wx::AuiNotebook Devel::ebug::Wx::View::Multi);
7             use Devel::ebug::Wx::Plugin qw(:plugin);
8              
9             __PACKAGE__->mk_accessors( qw(has_views) );
10              
11             use Wx qw(:aui);
12             use Wx::Event qw(EVT_RIGHT_UP EVT_MENU);
13              
14             sub tag_base { 'notebook' }
15             sub description_base { 'Notebook' }
16              
17             sub new : View {
18             my( $class, $parent, $wxebug, $layout_state ) = @_;
19             my $self = $class->SUPER::new( $parent, -1, [-1, -1], [-1, -1],
20             wxAUI_NB_TAB_MOVE|wxAUI_NB_CLOSE_BUTTON|
21             wxAUI_NB_WINDOWLIST_BUTTON );
22              
23             $self->wxebug( $wxebug );
24             $self->SetSize( $self->default_size );
25              
26             $self->AddPage( Wx::StaticText->new( $self, -1,
27             "Use 'View -> Edit Notebooks'" ),
28             'Add pages' );
29             $self->set_layout_state( $layout_state ) if $layout_state;
30             $self->register_view;
31              
32             return $self;
33             }
34              
35             sub add_view {
36             my( $self, $view ) = @_;
37             my $instance = $self->wxebug->view_manager_service->get_view( $view->tag );
38              
39             if( !$self->has_views ) {
40             $self->DeletePage( 0 );
41             }
42             # always destroy if present
43             if( $instance ) {
44             $instance->Destroy;
45             }
46             $instance = $view->new( $self, $self->wxebug );
47             $self->AddPage( $instance, $instance->description );
48             $self->has_views( 1 );
49             }
50              
51             sub get_layout_state {
52             my( $self ) = @_;
53             my $state = $self->SUPER::get_layout_state;
54             return $state unless $self->has_views;
55              
56             $state->{notebook} = [ map $_->get_layout_state,
57             map $self->GetPage( $_ ),
58             ( 0 .. $self->GetPageCount - 1 )
59             ];
60              
61             return $state;
62             }
63              
64             sub set_layout_state {
65             my( $self, $state ) = @_;
66             $self->SUPER::set_layout_state( $state );
67              
68             return unless $state->{notebook};
69             $self->DeletePage( 0 ); # FIXME use non ad-hoc handling...
70              
71             foreach my $subview ( @{$state->{notebook} || []} ) {
72             my $instance = $subview->{class}->new( $self, $self->wxebug,
73             $subview );
74             $self->AddPage( $instance, $instance->description );
75             $self->has_views( 1 );
76             }
77             }
78              
79              
80             1;