1 | package GCE::HashDialogue; |
1 | package GCE::HashDialogue; |
2 | |
2 | |
3 | =head1 NAME |
3 | =head1 NAME |
4 | |
4 | |
5 | GCE::AttachEditor - this is a editor for attachments for maps and objects |
5 | GCE::HashDialogue - this is a editor for hashes (eg. for properties and meta info) |
6 | |
6 | |
7 | =cut |
7 | =cut |
8 | |
8 | |
9 | use Gtk2; |
9 | use Gtk2; |
10 | use Gtk2::Gdk::Keysyms; |
10 | use Gtk2::Gdk::Keysyms; |
… | |
… | |
47 | my ($self, $key, $desc, $type, $cb) = @_; |
47 | my ($self, $key, $desc, $type, $cb) = @_; |
48 | |
48 | |
49 | my $table = $self->{table}; |
49 | my $table = $self->{table}; |
50 | my $idx = $self->{table_idx}; |
50 | my $idx = $self->{table_idx}; |
51 | |
51 | |
52 | if ($type eq 'string') { |
52 | if ($type eq 'string' || $type eq 'password') { |
53 | $table->attach_defaults (Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
53 | $table->attach_defaults (Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
54 | $table->attach_defaults (my $edwid = Gtk2::Entry->new, 1, 2, $idx, $idx + 1); |
54 | $table->attach_defaults (my $edwid = Gtk2::Entry->new, 1, 2, $idx, $idx + 1); |
|
|
55 | $edwid->set (visibility => 0) if $type eq 'password'; |
55 | $edwid->set_text ($self->{edit_hash}{$key}); |
56 | $edwid->set_text ($self->{edit_hash}{$key}); |
56 | $edwid->signal_connect (changed => sub { |
57 | $edwid->signal_connect (changed => sub { |
57 | $self->{edit_hash}->{$key} = $_[0]->get_text; |
58 | $self->{edit_hash}->{$key} = $_[0]->get_text; |
58 | }); |
59 | }); |
59 | |
60 | |
… | |
… | |
62 | $b->signal_connect (clicked => sub { $cb->(\$self->{edit_hash}{$key}) if $cb }); |
63 | $b->signal_connect (clicked => sub { $cb->(\$self->{edit_hash}{$key}) if $cb }); |
63 | |
64 | |
64 | } elsif ($type eq 'label') { |
65 | } elsif ($type eq 'label') { |
65 | $table->attach_defaults (Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
66 | $table->attach_defaults (Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
66 | $table->attach_defaults (Gtk2::Label->new ($self->{edit_hash}{$key}), 1, 2, $idx, $idx + 1); |
67 | $table->attach_defaults (Gtk2::Label->new ($self->{edit_hash}{$key}), 1, 2, $idx, $idx + 1); |
|
|
68 | |
|
|
69 | } elsif ($type eq 'desc') { |
|
|
70 | $table->attach_defaults (Gtk2::Label->new ($desc), 0, 2, $idx, $idx + 1); |
67 | |
71 | |
68 | } elsif ($type eq 'check') { |
72 | } elsif ($type eq 'check') { |
69 | $table->attach_defaults (Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
73 | $table->attach_defaults (Gtk2::Label->new ($desc), 0, 1, $idx, $idx + 1); |
70 | $table->attach_defaults (my $chk = Gtk2::CheckButton->new, 1, 2, $idx, $idx + 1); |
74 | $table->attach_defaults (my $chk = Gtk2::CheckButton->new, 1, 2, $idx, $idx + 1); |
71 | $chk->set_active ($self->{edit_hash}{$key}); |
75 | $chk->set_active ($self->{edit_hash}{$key}); |
… | |
… | |
127 | |
131 | |
128 | for (@{$self->{dialog}}) { |
132 | for (@{$self->{dialog}}) { |
129 | push @{$self->{hash_keys}}, $_->[0] if defined $_->[0]; |
133 | push @{$self->{hash_keys}}, $_->[0] if defined $_->[0]; |
130 | } |
134 | } |
131 | |
135 | |
132 | $self->add (my $sw = Gtk2::ScrolledWindow->new); |
136 | $self->add (my $vb = Gtk2::VBox->new); |
|
|
137 | $vb->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
133 | $sw->set_policy ('automatic', 'automatic'); |
138 | $sw->set_policy ('automatic', 'automatic'); |
134 | $sw->add_with_viewport (my $v = Gtk2::VBox->new); |
139 | $sw->add_with_viewport (my $v = Gtk2::VBox->new); |
135 | $v->pack_start ($self->{table} = Gtk2::Table->new (2, $cfg_lines), 0, 0, 0); |
140 | $v->pack_start ($self->{table} = Gtk2::Table->new (2, $cfg_lines), 0, 0, 0); |
|
|
141 | if ($self->{text_entry}) { |
|
|
142 | $vb->pack_start (Gtk2::Label->new ($self->{text_entry}->{label}), 0, 1, 0) |
|
|
143 | if $self->{text_entry}->{label}; |
|
|
144 | $vb->pack_start (my $txt = Gtk2::TextView->new, 1, 1, 0); |
|
|
145 | # TODO/XXX: Implement hash-changes! |
|
|
146 | } |
136 | $v->pack_start (my $hb = Gtk2::HBox->new (1, 0), 0, 0, 0); |
147 | $vb->pack_start (my $hb = Gtk2::HBox->new (1, 0), 0, 0, 0); |
137 | $hb->pack_start (my $save_btn = Gtk2::Button->new ("save"), 1, 1, 0); |
148 | $hb->pack_start (my $save_btn = Gtk2::Button->new ($self->{save_button_label} || "save"), 1, 1, 0); |
138 | $hb->pack_start (my $reset_btn = Gtk2::Button->new ("reset"), 1, 1, 0); |
149 | $hb->pack_start (my $reset_btn = Gtk2::Button->new ("reset"), 1, 1, 0); |
139 | $hb->pack_start (my $close_btn = Gtk2::Button->new ("cancel"), 1, 1, 0); |
150 | $hb->pack_start (my $close_btn = Gtk2::Button->new ("cancel"), 1, 1, 0); |
140 | |
151 | |
141 | $self->reset; |
152 | $self->reset; |
142 | |
153 | |
143 | $self->build_table; |
154 | $self->build_table; |
144 | |
155 | |