Curie/Component/MainWindow/Role/DragAndDrop.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 48 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use Renard::Incunabula::Common::Setup;
2 package Renard::Curie::Component::MainWindow::Role::DragAndDrop;
3 # ABSTRACT: Role for drag-and-drop
4 $Renard::Curie::Component::MainWindow::Role::DragAndDrop::VERSION = '0.005';
5 use Moo::Role;
6 use MooX::ShortHas;
7  
8 use URI::file;
9  
10 lazy DND_TARGET_URI_LIST => sub { 0 };
11 lazy DND_TARGET_TEXT => sub { 1 };
12  
13 requires 'content_box';
14  
15 after BUILD => method() {
16 $self->setup_dnd;
17 };
18  
19 method setup_dnd() {
20 $self->content_box->drag_dest_set('all', [], 'copy');
21 my $target_list = Gtk3::TargetList->new([
22 Gtk3::TargetEntry->new( 'text/uri-list', 0, $self->DND_TARGET_URI_LIST ),
23 Gtk3::TargetEntry->new( 'text/plain' , 0, $self->DND_TARGET_TEXT )
24 ]);
25 $self->content_box->drag_dest_set_target_list($target_list);
26  
27 $self->content_box->signal_connect('drag-data-received' =>
28 \&on_drag_data_received_cb, $self );
29 }
30  
31 callback on_drag_data_received_cb( $widget, $context, $x, $y, $data, $info, $time, $self ) {
32 my $pdf_filename_text;
33  
34 if( $info == $self->DND_TARGET_URI_LIST ) {
35 my @uris = @{ $data->get_uris };
36 $pdf_filename_text = $uris[0];
37 } elsif( $info == $self->DND_TARGET_TEXT ) {
38 my $text = $data->get_text;
39 if( $text =~ /^file:/ ) {
40 $pdf_filename_text = $text;
41 } else {
42 warn "Do not know what to do with text drag-and-drop data: $text";
43 }
44 }
45  
46 if( defined $pdf_filename_text ) {
47 $self->view_manager->open_document_as_file_uri(
48 URI->new($pdf_filename_text, 'file')
49 );
50 }
51 }
52  
53 1;
54  
55 __END__