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

Comparing rxvt-unicode/src/perl/macosx-clipboard (file contents):
Revision 1.1 by root, Thu Dec 7 20:59:59 2006 UTC vs.
Revision 1.8 by root, Tue Sep 4 22:41:11 2012 UTC

1#! perl -w 1#! perl -w
2
3# http://triplefusion.net/system/macosx-clipboard
4 2
5# ---------------------------------------------------------------------- 3# ----------------------------------------------------------------------
6# File: macosx-clipboard 4# File: macosx-clipboard
7# ---------------------------------------------------------------------- 5# ----------------------------------------------------------------------
8# 6#
9# All portions of code are copyright by their respective author/s. 7# All portions of code are copyright by their respective author/s.
10# Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net> 8# Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net>
9# 2009 Reza Jelveh <reza.jelveh@gmail.com>
11# 10#
12# This program is free software; you can redistribute it and/or modify 11# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by 12# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or 13# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version. 14# (at your option) any later version.
22# You should have received a copy of the GNU General Public License 21# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software 22# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25# ---------------------------------------------------------------------- 24# ----------------------------------------------------------------------
26 25
27# Usage: 26=head1 NAME
28 27
29# URxvt.perl-ext-common: macosx-clipboard 28macosx-clipboard and macosx-clipboard-native
30# URxvt.keysym.M-c: perl:macosx-clipboard:copy
31# URxvt.keysym.M-v: perl:macosx-clipboard:paste
32 29
33use Fcntl (); 30=head1 DESCRIPTION
34use Foundation;
35use locale;
36use utf8;
37 31
38our($appkit, $pasteboard); 32These two modules implement an extended clipboard for Mac OS X. They are
33used like this:
34
35 URxvt.perl-ext-common: default,macosx-clipboard
36 URxvt.keysym.M-c: perl:macosx-clipboard:copy
37 URxvt.keysym.M-v: perl:macosx-clipboard:paste
38
39The difference between them is that the native variant requires a
40perl from apple's devkit or so, and C<macosx-clipboard> requires the
41C<Mac::Pasteboard> module, works with other perls, has fewer bugs, is
42simpler etc. etc.
43
44=cut
45
46use Mac::Pasteboard;
47
48my $pasteboard = new Mac::Pasteboard;
39 49
40sub copy { 50sub copy {
41 my ($self) = @_; 51 my ($self) = @_;
42 52
43 $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); 53 $pasteboard->clear;
44 $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); 54 $pasteboard->copy ($self->selection);
55
45 () 56 ()
46} 57}
47 58
48sub paste { 59sub paste {
49 my ($self) = @_; 60 my ($self) = @_;
50 my ($type, $str);
51 61
52 $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); 62 my $str = $pasteboard->paste;
53 if ($type->isEqual_('NSStringPboardType')){
54 $str = $pasteboard->stringForType_($type)->UTF8String;
55 $str =~ tr/\n/\r/;
56 utf8::decode($str); 63 utf8::decode $str;
57 $self->tt_write($self->locale_encode($str)); 64 $self->tt_write ($self->locale_encode ($str));
58 }
59 ()
60}
61 65
62sub on_start {
63 my ($self) = @_;
64
65 $appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework');
66 $appkit->load if $appkit;
67
68 if ($appkit->isLoaded) {
69 no strict 'refs';
70 for my $class (qw(NSPasteboard)) {
71 @{$class . '::ISA'} = 'PerlObjCBridge';
72 }
73 } else {
74 undef $appkit;
75 }
76
77 $pasteboard = NSPasteboard->generalPasteboard;
78 () 66 ()
79} 67}
80 68
81sub on_user_command { 69sub on_user_command {
82 my ($self, $cmd) = @_; 70 my ($self, $cmd) = @_;
86 } 74 }
87 75
88 if ($cmd eq "macosx-clipboard:paste") { 76 if ($cmd eq "macosx-clipboard:paste") {
89 $self->paste; 77 $self->paste;
90 } 78 }
79
91 () 80 ()
92} 81}
93 82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines