ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection-popup
(Generate patch)

Comparing rxvt-unicode/src/perl/selection-popup (file contents):
Revision 1.26 by root, Sun Jun 10 17:31:53 2012 UTC vs.
Revision 1.30 by sf-exg, Fri May 23 20:51:15 2014 UTC

1#! perl 1#! perl
2 2
3#:META:X_RESOURCE:url-launcher:string:shell command to use 3#:META:RESOURCE:url-launcher:string:shell command to use
4 4
5=head1 NAME 5=head1 NAME
6 6
7 selection-popup (enabled by default) 7selection-popup (enabled by default)
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11Binds a popup menu to Ctrl-Button3 that lets you convert the selection 11Binds a popup menu to Ctrl-Button3 that lets you paste the X
12text into various other formats/action (such as uri unescaping, perl 12selections and either modify or use the internal selection text in
13various ways (such as uri unescaping, perl evaluation, web-browser
13evaluation, web-browser starting etc.), depending on content. 14starting etc.), depending on content.
14 15
15Other extensions can extend this popup menu by pushing a code reference 16Other extensions can extend this popup menu by pushing a code reference
16onto C<@{ $term->{selection_popup_hook} }>, which gets called whenever the 17onto C<< @{ $term->{selection_popup_hook} } >>, which gets called whenever
17popup is being displayed. 18the popup is being displayed.
18 19
19Its sole argument is the popup menu, which can be modified. The selection 20Its sole argument is the popup menu, which can be modified. The selection
20is in C<$_>, which can be used to decide whether to add something or not. 21is in C<$_>, which can be used to decide whether to add something or not.
21It should either return nothing or a string and a code reference. The 22It should either return nothing or a string and a code reference. The
22string will be used as button text and the code reference will be called 23string will be used as button text and the code reference will be called
59 60
60 if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) { 61 if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) {
61 my $popup = $self->popup ($event) 62 my $popup = $self->popup ($event)
62 or return 1; 63 or return 1;
63 64
64 $popup->add_title ("Convert Selection"); 65 $popup->add_title ("Selection");
65 66
66 my $text = $self->selection; 67 my $text = $self->selection;
67 68
68 my $title = $text; 69 my $title = $text;
69 $title =~ s/[\x00-\x1f\x80-\x9f]/·/g; 70 $title =~ s/[\x00-\x1f\x80-\x9f]/·/g;
88 }); 89 });
89 }; 90 };
90 91
91 for ($text) { 92 for ($text) {
92 /\n/ 93 /\n/
94 and $add_button->("paste primary selection" => sub { $self->selection_request (urxvt::CurrentTime, 1) });
95
96 /./
97 and $add_button->("paste clipboard selection" => sub { $self->selection_request (urxvt::CurrentTime, 3) });
98
99 /./
100 and $add_button->("copy selection to clipboard" => sub { $self->selection ($self->selection, 1);
101 $self->selection_grab (urxvt::CurrentTime, 1) });
102
103 /./
93 and $add_button->("newlines to spaces" => sub { y/\n/ / }); 104 and $add_button->("newlines to spaces" => sub { y/\n/ / });
94 105
95 /./ 106 /./
96 and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); 107 and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ });
97 108

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines