Changeset 505


Ignore:
Timestamp:
10/26/08 08:50:02 (3 years ago)
Author:
szabgab
Message:

move the abstract dialog creation code to Padre::Wx::Dialog

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MANIFEST

    r470 r505  
    2424lib/Padre/Wx/App.pm 
    2525lib/Padre/Wx/Bookmarks.pm 
     26lib/Padre/Wx/Dialog.pm 
    2627lib/Padre/Wx/Editor.pm 
    2728lib/Padre/Wx/FindDialog.pm 
  • trunk/lib/Padre/Wx/FindDialog.pm

    r467 r505  
    88 
    99use Padre::Wx; 
     10use Padre::Wx::Dialog; 
    1011 
    1112our $VERSION = '0.12'; 
     
    3334 
    3435    my $layout = get_layout($search_term, $config); 
    35     Padre::Wx::ModuleStartDialog::build_layout($dialog, $layout, [150, 200]); 
     36    Padre::Wx::Dialog::build_layout($dialog, $layout, [150, 200]); 
    3637 
    3738    foreach my $cb (@cbs) { 
     
    173174    my ( $dialog ) = @_; 
    174175 
    175     my $data = Padre::Wx::ModuleStartDialog::get_data_from($dialog, get_layout()); 
     176    my $data = Padre::Wx::Dialog::get_data_from($dialog, get_layout()); 
    176177 
    177178    #print Data::Dumper::Dumper $data; 
  • trunk/lib/Padre/Wx/ModuleStartDialog.pm

    r468 r505  
    99# Module::Start widget of Padre 
    1010 
    11 use Padre::Wx  (); 
     11use Padre::Wx         (); 
     12use Padre::Wx::Dialog (); 
    1213 
    1314our $VERSION = '0.12'; 
     
    2526 
    2627    my $layout = get_layout($config); 
    27     build_layout($dialog, $layout, [100, 200]); 
     28    Padre::Wx::Dialog::build_layout($dialog, $layout, [100, 200]); 
    2829 
    2930    $dialog->{_ok_}->SetDefault; 
     
    8182 
    8283 
    83 sub build_layout { 
    84     my ($dialog, $layout, $width) = @_; 
    85  
    86     my $box  = Wx::BoxSizer->new( Wx::wxVERTICAL ); 
    87  
    88     foreach my $i (0..@$layout-1) { 
    89         my $row = Wx::BoxSizer->new( Wx::wxHORIZONTAL ); 
    90         $box->Add($row); 
    91         foreach my $j (0..@{$layout->[$i]}-1) { 
    92             if (not @{ $layout->[$i][$j] } ) {  # [] means Expand 
    93                 $row->Add($width->[$j], 0, 0, Wx::wxEXPAND, 0); 
    94                 next; 
    95             } 
    96             my ($class, $name, $arg, @params) = @{ $layout->[$i][$j] }; 
    97  
    98             my $widget; 
    99             if ($class eq 'Wx::Button') { 
    100                 my ($first, $second) = $arg =~ /[a-zA-Z]/ ? (-1, $arg) : ($arg, ''); 
    101                 $widget = $class->new( $dialog, $first, $second); 
    102             } elsif ($class eq 'Wx::DirPickerCtrl') { 
    103                 my $title = shift(@params) || ''; 
    104                 $widget = $class->new( $dialog, -1, $arg, $title, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
    105                 # it seems we cannot set the default directory and  
    106                 # we still have to set this directory in order to get anything back in 
    107                 # GetPath 
    108                 $widget->SetPath(Cwd::cwd()); 
    109             } elsif ($class eq 'Wx::TextCtrl') { 
    110                 my $default = shift @params; 
    111                 $widget = $class->new( $dialog, -1, $arg, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
    112                 if (defined $default) { 
    113                     $widget->SetValue($default); 
    114                 } 
    115             } elsif ($class eq 'Wx::CheckBox') { 
    116                 my $default = shift @params; 
    117                 $widget = $class->new( $dialog, -1, $arg, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
    118                 $widget->SetValue($default); 
    119             } else { 
    120                 $widget = $class->new( $dialog, -1, $arg, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
    121             } 
    122  
    123             $row->Add($widget); 
    124  
    125             if ($name) { 
    126                 $dialog->{$name} = $widget; 
    127             } 
    128         } 
    129     } 
    130  
    131     $dialog->SetSizer($box); 
    132  
    133     return; 
    134 } 
    135  
    13684sub cancel_clicked { 
    13785    my ($dialog, $event) = @_; 
     
    14593    my ($dialog, $event) = @_; 
    14694 
    147     my $data = get_data_from( $dialog, get_layout() ); 
     95    my $data = Padre::Wx::Dialog::get_data_from( $dialog, get_layout() ); 
    14896    $dialog->Destroy; 
    14997    print Dumper $data; 
     
    181129} 
    182130 
    183 sub get_data_from { 
    184     my ( $dialog, $layout ) = @_; 
    185  
    186     my %data; 
    187     foreach my $i (0..@$layout-1) { 
    188         foreach my $j (0..@{$layout->[$i]}-1) { 
    189             next if not @{ $layout->[$i][$j] }; # [] means Expand 
    190             my ($class, $name, $arg, @params) = @{ $layout->[$i][$j] }; 
    191             if ($name) { 
    192                 next if $class eq 'Wx::Button'; 
    193  
    194                 if ($class eq 'Wx::DirPickerCtrl') { 
    195                     $data{$name} = $dialog->{$name}->GetPath; 
    196                 } else { 
    197                     $data{$name} = $dialog->{$name}->GetValue; 
    198                 } 
    199             } 
    200         } 
    201     } 
    202  
    203     return \%data; 
    204 } 
    205  
    206131 
    2071321; 
Note: See TracChangeset for help on using the changeset viewer.