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.2 by ayin, Mon Nov 12 14:41:42 2007 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:
39 34
40$appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); 35 URxvt.perl-ext-common: default,macosx-clipboard
41$appkit->load if $appkit; 36 URxvt.keysym.M-c: perl:macosx-clipboard:copy
37 URxvt.keysym.M-v: perl:macosx-clipboard:paste
42 38
43if ($appkit->isLoaded) { 39The difference between them is that the native variant requires a
44 no strict 'refs'; 40perl from apple's devkit or so, and C<macosx-clipboard> requires the
45 for my $class (qw(NSPasteboard)) { 41C<Mac::Pasteboard> module, works with other perls, has fewer bugs, is
46 @{$class . '::ISA'} = 'PerlObjCBridge'; 42simpler etc. etc.
47 }
48} else {
49 undef $appkit;
50}
51 43
52$pasteboard = NSPasteboard->generalPasteboard; 44=cut
45
46use Mac::Pasteboard;
47
48my $pasteboard = new Mac::Pasteboard;
53 49
54sub copy { 50sub copy {
55 my ($self) = @_; 51 my ($self) = @_;
56 52
57 $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); 53 $pasteboard->clear;
58 $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); 54 $pasteboard->copy ($self->selection);
55
59 () 56 ()
60} 57}
61 58
62sub paste { 59sub paste {
63 my ($self) = @_; 60 my ($self) = @_;
64 my ($type, $str);
65 61
66 $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); 62 my $str = $pasteboard->paste;
67 if ($type->isEqual_('NSStringPboardType')){
68 $str = $pasteboard->stringForType_($type)->UTF8String;
69 $str =~ tr/\n/\r/;
70 utf8::decode($str); 63 utf8::decode $str;
71 $self->tt_write($self->locale_encode($str)); 64 $self->tt_write ($self->locale_encode ($str));
72 } 65
73 () 66 ()
74} 67}
75 68
76sub on_user_command { 69sub on_user_command {
77 my ($self, $cmd) = @_; 70 my ($self, $cmd) = @_;
81 } 74 }
82 75
83 if ($cmd eq "macosx-clipboard:paste") { 76 if ($cmd eq "macosx-clipboard:paste") {
84 $self->paste; 77 $self->paste;
85 } 78 }
79
86 () 80 ()
87} 81}
88 82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines