ConnectProperties/Element/tree_selection.pm untested

filter: Statementstmt 0.0% 0 / 45 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 / 65 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 2010, 2011, 2012 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::tree_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  
49 'count' => Glib::ParamSpec->int ('count', # name
50 '', # nick
51 '', # blurb
52 0, # min
53 32767, # max
54 0, # default, unused
55 'readable'),
56  
57 'selected-path' => Glib::ParamSpec->boxed ('selected-path', # name
58 '', # nick
59 '', # blurb
60 'Gtk2::TreePath',
61 Glib::G_PARAM_READWRITE),
62 })
63 };
64  
65 use constant read_signal => 'changed';
66  
67 sub get_value {
68 my ($self) = @_;
69 ### tree_selection get_value(): "$self->{'object'}"
70  
71 my $sel = $self->{'object'};
72 my $pname = $self->{'pname'};
73 if ($pname eq 'selected-path') {
74 return ($sel->get_selected_rows)[0];
75 } else {
76 my $count = $sel->count_selected_rows;
77 if ($pname eq 'empty') {
78 return $count == 0;
79 } elsif ($pname eq 'not-empty') {
80 return $count != 0;
81 } else {
82 return $count;
83 }
84 }
85 }
86  
87 sub set_value {
88 my ($self, $value) = @_;
89 ### tree_selection set_value(): "$self->{'object'}"
90 ### value: $value && "$value"
91  
92 # pname eq "selected-path"
93 my $sel = $self->{'object'};
94 if (defined $value) {
95 ### select_path: $value->to_string
96 $sel->select_path ($value);
97 } else {
98 ### unselect_all
99 $sel->unselect_all;
100 }
101 }
102  
103 1;
104 __END__