Changeset 6885


Ignore:
Timestamp:
08/04/09 14:13:49 (3 years ago)
Author:
Sewi
Message:

50% fix for ticket #390: Copy&Paste error

File:
1 edited

Legend:

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

    r6799 r6885  
    3434my $data_private; 
    3535my $width; 
     36my $Clipboard_Old; 
    3637 
    3738sub new { 
     
    6364    Wx::Event::EVT_CHAR( $self, \&on_char ); 
    6465    Wx::Event::EVT_SET_FOCUS( $self, \&on_focus ); 
     66    Wx::Event::EVT_MIDDLE_UP($self, \&on_middle_up ); 
    6567 
    6668    # Smart highlighting... 
     
    728730 
    729731        # Only on X11 based platforms 
    730         Wx::wxTheClipboard->UsePrimarySelection(1); 
     732#       Wx::wxTheClipboard->UsePrimarySelection(1); 
    731733        $self->put_text_to_clipboard($text); 
    732         Wx::wxTheClipboard->UsePrimarySelection(0); 
     734#       Wx::wxTheClipboard->UsePrimarySelection(0); 
    733735    } 
    734736 
     
    736738    if ( $doc->can('event_on_left_up') ) { 
    737739        $doc->event_on_left_up( $self, $event ); 
     740    } 
     741 
     742    $event->Skip; 
     743    return; 
     744} 
     745 
     746sub on_middle_up { 
     747    my ( $self, $event ) = @_; 
     748 
     749    # TODO: Sometimes there are unexpected effects when using the middle button. 
     750    # It seems that another event is doing something but not within this module. 
     751    # Please look at ticket #390 for details! 
     752 
     753    Padre::Current->editor->Paste; 
     754 
     755    my $doc = $self->{Document}; 
     756    if ( $doc->can('event_on_middle_up') ) { 
     757        $doc->event_on_middle_up( $self, $event ); 
    738758    } 
    739759 
     
    10401060} 
    10411061 
     1062sub Paste { 
     1063    my $self = shift; 
     1064 
     1065    # Workaround for Copy/Paste bug ticket #390 
     1066    my $text = $self->get_text_from_clipboard; 
     1067    $self->ReplaceSelection($text); 
     1068 
     1069    return 1; 
     1070} 
     1071 
    10421072sub put_text_to_clipboard { 
    10431073    my ( $self, $text ) = @_; 
    10441074    @_ = (); # Feeble attempt to kill Scalars Leaked 
    10451075 
     1076        # Backup last clipboard value: 
     1077        $self->{Clipboard_Old} = $self->get_text_from_clipboard 
     1078         if $self->{Clipboard_Old} ne $self->get_text_from_clipboard; 
     1079 
    10461080    Wx::wxTheClipboard->Open; 
    10471081    Wx::wxTheClipboard->SetData( Wx::TextDataObject->new($text) ); 
     
    10531087sub get_text_from_clipboard { 
    10541088 
    1055     # This is to be used as a method even if we don't use $self! 
    1056     # my $self = shift; 
     1089    my $self = shift; 
     1090 
    10571091    my $text = ''; 
    10581092    Wx::wxTheClipboard->Open; 
     
    10601094        my $data = Wx::TextDataObject->new; 
    10611095        if ( Wx::wxTheClipboard->GetData($data) ) { 
    1062             $text = $data->GetText; 
    1063         } 
    1064     } 
     1096            $text = $data->GetText if defined($data); 
     1097        } 
     1098    } 
     1099    if ($text eq $self->GetSelectedText) { 
     1100        $text = $self->{Clipboard_Old}; 
     1101    } 
     1102 
    10651103    Wx::wxTheClipboard->Close; 
    10661104    return $text; 
Note: See TracChangeset for help on using the changeset viewer.