562
=head2 autocomplete_matching_char
564
The first argument needs to be a reference to the editor this method should
567
The second argument is expected to be a event reference to the event object
568
which is the reason why the method was launched.
570
This method expects a hash as the third argument. If the last key typed by the
571
user is a key in this hash, the value is automatically added and the cursor is
572
set between key and value. Both key and value are expected to be ASCII codes.
574
Usually used for brackets and text signs like:
576
$self->autocomplete_matching_char(
583
Returns 1 if something was added or 0 otherwise (if anybody cares about this).
587
sub autocomplete_matching_char {
593
my $config = Padre->ide->config;
594
my $main = Padre->ide->wx->main;
596
my $selection_exists = 0;
597
my $text = $editor->GetSelectedText;
598
if ( defined($text) && length($text) > 0 ) {
599
$selection_exists = 1;
602
my $key = $event->GetUnicodeKey;
604
my $pos = $editor->GetCurrentPos;
605
my $line = $editor->LineFromPosition($pos);
606
my $first = $editor->PositionFromLine($line);
607
my $last = $editor->PositionFromLine( $line + 1 ) - 1;
609
if ( $config->autocomplete_brackets ) {
610
if ( $table{$key} ) {
611
if ($selection_exists) {
612
my $start = $editor->GetSelectionStart;
613
my $end = $editor->GetSelectionEnd;
614
$editor->GotoPos($end);
615
$editor->AddText( chr( $table{$key} ) );
616
$editor->GotoPos($start);
619
if ( $editor->GetTextLength > $pos ) {
620
$nextChar = $editor->GetTextRange( $pos, $pos + 1 );
622
unless ( defined($nextChar) && ord($nextChar) == $table{$key}
623
and ( !$config->autocomplete_multiclosebracket ) )
625
$editor->AddText( chr( $table{$key} ) );
560
639
sub _set_filename {
561
640
my $self = shift;
562
641
my $filename = shift;
575
654
$self->{filename} = $self->{file}->{filename};
657
# Only a dummy for documents which don't support this
580
668
$self->set_errstr('');
670
my $config = Padre->ide->config;
672
$self->autoclean if $config->save_autoclean;
582
674
my $content = $self->text_get;
583
675
my $file = $self->file;
584
676
if ( !defined($file) ) {