File Coverage

blib/lib/Gtk2/Ex/ToolbarBits.pm
Criterion Covered Total %
statement 12 19 63.1
branch 0 4 0.0
condition 0 3 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 32 53.1


line stmt bran cond sub pod time code
1             # Copyright 2010, 2011, 2012 Kevin Ryde
2              
3             # This file is part of Gtk2-Ex-WidgetBits.
4             #
5             # Gtk2-Ex-WidgetBits 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             # Gtk2-Ex-WidgetBits is distributed in the hope that it will be useful,
11             # 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 Gtk2-Ex-WidgetBits. If not, see .
17              
18              
19             package Gtk2::Ex::ToolbarBits;
20 1     1   577 use 5.008;
  1         3  
  1         42  
21 1     1   5 use strict;
  1         2  
  1         73  
22 1     1   6 use warnings;
  1         2  
  1         29  
23              
24 1     1   6 use Exporter;
  1         1  
  1         213  
25             our @ISA = ('Exporter');
26             our @EXPORT_OK = qw(move_item_after);
27              
28             our $VERSION = 48;
29              
30             # uncomment this to run the ### lines
31             #use Smart::Comments;
32              
33             sub move_item_after {
34 0     0 1   my ($toolbar, $item, $after_item) = @_;
35              
36             # get_item_index() gives a g_log() if $after_item is not in $toolbar.
37             # Believe that's enough error report. Could check the parent and croak if
38             # something stricter was wanted.
39             #
40 0           my $target_pos = $toolbar->get_item_index($after_item) + 1;
41              
42 0 0         if (my $parent = $item->get_parent) {
43 0 0 0       if ($parent == $toolbar
44             && $toolbar->get_item_index ($item) == $target_pos) {
45 0           return; # already right
46             }
47 0           $toolbar->remove ($item);
48             }
49 0           $toolbar->insert ($item, $target_pos);
50             }
51              
52             1;
53             __END__