Changeset 853
- Timestamp:
- 11/09/08 11:34:40 (3 years ago)
- Location:
- trunk/lib/Padre/Wx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Padre/Wx/Editor.pm
r781 r853 8 8 9 9 use Padre::Documents (); 10 use Wx qw(:dnd wxTheClipboard); 11 use Wx::DND; 10 12 use Wx::STC; 11 13 use Padre::Wx; … … 303 305 ); 304 306 $menu->AppendSeparator; 305 306 307 308 my $selection_exists = 0; 309 my $id = $win->{notebook}->GetSelection; 310 if ( $id != -1 ) { 311 my $txt = $win->{notebook}->GetPage($id)->GetSelectedText; 312 if ( defined($txt) && length($txt) > 0 ) { 313 $selection_exists = 1; 314 } 315 } 316 317 my $sel_all = $menu->Append( Wx::wxID_SELECTALL, gettext("Select all\tCtrl-A") ); 318 if ( not $win->{notebook}->GetPage($id)->GetTextLength > 0 ) { 319 $sel_all->Enable(0); 320 } 321 Wx::Event::EVT_MENU( $win, # Ctrl-A 322 $sel_all, 323 sub { \&text_select_all(@_) }, 324 ); 325 $menu->AppendSeparator; 326 327 my $copy = $menu->Append( Wx::wxID_COPY, '' ); 328 if ( not $selection_exists ) { 329 $copy->Enable(0); 330 } 331 Wx::Event::EVT_MENU( $win, # Ctrl-C 332 $copy, 333 sub { \&text_copy_to_clipboard(@_) }, 334 ); 335 336 my $cut = $menu->Append( Wx::wxID_CUT, '' ); 337 if ( not $selection_exists ) { 338 $cut->Enable(0); 339 } 340 Wx::Event::EVT_MENU( $win, # Ctrl-X 341 $cut, 342 sub { \&text_cut_to_clipboard(@_) }, 343 ); 344 345 my $paste = $menu->Append( Wx::wxID_PASTE, '' ); 346 wxTheClipboard->Open; 347 if ( wxTheClipboard->IsSupported(wxDF_TEXT) ) { 348 my $data = Wx::TextDataObject->new; 349 my $ok = wxTheClipboard->GetData($data); 350 if ( $ok && $data->GetTextLength > 0 && $win->{notebook}->GetPage($id)->CanPaste ) { 351 Wx::Event::EVT_MENU( $win, # Ctrl-V 352 $paste, 353 sub { \&text_paste_from_clipboard(@_) }, 354 ); 355 } 356 else { 357 $paste->Enable(0); 358 } 359 } 360 wxTheClipboard->Close; 361 362 $menu->AppendSeparator; 363 307 364 # $menu->Append( Wx::wxID_NEW, '' ); 308 365 Wx::Event::EVT_MENU( $win, … … 327 384 } 328 385 386 sub text_select_all { 387 my ( $win, $event ) = @_; 388 389 my $id = $win->{notebook}->GetSelection; 390 return if $id == -1; 391 $win->{notebook}->GetPage($id)->SelectAll; 392 return; 393 } 394 395 sub text_copy_to_clipboard { 396 my ( $win, $event ) = @_; 397 398 my $id = $win->{notebook}->GetSelection; 399 return if $id == -1; 400 wxTheClipboard->Open; 401 402 my $txt = $win->{notebook}->GetPage($id)->GetSelectedText; 403 if ( defined($txt) ) { 404 wxTheClipboard->SetData( Wx::TextDataObject->new($txt) ); 405 } 406 407 wxTheClipboard->Close; 408 return; 409 } 410 411 sub text_cut_to_clipboard { 412 my ( $win, $event ) = @_; 413 414 my $id = $win->{notebook}->GetSelection; 415 return if $id == -1; 416 wxTheClipboard->Open; 417 418 my $txt = $win->{notebook}->GetPage($id)->GetSelectedText; 419 if ( defined($txt) ) { 420 wxTheClipboard->SetData( Wx::TextDataObject->new($txt) ); 421 $win->{notebook}->GetPage($id)->ReplaceSelection(''); 422 } 423 424 wxTheClipboard->Close; 425 return; 426 } 427 428 sub text_paste_from_clipboard { 429 my ( $win, $event ) = @_; 430 431 my $id = $win->{notebook}->GetSelection; 432 return if $id == -1; 433 434 wxTheClipboard->Open; 435 my $text = ''; 436 my $length = 0; 437 if ( wxTheClipboard->IsSupported(wxDF_TEXT) ) { 438 my $data = Wx::TextDataObject->new; 439 my $ok = wxTheClipboard->GetData($data); 440 if ($ok) { 441 $text = $data->GetText; 442 $length = $data->GetTextLength; 443 } 444 else { 445 $text = ''; 446 $length = 1; 447 } 448 } 449 my $pos = $win->{notebook}->GetPage($id)->GetCurrentPos; 450 $win->{notebook}->GetPage($id)->InsertText( $pos, $text ); 451 $win->{notebook}->GetPage($id)->GotoPos( $pos + $length - 1 ); 452 453 wxTheClipboard->Close; 454 return; 455 } 456 329 457 1; 330 458 -
trunk/lib/Padre/Wx/Menu.pm
r848 r853 170 170 ); 171 171 $menu->{edit}->AppendSeparator; 172 173 Wx::Event::EVT_MENU( $win, 174 $menu->{edit}->Append( Wx::wxID_SELECTALL, gettext("Select all\tCtrl-A") ), 175 sub { \&Padre::Wx::Editor::text_select_all(@_) }, 176 ); 177 Wx::Event::EVT_MENU( $win, 178 $menu->{edit}->Append( Wx::wxID_COPY, '' ), 179 sub { \&Padre::Wx::Editor::text_copy_to_clipboard(@_) }, 180 ); 181 Wx::Event::EVT_MENU( $win, 182 $menu->{edit}->Append( Wx::wxID_CUT, '' ), 183 sub { \&Padre::Wx::Editor::text_cut_to_clipboard(@_) }, 184 ); 185 Wx::Event::EVT_MENU( $win, 186 $menu->{edit}->Append( Wx::wxID_PASTE, '' ), 187 sub { \&Padre::Wx::Editor::text_paste_from_clipboard(@_) }, 188 ); 189 $menu->{edit}->AppendSeparator; 172 190 173 191 # Random shit that doesn't fit anywhere better yet -
trunk/lib/Padre/Wx/ToolBar.pm
r823 r853 5 5 use warnings; 6 6 7 use Wx qw(:dnd wxTheClipboard);8 use Wx::DND;9 7 use Padre::Wx (); 8 use Padre::Wx::Editor (); 10 9 use Wx::Locale qw(:default); 11 10 use File::Spec::Functions qw(catfile); … … 51 50 $self->AddTool( Wx::wxID_PASTE, '', Padre::Wx::tango( catfile( 'actions', 'edit-paste.png' ) ), gettext('Paste') ); 52 51 53 Wx::Event::EVT_TOOL( 54 $parent, 55 Wx::wxID_SELECTALL, 56 sub { 57 my $win = shift; 58 my $evt = shift; 59 60 my $id = $win->{notebook}->GetSelection; 61 return if $id == -1; 62 $win->{notebook}->GetPage($id)->SelectAll; 63 return; 64 } 65 ); 66 67 Wx::Event::EVT_TOOL( 68 $parent, 69 Wx::wxID_COPY, 70 sub { 71 my $win = shift; 72 my $evt = shift; 73 74 my $id = $win->{notebook}->GetSelection; 75 return if $id == -1; 76 wxTheClipboard->Open; 77 78 my $txt = $win->{notebook}->GetPage($id)->GetSelectedText; 79 if ( defined($txt) ) { 80 wxTheClipboard->SetData( Wx::TextDataObject->new($txt) ); 81 } 82 83 wxTheClipboard->Close; 84 return; 85 }, 86 ); 87 Wx::Event::EVT_TOOL( 88 $parent, 89 Wx::wxID_CUT, 90 sub { 91 my $win = shift; 92 my $evt = shift; 93 94 my $id = $win->{notebook}->GetSelection; 95 return if $id == -1; 96 wxTheClipboard->Open; 97 98 my $txt = $win->{notebook}->GetPage($id)->GetSelectedText; 99 if ( defined($txt) ) { 100 wxTheClipboard->SetData( Wx::TextDataObject->new($txt) ); 101 $win->{notebook}->GetPage($id)->ReplaceSelection(''); 102 } 103 104 wxTheClipboard->Close; 105 return; 106 }, 107 ); 108 Wx::Event::EVT_TOOL( 109 $parent, 110 Wx::wxID_PASTE, 111 sub { 112 my $win = shift; 113 my $evt = shift; 114 my $id = $win->{notebook}->GetSelection; 115 return if $id == -1; 116 wxTheClipboard->Open; 117 my $text = ''; 118 my $length = 0; 119 if ( wxTheClipboard->IsSupported(wxDF_TEXT) ) { 120 my $data = Wx::TextDataObject->new; 121 my $ok = wxTheClipboard->GetData($data); 122 if ($ok) { 123 $text = $data->GetText; 124 $length = $data->GetTextLength; 125 } 126 else { 127 $text = ''; 128 $length = 1; 129 } 130 } 131 my $pos = $win->{notebook}->GetPage($id)->GetCurrentPos; 132 $win->{notebook}->GetPage($id)->InsertText( $pos, $text ); 133 $win->{notebook}->GetPage($id)->GotoPos( $pos + $length - 1 ); 134 wxTheClipboard->Close; 135 return; 136 }, 137 ); 52 Wx::Event::EVT_TOOL( $parent, Wx::wxID_SELECTALL, sub { \&Padre::Wx::Editor::text_select_all(@_) } ); 53 Wx::Event::EVT_TOOL( $parent, Wx::wxID_COPY, sub { \&Padre::Wx::Editor::text_copy_to_clipboard(@_) } ); 54 Wx::Event::EVT_TOOL( $parent, Wx::wxID_CUT, sub { \&Padre::Wx::Editor::text_cut_to_clipboard(@_) } ); 55 Wx::Event::EVT_TOOL( $parent, Wx::wxID_PASTE, sub { \&Padre::Wx::Editor::text_paste_from_clipboard(@_) } ); 138 56 139 57 return $self;
Note: See TracChangeset
for help on using the changeset viewer.
