ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection-popup
Revision: 1.3
Committed: Mon Jan 9 02:06:43 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.2: +3 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     sub on_start {
4     my ($self) = @_;
5    
6     $self->grab_button (3, urxvt::ControlMask);
7     }
8    
9     sub on_button_press {
10     my ($self, $event) = @_;
11    
12     if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) {
13     my $popup = $self->popup ($event)
14     or return 1;
15    
16     $popup->add_title ("Convert Selection");
17    
18     my $text = $self->selection;
19    
20     my $title = $text;
21     $title =~ s/[\x00-\x1f\x80-\x9f]/ยท/g;
22     substr $title, 40, -1, "..." if 40 < length $title;
23     $popup->add_title ($title);
24     $popup->add_separator;
25    
26     my $add_button = sub {
27     my ($title, $cb) = @_;
28    
29     $popup->add_button ($title => sub {
30     for ($text) {
31     $cb->();
32     $self->selection ($_);
33     }
34     });
35     };
36    
37     for ($text) {
38 root 1.2 $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ });
39    
40 root 1.3 urxvt::safe
41     and $add_button->("eval perl expression" => sub { $_ = eval urxvt::untaint $_ });
42    
43 root 1.1 /^(\S+):(\d+):?$/
44     and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ });
45 root 1.2
46 root 1.1 /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/
47     and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge });
48 root 1.2
49 root 1.1 /^(http|ftp|telnet|irc|news):\//
50     and $add_button->("run x-www-browser" => sub { system "x-www-browser \Q$_\E &" });
51     }
52    
53     $popup->show;
54    
55     return 1;
56     }
57    
58     ()
59     }
60