Changeset 510


Ignore:
Timestamp:
10/26/08 09:48:58 (3 years ago)
Author:
szabgab
Message:

replace the Preferences dialog with one that uses the common
dialog infrastructure

Location:
trunk/lib/Padre/Wx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Padre/Wx/Dialog.pm

    r509 r510  
    2626    $top_left_offset = [0, 0] if not ref($top_left_offset); 
    2727 
     28    # TODO make sure width has enough elements to the widest row 
     29    # or maybe we should also check that all the rows has the same number of elements 
    2830    my $box  = Wx::BoxSizer->new( Wx::wxVERTICAL ); 
    2931    # Add Y-offset 
     
    6365                $widget = $class->new( $dialog, -1, $arg, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
    6466                $widget->SetValue($default); 
     67            } elsif ($class eq 'Wx::StaticText') { 
     68                $widget = $class->new( $dialog, -1, $arg, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
     69            } elsif ($class eq 'Wx::ComboBox') { 
     70                $widget = $class->new( $dialog, -1, $arg, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
     71            } elsif ($class eq 'Wx::Choice') { 
     72                $widget = $class->new( $dialog, -1, Wx::wxDefaultPosition, [$width->[$j], -1], $arg, @params ); 
    6573            } else { 
    66                 $widget = $class->new( $dialog, -1, $arg, Wx::wxDefaultPosition, [$width->[$j], -1], @params ); 
     74                warn "Unsupported widget $class\n"; 
     75                return; 
    6776            } 
    6877 
     
    93102                if ($class eq 'Wx::DirPickerCtrl') { 
    94103                    $data{$name} = $dialog->{$name}->GetPath; 
     104                } elsif ($class eq 'Wx::Choice') { 
     105                    $data{$name} = $dialog->{$name}->GetSelection; 
    95106                } else { 
    96107                    $data{$name} = $dialog->{$name}->GetValue; 
  • trunk/lib/Padre/Wx/ModuleStartDialog.pm

    r509 r510  
    7878            [ 'Wx::Button',     '_ok_',           Wx::wxID_OK     ], 
    7979            [ 'Wx::Button',     '_cancel_',       Wx::wxID_CANCEL ], 
    80         ] 
     80        ], 
    8181    ); 
    8282    return \@layout; 
  • trunk/lib/Padre/Wx/Preferences.pm

    r468 r510  
    55use warnings; 
    66 
    7 use Padre::Wx  (); 
     7use Padre::Wx         (); 
     8use Padre::Wx::Dialog (); 
    89 
    910our $VERSION = '0.12'; 
     11 
     12sub get_layout { 
     13    my ($config, $values) = @_; 
     14 
     15    return [ 
     16        [ 
     17            [ 'Wx::StaticText', undef,              'TAB display size (in spaces)'], 
     18            [ 'Wx::TextCtrl',   'editor_tabwidth',  $config->{editor_tabwidth}], 
     19        ], 
     20        [ 
     21            [ 'Wx::StaticText', undef,              'Max number of modules'], 
     22            [ 'Wx::TextCtrl',   'pod_maxlist',      $config->{pod_maxlist}], 
     23        ], 
     24        [ 
     25            [ 'Wx::StaticText', undef,              'Min number of modules'], 
     26            [ 'Wx::TextCtrl',   'pod_minlist',       $config->{pod_minlist}], 
     27        ], 
     28        [ 
     29            [ 'Wx::StaticText', undef,              'Open files:'], 
     30            [ 'Wx::Choice',     'choice',    $values], 
     31        ], 
     32        [ 
     33            [ 'Wx::Button',     '_ok_',           Wx::wxID_OK     ], 
     34            [ 'Wx::Button',     '_cancel_',       Wx::wxID_CANCEL ], 
     35        ], 
     36    ]; 
     37} 
    1038 
    1139sub run { 
    1240    my ( $class, $win, $config ) = @_; 
    1341 
    14     my $dialog = Wx::Dialog->new( $win, -1, "Preferences", [-1, -1], [550, 200], Wx::wxDEFAULT_FRAME_STYLE); 
    15  
    16     my $y = 10; 
    17     my $HEIGHT = 30; 
    18  
    19     Wx::StaticText->new( $dialog, -1, 'TAB display size (in spaces)', [10, $y], [-1, -1]); 
    20     my $tabwidth = Wx::TextCtrl->new( 
    21         $dialog, 
    22         -1, 
    23         $config->{editor_tabwidth}, 
    24         [ 300, $y ], 
    25         [ -1, -1 ], 
    26     ); 
    27     $tabwidth->SetFocus; 
    28  
    29     $y += $HEIGHT; 
    30     Wx::StaticText->new( $dialog, -1, 'Max number of modules', [10, $y], [-1, -1]); 
    31     my $max = Wx::TextCtrl->new( $dialog, -1, $config->{pod_maxlist}, [300, $y] , [-1, -1]); 
    32  
    33     $y += $HEIGHT; 
    34     Wx::StaticText->new( $dialog, -1, 'Min number of modules', [10, $y], [-1, -1]); 
    35     my $min = Wx::TextCtrl->new( $dialog, -1, $config->{pod_minlist}, [300, $y] , [-1, -1]); 
    36  
    37     $y += $HEIGHT; 
    38     Wx::StaticText->new( $dialog, -1, 'Open files:', [10, $y], [-1, -1]); 
    3942    my @values = ( 
    4043        $config->{main_startup}, 
    4144        grep { $_ ne $config->{main_startup} } qw( new nothing last ) 
    4245    ); 
    43     my $choice = Wx::Choice->new( $dialog, -1, [300, $y], [-1, -1], \@values ); 
    4446 
    45     $y += $HEIGHT; 
    46     my $ok     = Wx::Button->new( $dialog, Wx::wxID_OK,     '', [10,  $y] ); 
    47     my $cancel = Wx::Button->new( $dialog, Wx::wxID_CANCEL, '', [120, $y], $ok->GetSize ); 
    48     Wx::Event::EVT_BUTTON( $dialog, $ok,     sub { $dialog->EndModal(Wx::wxID_OK) } ); 
    49     Wx::Event::EVT_BUTTON( $dialog, $cancel, sub { $dialog->EndModal(Wx::wxID_CANCEL) } ); 
    50     $ok->SetDefault; 
     47    my $dialog = Wx::Dialog->new( $win, -1, "Preferences", [-1, -1], [550, 200], Wx::wxDEFAULT_FRAME_STYLE); 
     48 
     49    my $layout = get_layout($config, \@values); 
     50    Padre::Wx::Dialog::build_layout($dialog, $layout, [250, 200]); 
     51    $dialog->{editor_tabwidth}->SetFocus; 
     52    Wx::Event::EVT_BUTTON( $dialog, $dialog->{_ok_},     sub { $dialog->EndModal(Wx::wxID_OK) } ); 
     53    Wx::Event::EVT_BUTTON( $dialog, $dialog->{_cancel_}, sub { $dialog->EndModal(Wx::wxID_CANCEL) } ); 
     54 
     55    $dialog->{_ok_}->SetDefault; 
    5156    if ($dialog->ShowModal == Wx::wxID_CANCEL) { 
    5257        return; 
    5358    } 
    54     $config->{pod_maxlist}     = $max->GetValue; 
    55     $config->{pod_minlist}     = $min->GetValue; 
    56     $config->{editor_tabwidth} = $tabwidth->GetValue; 
    57     $config->{main_startup}    = $values[ $choice->GetSelection ]; 
     59 
     60    my $data = Padre::Wx::Dialog::get_data_from( $dialog, get_layout() ); 
     61 
     62    $config->{pod_maxlist}     = $data->{pod_maxlist}; 
     63    $config->{pod_minlist}     = $data->{pod_minlist}; 
     64    $config->{editor_tabwidth} = $data->{editor_tabwidth}; 
     65    $config->{main_startup}    = $values[ $data->{choice} ]; 
    5866 
    5967    return; 
Note: See TracChangeset for help on using the changeset viewer.