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

File Contents

# Content
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 $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ });
39
40 /^(\S+):(\d+):?$/
41 and $add_button->("vi-commands to load '$1'" => sub { s/^(\S+):(\d+):?$/\x1b:e $1\x0d:$2\x0d/ });
42
43 /%[0-9a-fA-F]{2}/ && !/%[^0-9a-fA-F]/ && !/%.[^0-9a-fA-F]/
44 and $add_button->("uri unescape" => sub { s/%([0-9a-fA-F]{2})/chr hex $1/ge });
45
46 /^(http|ftp|telnet|irc|news):\//
47 and $add_button->("run x-www-browser" => sub { system "x-www-browser \Q$_\E &" });
48 }
49
50 $popup->show;
51
52 return 1;
53 }
54
55 ()
56 }
57