Changeset 5422


Ignore:
Timestamp:
06/20/09 21:41:35 (3 years ago)
Author:
azawawi
Message:

[Ecliptic] Ctrl-~ Quick Fix is now more generic and can be used by other plugins.

Location:
trunk/Padre-Plugin-Ecliptic/lib/Padre/Plugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre-Plugin-Ecliptic/lib/Padre/Plugin/Ecliptic.pm

    r5207 r5422  
    1313# is a subclass of Padre::Plugin 
    1414use base 'Padre::Plugin'; 
     15 
     16 
     17# accessors 
     18use Class::XSAccessor accessors => { 
     19    quick_fix_items  => 'quick_fix_items',  # Public Quick fix items 
     20}; 
     21 
    1522 
    1623# 
     
    236243    my $self = shift; 
    237244 
     245    if(not defined $self->quick_fix_items) { 
     246        my @empty_list = (); 
     247        $self->quick_fix_items(\@empty_list); 
     248 
     249        my @items = (  
     250            { 
     251                text     => '123...',  
     252                listener => sub {  
     253                    print "123...\n"; 
     254                }  
     255            }, 
     256            { 
     257                text     => '456...',  
     258                listener => sub {  
     259                    print "456...\n"; 
     260                }  
     261            }, 
     262        ); 
     263 
     264        push @{$self->quick_fix_items}, @items; 
     265 
     266    } 
     267     
    238268    #Create and show the dialog 
    239269    require Padre::Plugin::Ecliptic::QuickFixDialog; 
  • trunk/Padre-Plugin-Ecliptic/lib/Padre/Plugin/Ecliptic/QuickFixDialog.pm

    r5207 r5422  
    1919    _sizer             => '_sizer',              # window sizer 
    2020    _list              => '_list',               # key bindings list 
     21    _listeners         => '_listeners',          # hash of quick fix listener 
    2122}; 
    2223 
     
    106107    }); 
    107108 
     109    Wx::Event::EVT_LIST_ITEM_ACTIVATED( $self, $self->_list, sub { 
     110 
     111        my $selection = $self->_list->GetFirstSelected; 
     112        if($selection != -1) { 
     113            my $listener = $self->_listeners->{$selection}; 
     114            if($listener) { 
     115                &{$listener}(); 
     116            } 
     117        } 
     118        return; 
     119    }); 
     120     
    108121} 
    109122 
     
    132145    $self->_list->SetColumnWidth( 0, $list_width - 5 ); 
    133146     
    134     my $item; 
     147    # add list items from callbacks 
     148    my %listeners = (); 
     149    my $item_count = 0; 
     150    foreach my $item (@{ $self->_plugin->quick_fix_items }) { 
     151        # add the list item 
     152        $self->_list->InsertStringItem($item_count, $item->{text}); 
    135153 
    136     $item = Wx::ListItem->new(); 
    137     $item->SetText("Inline variable..."); 
    138     $self->_list->InsertItem($item); 
     154        # and register its action 
     155        $listeners{$item_count} = $item->{listener};  
     156 
     157        #next item... 
     158        $item_count++; 
     159    } 
     160    $self->_listeners(\%listeners); 
     161 
     162    #XXX- any empty quick fix must display "No suggestions" like Eclipse 
    139163     
    140     $item = Wx::ListItem->new(); 
    141     $item->SetText("Toggle Comment..."); 
    142     $self->_list->InsertItem($item); 
    143      
    144     if($self->_list->GetItemCount()) { 
     164    if($item_count) { 
    145165        $self->_list->Select(0, 1); 
    146166    } 
Note: See TracChangeset for help on using the changeset viewer.