/usr/share/perl5/Config/Model/Tk/NodeEditor.pm is in libconfig-model-tkui-perl 1.365-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | #
# This file is part of Config-Model-TkUI
#
# This software is Copyright (c) 2008-2017 by Dominique Dumont.
#
# This is free software, licensed under:
#
# The GNU Lesser General Public License, Version 2.1, February 1999
#
package Config::Model::Tk::NodeEditor;
$Config::Model::Tk::NodeEditor::VERSION = '1.365';
use strict;
use warnings;
use Carp;
use Tk::Pane;
use Tk::Balloon;
use Text::Wrap;
use Config::Model::Tk::NoteEditor;
use base qw/Config::Model::Tk::NodeViewer/;
use subs qw/menu_struct/;
Construct Tk::Widget 'ConfigModelNodeEditor';
my @fbe1 = qw/-fill both -expand 1/;
my @fxe1 = qw/-fill x -expand 1/;
my @fx = qw/-fill x -expand 0/;
my $logger = Log::Log4perl::get_logger("Tk::NodeEditor");
sub ClassInit {
my ( $cw, $args ) = @_;
# ClassInit is often used to define bindings and/or other
# resources shared by all instances, e.g., images.
# cw->Advertise(name=>$widget);
}
sub Populate {
my ( $cw, $args ) = @_;
my $node = $cw->{node} = delete $args->{-item}
|| die "NodeViewer: no -item, got ", keys %$args;
$cw->{path} = delete $args->{-path};
$cw->{store_cb} = delete $args->{-store_cb} || die __PACKAGE__, "no -store_cb";
my $cme_font = $cw->{my_font} = delete $args->{-font};
$cw->add_header( Edit => $node )->pack(@fx);
$cw->Label( -text => $node->composite_name . ' node elements' )->pack();
$cw->{pane} = $cw->Scrolled(qw/Pane -scrollbars osow -sticky senw/);
$cw->{pane}->pack(@fbe1);
$cw->fill_pane;
# insert a widget for "accepted" elements
my @rexp = $node->accept_regexp;
if (@rexp) {
$cw->add_accept_entry(@rexp);
}
# add adjuster
#require Tk::Adjuster;
#$cw -> Adjuster()->pack(-fill => 'x' , -side => 'top') ;
$cw->ConfigModelNoteEditor( -object => $node )->pack;
$cw->add_info_button()->pack( @fxe1, qw/-anchor n/ );
if ( $node->parent ) {
$cw->add_summary($node)->pack(@fx);
$cw->add_description($node)->pack(@fbe1);
}
else {
$cw->add_help( class => $node->get_help )->pack(@fx);
}
$cw->ConfigSpecs(-font => [['SELF','DESCENDANTS'], 'font','Font', $cme_font ],);
# don't call directly SUPER::Populate as it's NodeViewer's populate
$cw->Tk::Frame::Populate($args);
# TODO: above is a hack. The required methods of NodeViewer and
# AnyViewer should be moved into a role. Question: how can roles
# be done with Tk ??
}
sub reload {
goto &fill_pane;
}
sub fill_pane {
my $cw = shift;
my $node = $cw->{node};
my $elt_pane = $cw->{pane};
my %is_elt_drawn = map { ( $_ => 1 ) } keys %{ $cw->{elt_widgets} || {} };
my %values;
my %modified;
my $prev_elt;
my $font = $cw->{my_font}; #cget('-font');
foreach my $c ( $node->get_element_name() ) {
if ( delete $is_elt_drawn{$c} ) {
$prev_elt = $c;
next;
}
my $type = $node->element_type($c);
my $elt_path = $cw->{path} . '.' . $c;
my @after = defined $prev_elt ? ( -after => $cw->{elt_widgets}{$prev_elt} ) : ();
$prev_elt = $c;
my $f = $elt_pane->Frame( -relief => 'groove', -borderwidth => 1 );
$f->pack( -side => 'top', @fx, @after );
$cw->{elt_widgets}{$c} = $f;
my $label = $f->Label( -text => $c, -font => $font, -width => 22, -anchor => 'w' );
$label->pack(qw/-side left -fill x -anchor w/);
my $help = $node->get_help_as_text( summary => $c ) || $node->get_help_as_text( description => $c );
$cw->Balloon( -state => 'balloon' )->attach( $label, -msg => wrap( '', '', $help ) );
if ( $type eq 'leaf' ) {
my $leaf = $node->fetch_element($c);
my $v = $node->fetch_element_value( name => $c, check => 'no' );
my $store_sub = sub {
$leaf->store($v);
$cw->{store_cb}->($elt_path);
$cw->fill_pane;
};
my $v_type = $leaf->value_type;
if ( $v_type =~ /integer|number|uniline/ ) {
my $e = $f->Entry( -textvariable => \$v )->pack( qw/-side left -anchor w/, @fxe1 );
$e->bind( "<Return>" => $store_sub );
$e->bind( "<FocusOut>" => $store_sub );
next;
}
if ( $v_type =~ /boolean/ ) {
my $e = $f->Checkbutton( -variable => \$v, -font => $font, -command => $store_sub )
->pack(qw/-side left -anchor w/);
next;
}
if ( $v_type =~ /enum|reference/ ) {
my @choices = $leaf->get_choice;
require Tk::BrowseEntry;
my $e = $f->BrowseEntry(
-variable => \$v,
-font => $font,
-browsecmd => $store_sub,
-choices => \@choices
)->pack( qw/-side left -anchor w/, @fxe1 );
next;
}
}
# add button to launch dedicated editor
my $obj = $node->fetch_element($c);
my $edit_sub = sub {
# it would be better for tkui ui to pass this as a callback
# note that storing tkui object in a sub widget creates issues with tk
$cw->parent->parent->parent->parent->create_element_widget( 'edit', $elt_path, $obj );
};
my $edb = $f->Button(
-text => '...',
-font => $font,
-command => $edit_sub
);
$edb->pack( -anchor => 'w' );
my $content =
$type eq 'leaf' ? $obj->fetch( check => 'no' ) || ''
: $type eq 'node' ? $node->config_class_name
: $type;
$cw->Balloon( -state => 'balloon' )->attach( $edb, -msg => wrap( '', '', $content ) );
}
# destroy leftover widgets (may occur with warp mechanism)
map { my $w = delete $cw->{elt_widgets}{$_}; $w->destroy } keys %is_elt_drawn;
}
sub add_accept_entry {
my ( $cw, @rexp ) = @_;
my $node = $cw->{node};
my $f = $cw->Frame( -relief => 'groove', -borderwidth => 1 );
$f->pack( -side => 'top', @fx );
my $font = $cw->{my_font}; #cget('-font');
my $accepted = '';
$f->Label( -text => 'accept : /' . join( '/, /', @rexp ) . '/', -font => $font )->pack;
my $e = $f->Entry( -textvariable => \$accepted, -font => $font)->pack( qw/-side left -anchor w/, @fxe1 );
my $sub = sub {
return unless $accepted;
my $ok = 0;
map { $ok++ if $accepted =~ /^$_$/ } @rexp;
if ( not $ok ) {
die "Cannot accept $accepted, it does not match any accepted regexp\n";
}
$node->fetch_element($accepted);
$cw->{store_cb}->();
$cw->fill_pane;
$cw->{pane}->yview( moveto => 1 );
};
$e->bind( "<Return>" => $sub );
}
1;
|