ConnectProperties/Element/iconview_selection.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 63 CC 5 SCAR 20.4
CC
5
Cov
0%
get_value
20.0
set_value
6.0
BEGIN
2.0
CRAP 7.7
1 # Copyright 2011, 2012, 2013 Kevin Ryde
2  
3 # This file is part of Glib-Ex-ConnectProperties.
4 #
5 # Glib-Ex-ConnectProperties is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Glib-Ex-ConnectProperties is distributed in the hope that it will be
11 # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Glib-Ex-ConnectProperties. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 # set selected-path select_path()
20 # model -- its treeview model or undef
21  
22  
23  
24 package Glib::Ex::ConnectProperties::Element::iconview_selection;
25 use 5.008;
26 use strict;
27 use warnings;
28 use Glib;
29 use Gtk2;
30 use base 'Glib::Ex::ConnectProperties::Element';
31  
32 our $VERSION = 20;
33  
34 # uncomment this to run the ### lines
35 #use Smart::Comments;
36  
37  
38 use constant pspec_hash =>
39 do {
40 my $bool = Glib::ParamSpec->boolean ('empty', # name
41 '', # nick
42 '', # blurb
43 1, # default, unused
44 'readable');
45 ({
46 'empty' => $bool,
47 'not-empty' => $bool,
48 'count' => Glib::ParamSpec->int ('count', # name
49 '', # nick
50 '', # blurb
51 0, # min
52 32767, # max
53 0, # default, unused
54 'readable'),
55  
56 'selected-path' => Glib::ParamSpec->boxed ('selected-path', # name
57 '', # nick
58 '', # blurb
59 'Gtk2::TreePath',
60 Glib::G_PARAM_READWRITE),
61 })
62 };
63  
64 use constant read_signal => 'selection-changed';
65  
66 sub get_value {
67 my ($self) = @_;
68 ### iconview_selection get_value()
69  
70 my @paths = $self->{'object'}->get_selected_items;
71 my $pname = $self->{'pname'};
72 if ($pname eq 'empty') {
73 return scalar(@paths) == 0;
74 } elsif ($pname eq 'not-empty') {
75 return scalar(@paths) != 0;
76 } elsif ($pname eq 'count') {
77 return scalar(@paths);
78 } else {
79 return $paths[0];
80 }
81 }
82  
83 sub set_value {
84 my ($self, $value) = @_;
85 ### iconview_selection set_value(): $value && "$value"
86  
87 # pname eq "selected-path"
88 my $iconview = $self->{'object'};
89 if (defined $value) {
90 ### select_path: $value->to_string
91 $iconview->select_path ($value);
92 } else {
93 ### unselect_all
94 $iconview->unselect_all;
95 }
96 }
97  
98 #------------------------------------------------------------------------------
99 # unused
100  
101 # sub _iconview_count_selected_items {
102 # my ($iconview) = @_;
103 # my @paths = $iconview->get_selected_items;
104 # return scalar(@paths);
105 # }
106  
107  
108 1;
109 __END__