Changeset 470


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

move the methods returning a single document to the Padre::Documents class

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MANIFEST

    r452 r470  
    1010lib/Padre/DB.pm 
    1111lib/Padre/Document.pm 
     12lib/Padre/Documents.pm 
    1213lib/Padre/PluginManager.pm 
    1314lib/Padre/Project.pm 
  • trunk/lib/Padre/Document.pm

    r456 r470  
    147147our $DEFAULT_LEXER = wxSTC_LEX_AUTOMATIC; 
    148148 
    149 ### DODGY HACK 
    150 # This is a temporary method that can generate an "anonymous" 
    151 # document for whatever is in the current buffer. The document 
    152 # is not saved or cached anywhere. 
    153 # This method may be changed to work properly later, but for now 
    154 # feel free to use it wherever needed. 
    155 sub from_selection { 
    156     $_[0]->from_pageid( $_[0]->notebook->GetSelection ); 
    157 } 
    158  
    159 sub from_pageid { 
    160     my $class   = shift; 
    161     my $pageid  = shift; 
    162  
    163     # TODO maybe report some error? 
    164     return if not defined $pageid or $pageid =~ /\D/; 
    165  
    166     if ( $pageid == -1 ) { 
    167         # No page selected 
    168         return; 
    169     } 
    170  
    171     return if $pageid >= $class->notebook->GetPageCount; 
    172  
    173     my $page = $class->notebook->GetPage( $pageid ); 
    174  
    175     return $page->{Document}; 
    176 } 
    177  
    178  
    179  
    180  
    181  
    182 ##################################################################### 
    183 # Class Methods 
    184  
    185 sub notebook { 
    186     Padre->ide->wx->main_window->{notebook}; 
    187 } 
    188  
    189  
    190  
    191149 
    192150 
  • trunk/lib/Padre/Wx/MainWindow.pm

    r469 r470  
    1919use Padre::Wx::ToolBar (); 
    2020use Padre::Wx::Output  (); 
     21use Padre::Documents   (); 
    2122 
    2223use base qw{Wx::Frame}; 
     
    341342 
    342343sub selected_document { 
    343     Padre::Document->from_selection; 
     344    Padre::Documents->from_selection; 
    344345} 
    345346 
     
    850851    # and it is unused, close it. 
    851852    if ( $self->{notebook}->GetPageCount == 1 ) { 
    852         if ( Padre::Document->from_selection->is_unused ) { 
     853        if ( Padre::Documents->from_selection->is_unused ) { 
    853854            $self->on_close; 
    854855        } 
     
    935936    my $self = shift; 
    936937    foreach my $id ( $self->pageids ) { 
    937         my $doc = Padre::Document->from_pageid($id); 
     938        my $doc = Padre::Documents->from_pageid($id); 
    938939        $self->on_save( $doc ) or return 0; 
    939940    } 
     
    12441245 
    12451246sub _DOCUMENT { 
    1246     return (defined $_[0]) ? Padre::Document->from_pageid($_[0]) : Padre::Document->from_selection; 
     1247    return (defined $_[0]) ? Padre::Documents->from_pageid($_[0]) : Padre::Documents->from_selection; 
    12471248} 
    12481249 
  • trunk/lib/Padre/Wx/Menu.pm

    r469 r470  
    66use Params::Util qw{_INSTANCE}; 
    77 
    8 use Padre::Wx    (); 
    9 use Padre::Util  (); 
     8use Padre::Wx        (); 
     9use Padre::Util      (); 
     10use Padre::Documents (); 
    1011 
    1112our $VERSION = '0.12'; 
     
    99100            sub {  
    100101                if ( $_[ 0 ]->{notebook}->GetPageCount == 1 ) { 
    101                     if ( Padre::Document->from_selection->is_unused ) { 
     102                    if ( Padre::Documents->from_selection->is_unused ) { 
    102103                        $_[0]->on_close; 
    103104                    } 
     
    138139        $menu->{edit}->Append( Wx::wxID_UNDO, '' ), 
    139140        sub { 
    140             my $page = Padre::Document->from_selection->editor; 
     141            my $page = Padre::Documents->from_selection->editor; 
    141142            if ( $page->CanUndo ) { 
    142143                $page->Undo; 
     
    148149        $menu->{edit}->Append( Wx::wxID_REDO, '' ), 
    149150        sub { 
    150             my $page = Padre::Document->from_selection->editor; 
     151            my $page = Padre::Documents->from_selection->editor; 
    151152            if ( $page->CanRedo ) { 
    152153                $page->Redo; 
     
    277278        $menu->{perl_find_unmatched}, 
    278279        sub { 
    279             my $doc = Padre::Document->from_selection; 
     280            my $doc = Padre::Documents->from_selection; 
    280281            unless ( $doc and $doc->isa('Padre::Document::Perl') ) { 
    281282                return; 
     
    437438            sub { 
    438439                $DB::single = 1; 
    439                 my $document = Padre::Document->from_selection; 
     440                my $document = Padre::Documents->from_selection; 
    440441                $_[0]->{menu}->refresh( $document ); 
    441442                $_[0]->SetMenuBar( $_[0]->{menu}->{wx} ); 
     
    449450            sub { 
    450451                my $self = shift; 
    451                 my $code = Padre::Document->from_selection->text_get; 
     452                my $code = Padre::Documents->from_selection->text_get; 
    452453                eval $code; 
    453454                if ($@) { 
Note: See TracChangeset for help on using the changeset viewer.