… | |
… | |
30 | my ($self) = @_; |
30 | my ($self) = @_; |
31 | |
31 | |
32 | $self->{raw} = 1; |
32 | $self->{raw} = 1; |
33 | $self->{editable} = 1; |
33 | $self->{editable} = 1; |
34 | |
34 | |
35 | my $ls = $self->{ls} = |
35 | my $ls = $self->{liststore} = |
36 | Gtk2::ListStore->new ( |
36 | Gtk2::ListStore->new ( |
37 | 'Glib::String', 'Glib::String', 'Glib::String' |
37 | 'Glib::String', 'Glib::String', 'Glib::String' |
38 | ); |
38 | ); |
39 | |
39 | |
40 | my $tv = $self->{tv} = Gtk2::TreeView->new ($ls); |
40 | my $tv = $self->{tv} = Gtk2::TreeView->new ($ls); |
… | |
… | |
42 | |
42 | |
43 | $self->add_columns ($tv); |
43 | $self->add_columns ($tv); |
44 | |
44 | |
45 | $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
45 | $self->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
46 | $sw->set_shadow_type ('etched-in'); |
46 | $sw->set_shadow_type ('etched-in'); |
47 | $sw->set_policy ('never', 'automatic'); |
47 | $sw->set_policy ('automatic', 'automatic'); |
48 | $sw->add ($tv); |
48 | $sw->add ($tv); |
49 | |
49 | |
50 | $self->pack_start (my $e = $self->{new_attr_entry} = Gtk2::Entry->new, 0, 1, 0); |
50 | $self->pack_start (my $e = $self->{new_attr_entry} = Gtk2::Entry->new, 0, 1, 0); |
51 | $e->signal_connect (activate => sub { |
51 | $e->signal_connect (activate => sub { |
52 | my ($e) = @_; |
52 | my ($e) = @_; |
53 | |
53 | |
54 | $self->set_attr ($e->get_text, '<please fill>'); |
54 | $self->set_attr ($e->get_text, '<insert value>'); |
55 | $e->set_text (''); |
55 | $e->set_text (''); |
56 | |
56 | |
57 | }); |
57 | }); |
58 | } |
58 | } |
59 | |
59 | |
… | |
… | |
124 | |
124 | |
125 | sub set_arch { |
125 | sub set_arch { |
126 | my ($self, $arch) = @_; |
126 | my ($self, $arch) = @_; |
127 | |
127 | |
128 | $self->{arch} = $arch; |
128 | $self->{arch} = $arch; |
129 | my @interesting = GCE::AttrTypemap::interesting_fields ($arch); |
|
|
130 | |
129 | |
131 | $self->{ls}->clear; |
130 | $self->{liststore}->clear; |
132 | |
131 | |
|
|
132 | # these are all attribute keys that will be _displayed_ |
|
|
133 | my @attrib_keys = |
|
|
134 | grep { |
|
|
135 | # filter out msg, lore they are special and multiline! |
|
|
136 | $_ ne 'msg' and $_ ne 'lore' |
|
|
137 | } ( |
|
|
138 | keys %$arch, # include all defined attribute keys |
|
|
139 | grep { |
|
|
140 | # we exclude the interesting attributes from |
|
|
141 | # the Typemap when raw is enabled |
|
|
142 | |
|
|
143 | !$self->{raw} and not exists $self->{arch}->{$_} |
|
|
144 | |
|
|
145 | } GCE::AttrTypemap::interesting_fields ($arch) |
|
|
146 | ); |
|
|
147 | |
|
|
148 | # construct the sorted list of displayed attributes |
133 | my @list = |
149 | my @list = |
|
|
150 | sort { |
|
|
151 | |
134 | sort { $a->[0] cmp $b->[0] } |
152 | $a->[0] cmp $b->[0] |
135 | |
153 | |
136 | map { my $c = $arch->{$_}; |
154 | } map { |
137 | |
155 | # exclude inventory |
138 | if (ref $c eq 'ARRAY') { |
156 | ref $c |
139 | |
|
|
140 | [$_, join (',', map { $_->{_name} } @$c)]; |
157 | ? [$_, join (',', map { $_->{_name} } @{$arch->{$_}})] |
141 | |
|
|
142 | } else { |
|
|
143 | |
|
|
144 | [$_, $c]; |
158 | : [$_, $arch->{$_}] |
145 | } |
|
|
146 | |
159 | |
147 | } (keys %$arch, grep { (not $self->{raw}) and not exists $self->{arch}->{$_} } @interesting); |
160 | } @attrib_keys; |
148 | |
161 | |
149 | for (@list) { |
162 | for (@list) { |
150 | |
163 | |
151 | my $it = $self->{ls}->append; |
164 | my $it = $self->{liststore}->append; # append |
152 | |
165 | |
|
|
166 | # get the attribute display name |
153 | my $attrname = |
167 | my $attrname = |
154 | $self->{raw} |
168 | $self->{raw} |
155 | ? $_->[0] |
169 | ? $_->[0] |
156 | : $self->get_attr_name ($arch, $_->[0]); |
170 | : $self->get_attr_name ($arch, $_->[0]); |
157 | |
171 | |
158 | $self->{ls}->set ($it, 0 => $attrname, 1 => $_->[1], 2 => $_->[2]); |
172 | $self->{liststore}->set ( |
|
|
173 | $it, |
|
|
174 | 0 => $attrname, |
|
|
175 | 1 => $_->[1], |
|
|
176 | 2 => $_->[2] |
|
|
177 | ); |
159 | } |
178 | } |
160 | |
179 | |
|
|
180 | # XXX: How do i update the model correctly? |
161 | $self->{tv}->set_model ($self->{ls}); |
181 | $self->{tv}->set_model ($self->{liststore}); |
162 | |
182 | |
163 | $self->{attr_list} = \@list; |
183 | $self->{attr_list} = \@list; |
164 | } |
184 | } |
165 | |
185 | |
166 | sub set_attr { |
186 | sub set_attr { |