Tk/NoteEditor.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 87 CC 2 SCAR 9.6
CC
2
Cov
0%
Populate
6.0
ClassInit
2.0
BEGIN
2.0
CRAP 2.6
1 #
2 # This file is part of Config-Model-TkUI
3 #
4 # This software is Copyright (c) 2008-2021 by Dominique Dumont.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package Config::Model::Tk::NoteEditor 1.382;
11  
12 use strict;
13 use warnings;
14 use Carp;
15 use Log::Log4perl;
16  
17 use base qw/Tk::Frame/;
18 use vars qw/$icon_path/;
19 use subs qw/menu_struct/;
20 use Tk::Photo;
21 use Tk::Balloon;
22 use Tk; # Needed to import Ev function
23  
24 Construct Tk::Widget 'ConfigModelNoteEditor';
25  
26 my @fbe1 = qw/-fill both -expand 1/;
27 my @fxe1 = qw/-fill x -expand 1/;
28 my @fx = qw/-fill x /;
29 my $logger = Log::Log4perl::get_logger(__PACKAGE__);
30  
31 sub ClassInit {
32 my ( $cw, $args ) = @_;
33  
34 # ClassInit is often used to define bindings and/or other
35 # resources shared by all instances, e.g., images.
36  
37 # cw->Advertise(name=>$widget);
38 }
39  
40 # This widget is to be integrated directly in a ConfigModel editor widget
41  
42 sub Populate {
43 my ( $cw, $args ) = @_;
44 my $obj = delete $args->{-object}
45 || croak "NoteEditor: no -object option, got ",
46 join( ',', keys %$args );
47  
48 return unless $obj->backend_support_annotation ;
49 my $label = 'Edit Note';
50 my $status = $label;
51 my $note_w;
52 my $cme_font = delete $args->{-font};
53  
54 my $save_cb = sub { $obj->annotation( $note_w->Contents ); $status = $label; };
55 my $del_cb = sub {
56 $obj->clear_annotation;
57 $note_w->Contents('');
58 $status = $label;
59 };
60 my $updated_cb = sub {
61 my $k = Ev('k');
62 $status = $label . '*';
63 };
64  
65 my $ed_frame = $cw->Frame->pack();
66 my $ctrl_frame = $ed_frame->Frame->pack( -side => 'left' );
67 $ctrl_frame->Label( -textvariable => \$status )->pack();
68 $ctrl_frame->Button( -text => 'save note', -command => $save_cb )->pack( -fill => 'x' );
69 $ctrl_frame->Button( -text => 'del note', -command => $del_cb )->pack( -fill => 'x' );
70  
71 $note_w = $ed_frame->Scrolled(
72 'Text',
73 -height => 5,
74 -scrollbars => 'ow',
75 )->pack( @fbe1, -anchor => 's', -side => 'bottom' );
76  
77 my $balloon = $ed_frame->Balloon( -state => 'balloon' );
78 $balloon->attach( $note_w, -msg => 'You may enter a comment here' );
79  
80 # read annotation and set up a callback to save user's entry at
81 # every return
82 $note_w->Contents( $obj->annotation );
83 $note_w->bind( '<KeyPress>', $updated_cb );
84 $note_w->bind( '<Button-2>', $updated_cb );
85  
86 $cw->ConfigSpecs(-font => [['SELF','DESCENDANTS'], 'font','Font', $cme_font ],);
87  
88 $cw->SUPER::Populate($args);
89 }
90  
91 1;