Ticket #230: toggle_comment.diff

File toggle_comment.diff, 2.6 KB (added by claudio, 5 years ago)

Svn diff patch implementing toggle comment

  • Padre/lib/Padre/Wx/Main.pm

     
    897897    return; 
    898898} 
    899899 
     900sub on_comment_toggle_block { 
     901        my $self     = shift; 
     902        my $current  = $self->current; 
     903        my $editor   = $current->editor; 
     904        my $document = $current->document; 
     905        my $begin    = $editor->LineFromPosition($editor->GetSelectionStart); 
     906        my $end      = $editor->LineFromPosition($editor->GetSelectionEnd); 
     907        my $string   = $document->comment_lines_str; 
     908        return unless defined $string; 
     909    $editor->comment_toggle_lines($begin, $end, $string); 
     910        return; 
     911} 
     912 
    900913sub on_comment_out_block { 
    901914    my $self     = shift; 
    902915    my $current  = $self->current; 
  • Padre/lib/Padre/Wx/Editor.pm

     
    642642    } 
    643643 
    644644    $menu->AppendSeparator; 
    645  
     645     
     646    my $commentToggle = $menu->Append( -1, Wx::gettext("&Toggle Comment\tCtrl-Shift-C") ); 
     647        Wx::Event::EVT_MENU( $main, $commentToggle, 
     648                \&Padre::Wx::Main::on_comment_toggle_block, 
     649        ); 
    646650    my $comment = $menu->Append( -1, Wx::gettext("&Comment Selected Lines\tCtrl-M") ); 
    647651    Wx::Event::EVT_MENU( $main, $comment, 
    648652        \&Padre::Wx::Main::on_comment_out_block, 
     
    837841    return $text; 
    838842} 
    839843 
     844# Coment or comment text depending on the first selected line. 
     845# This is the most coherent way to handle mixed blocks(commented and 
     846# uncommented lines). 
     847sub comment_toggle_lines { 
     848    my ($self, $begin, $end, $str) = @_; 
     849    if ( _get_line_by_number($self, $begin) =~ /\s*$str/ ) { 
     850        uncomment_lines(@_); 
     851    } else { 
     852        comment_lines(@_); 
     853        }    
     854} 
     855 
    840856# $editor->comment_lines($begin, $end, $str); 
    841857# $str is either # for perl or // for Javascript, etc. 
    842858# $str might be ['<--', '-->] for html 
  • Padre/lib/Padre/Wx/Menu/Edit.pm

     
    194194 
    195195 
    196196    # Commenting 
     197    $self->{comment_toggle} = $self->Append( -1, 
     198                Wx::gettext("&Toggle Comment\tCtrl-Shift-C") 
     199        ); 
     200        Wx::Event::EVT_MENU( $main, 
     201                $self->{comment_toggle}, 
     202                \&Padre::Wx::Main::on_comment_toggle_block, 
     203        ); 
     204 
    197205    $self->{comment_out} = $self->Append( -1, 
    198206        Wx::gettext("&Comment Selected Lines\tCtrl-M") 
    199207    );