blib/lib/Gtk2/Ex/FileLocator/DropPocket.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 84 CC 2 SCAR 9.4
CC
2
Cov
0%
on_drag_data_received
6.0
INIT_INSTANCE
2.0
on_map
2.0
CRAP 2.6
1 package Gtk2::Ex::FileLocator::DropPocket;
2 use strict;
3 no warnings;
4  
5 use Gtk2;
6 use Glib qw(TRUE FALSE);
7  
8 use Gtk2::Ex::FileLocator::Helper;
9 use Gtk2::Ex::FileLocator::FileChooser;
10  
11 use Glib::Object::Subclass Gtk2::Ex::FileLocator::FileChooser::,;
12  
13 our @targets = (
14 { target => "text/uri-list", flags => [], info => 0 },
15 { target => "STRING", flags => [], info => 0 },
16 { target => "text/plain", flags => [], info => 0 },
17 );
18  
19 sub INIT_INSTANCE {
20 my $this = shift;
21  
22 $this->{iconsize} = "small";
23  
24 $this->{image} = Gtk2::Image->new;
25 $this->{image}->show;
26  
27 my $button = new Gtk2::Button;
28 $button->set_border_width(1);
29 $button->add( $this->{image} );
30 $button->drag_source_set( [ 'button1_mask', 'button3_mask' ],
31 [qw'copy link'], $targets[0] );
32 $button->signal_connect( 'drag_data_get', \&on_drag_data_get, $this );
33 $button->signal_connect_after( 'clicked' => \&on_click, $this );
34 $button->show;
35 $button->set_reallocate_redraws(FALSE);
36 $button->set_resize_mode('parent');
37  
38 #$this->set_shadow_type('in');
39 $this->add($button);
40  
41 $this->drag_dest_set( 'all', [qw(copy move link)], @targets );
42 $this->signal_connect_after( 'map' => \&on_map );
43 $this->signal_connect_after(
44 'drag_data_received' => \&on_drag_data_received );
45  
46 $this->signal_connect( 'selection-changed', sub { $this->change_image } );
47 }
48  
49 sub on_map {
50 my $this = shift;
51 $this->set_size_request( $this->allocation->height + 5, 0 );
52 0;
53 }
54  
55 sub change_image {
56 my ($this) = @_;
57  
58 #$this->Debug("###### ", $this->get_filename);
59  
60 image_set_file_icon( $this->{image}, string_shell_unescape($this->get_filename),
61 $this->{iconsize} );
62  
63 return;
64 }
65  
66 sub on_click {
67 my ( $widget, $this ) = @_;
68 $this->get('chooser')->show;
69 return;
70 }
71  
72 sub on_drag_data_received {
73 my ( $this, $context, $x, $y, $data, $flags, $time ) = @_;
74  
75 #$this->Debug($data->data, $data->type->name);
76  
77 if ( $data->type->name eq "text/uri-list" ) {
78 my @uri = split "\r\n", $data->data;
79 printf "uri %s\n", $uri[0];
80  
81 $this->set_uri( $uri[0] );
82 }
83 0;
84 }
85  
86 sub on_drag_data_get {
87 my ( $button, $context, $data, $info, $time, $this ) = @_;
88 my $uri = $this->get_uri;
89 $data->set( $data->target, 8, " $uri\r\n" );
90 0;
91 }
92  
93 1;
94 __END__