| 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::ListViewer 1.382; | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use warnings; | ||
| 14 | use Carp; | ||
| 15 | |||
| 16 | use base qw/Tk::Frame Config::Model::Tk::AnyViewer/; | ||
| 17 | use subs qw/menu_struct/; | ||
| 18 | |||
| 19 | Construct Tk::Widget 'ConfigModelListViewer'; | ||
| 20 | |||
| 21 | my @fbe1 = qw/-fill both -expand 1/; | ||
| 22 | my @fxe1 = qw/-fill x -expand 1/; | ||
| 23 | my @fx = qw/-fill x /; | ||
| 24 | |||
| 25 | sub ClassInit { | ||
| 26 | my ( $cw, $args ) = @_; | ||
| 27 | |||
| 28 | # ClassInit is often used to define bindings and/or other | ||
| 29 | # resources shared by all instances, e.g., images. | ||
| 30 | |||
| 31 | # cw->Advertise(name=>$widget); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub Populate { | ||
| 35 | my ( $cw, $args ) = @_; | ||
| 36 | my $list = $cw->{list} = delete $args->{-item} | ||
| 37 | || die "ListViewer: no -item, got ", keys %$args; | ||
| 38 | my $path = delete $args->{-path} | ||
| 39 | || die "ListViewer: no -path, got ", keys %$args; | ||
| 40 | my $cme_font = delete $args->{-font}; | ||
| 41 | |||
| 42 | $cw->add_header( View => $list )->pack(@fx); | ||
| 43 | |||
| 44 | my $inst = $list->instance; | ||
| 45 | |||
| 46 | my $elt_frame = $cw->Frame(qw/-relief raised -borderwidth 2/)->pack(@fbe1); | ||
| 47 | my $str = $list->element_name . ' ' . $list->get_type . ' elements'; | ||
| 48 | $elt_frame->Label( -text => $str )->pack(); | ||
| 49 | |||
| 50 | my $rt = $elt_frame->Scrolled( 'ROText', -height => 10, )->pack(@fbe1); | ||
| 51 | |||
| 52 | my @insert = | ||
| 53 | $list->cargo_type eq 'leaf' | ||
| 54 | ? $list->fetch_all_values( check => 'no' ) | ||
| 55 | : $list->fetch_all_indexes; | ||
| 56 | foreach my $c (@insert) { | ||
| 57 | my $line = defined $c ? $c : '<undef>'; | ||
| 58 | $rt->insert( 'end', $line . "\n" ); | ||
| 59 | } | ||
| 60 | |||
| 61 | $cw->add_annotation($list)->pack(@fx); | ||
| 62 | $cw->add_warning( $list, 'view' )->pack(@fx); | ||
| 63 | $cw->add_summary($list)->pack(@fx); | ||
| 64 | $cw->add_description($list)->pack(@fbe1); | ||
| 65 | |||
| 66 | $cw->add_info_button()->pack( -side => 'left', @fxe1 ); | ||
| 67 | $cw->add_editor_button($path)->pack( -side => 'right', @fxe1 ); | ||
| 68 | |||
| 69 | $cw->ConfigSpecs(-font => [['SELF','DESCENDANTS'], 'font','Font', $cme_font ],); | ||
| 70 | |||
| 71 | $cw->SUPER::Populate($args); | ||
| 72 | } | ||
| 73 | |||
| 74 | sub cme_object { | ||
| 75 | my $cw = shift; | ||
| 76 | return $cw->{list}; | ||
| 77 | } | ||
| 78 | |||
| 79 | 1; |