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.5 by sf-exg, Tue Nov 22 17:04:28 2011 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.
28 27
29# URxvt.perl-ext-common: macosx-clipboard 28# URxvt.perl-ext-common: macosx-clipboard
30# URxvt.keysym.M-c: perl:macosx-clipboard:copy 29# URxvt.keysym.M-c: perl:macosx-clipboard:copy
31# URxvt.keysym.M-v: perl:macosx-clipboard:paste 30# URxvt.keysym.M-v: perl:macosx-clipboard:paste
32 31
33use Fcntl (); 32use Mac::Pasteboard;
34use Foundation;
35use locale;
36use utf8;
37 33
38our($appkit, $pasteboard); 34my $pasteboard = new Mac::Pasteboard;
39 35
40sub copy { 36sub copy {
41 my ($self) = @_; 37 my ($self) = @_;
42 38
43 $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); 39 $pasteboard->clear;
44 $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); 40 $pasteboard->copy ($self->selection);
41
45 () 42 ()
46} 43}
47 44
48sub paste { 45sub paste {
49 my ($self) = @_; 46 my ($self) = @_;
50 my ($type, $str);
51 47
52 $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); 48 my $str = $pasteboard->paste;
53 if ($type->isEqual_('NSStringPboardType')){
54 $str = $pasteboard->stringForType_($type)->UTF8String;
55 $str =~ tr/\n/\r/;
56 utf8::decode($str); 49 utf8::decode $str;
57 $self->tt_write($self->locale_encode($str)); 50 $self->tt_write ($self->locale_encode ($str));
58 }
59 ()
60}
61 51
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 () 52 ()
79} 53}
80 54
81sub on_user_command { 55sub on_user_command {
82 my ($self, $cmd) = @_; 56 my ($self, $cmd) = @_;
86 } 60 }
87 61
88 if ($cmd eq "macosx-clipboard:paste") { 62 if ($cmd eq "macosx-clipboard:paste") {
89 $self->paste; 63 $self->paste;
90 } 64 }
65
91 () 66 ()
92} 67}
93 68

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines