1 |
elmex |
1.1 |
package GCE::AttrEdit; |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
GCE::AttrEdit - an edit wiget for attributes |
6 |
|
|
|
7 |
|
|
=cut |
8 |
|
|
|
9 |
|
|
use Gtk2; |
10 |
|
|
use Gtk2::Gdk::Keysyms; |
11 |
|
|
use Gtk2::SimpleList; |
12 |
|
|
|
13 |
elmex |
1.4 |
use Glib::Object::Subclass Gtk2::VBox; |
14 |
elmex |
1.3 |
|
15 |
|
|
use GCE::AttrList; |
16 |
|
|
|
17 |
|
|
use Crossfire; |
18 |
elmex |
1.1 |
|
19 |
|
|
sub INIT_INSTANCE { |
20 |
|
|
my ($self) = @_; |
21 |
|
|
|
22 |
elmex |
1.4 |
$self->pack_start (my $lbl = $self->{arch_name_lbl} = Gtk2::Label->new, 0, 1, 0); |
23 |
|
|
$self->pack_start (my $ntbook = $self->{ntbook} = Gtk2::Notebook->new, 1, 1, 0); |
24 |
elmex |
1.6 |
$self->pack_start (my $hb = Gtk2::HBox->new (1, 0), 0, 1, 0); |
25 |
|
|
$hb->pack_start (my $ek = $self->{new_attrkey_entry} = Gtk2::Entry->new, 1, 1, 0); |
26 |
|
|
$hb->pack_start (my $ev = $self->{new_attrval_entry} = Gtk2::Entry->new, 1, 1, 0); |
27 |
elmex |
1.5 |
$ek->signal_connect (activate => sub { |
28 |
|
|
$ev->grab_focus; |
29 |
|
|
}); |
30 |
|
|
$ev->signal_connect (activate => sub { |
31 |
|
|
my ($e) = @_; |
32 |
|
|
|
33 |
|
|
$self->set_attr ($ek->get_text, $ev->get_text); |
34 |
|
|
$ev->set_text (''); |
35 |
|
|
$ek->set_text (''); |
36 |
|
|
}); |
37 |
elmex |
1.4 |
|
38 |
elmex |
1.3 |
my $al = $self->{al} = GCE::AttrList->new (editable => 1, raw => 0); |
39 |
elmex |
1.4 |
$ntbook->append_page ($al, "obj attrs"); |
40 |
elmex |
1.3 |
$al->set_arch_cb (sub { $self->update_arch (@_) }); |
41 |
|
|
|
42 |
|
|
$al = $self->{raw_al} = GCE::AttrList->new (editable => 1); |
43 |
elmex |
1.4 |
$ntbook->append_page ($al, "raw attrs"); |
44 |
elmex |
1.3 |
$al->set_arch_cb (sub { $self->update_arch (@_) }); |
45 |
|
|
|
46 |
|
|
$al = $self->{al_arch} = GCE::AttrList->new (editable => 0); |
47 |
elmex |
1.4 |
$ntbook->append_page ($al, "arch attrs"); |
48 |
elmex |
1.3 |
$al->set_arch_cb (sub { $self->update_arch (@_) }); |
49 |
elmex |
1.4 |
|
50 |
|
|
# XXX: Implement autosave! |
51 |
|
|
for my $type (qw/lore msg/) { |
52 |
|
|
|
53 |
|
|
$ntbook->append_page (my $vb = Gtk2::VBox->new, $type); |
54 |
|
|
$vb->pack_start (my $txtv = $self->{"${type}_view"} = Gtk2::TextView->new, 1, 1, 0); |
55 |
|
|
$vb->pack_start (my $btn = Gtk2::Button->new_with_label ("save $type"), 0, 1, 0); |
56 |
|
|
$btn->signal_connect (clicked => sub { |
57 |
|
|
|
58 |
|
|
my $txtbuf = $txtv->get_buffer; |
59 |
|
|
|
60 |
|
|
my ($start_iter, $end_iter) = ($txtbuf->get_start_iter, $txtbuf->get_end_iter); |
61 |
|
|
my $txt = $txtv->get_buffer ()->get_text ($start_iter, $end_iter, 0); |
62 |
|
|
|
63 |
|
|
$self->update_arch ($self->{arch}, $type, $txt); |
64 |
|
|
}); |
65 |
|
|
} |
66 |
elmex |
1.3 |
} |
67 |
|
|
|
68 |
|
|
sub update_arch { |
69 |
|
|
my ($self, $arch, $key, $value) = @_; |
70 |
|
|
|
71 |
|
|
if ($value ne '') { |
72 |
|
|
|
73 |
|
|
$arch->{$key} = $value; |
74 |
|
|
|
75 |
|
|
} else { |
76 |
|
|
|
77 |
|
|
delete $arch->{$key}; |
78 |
|
|
} |
79 |
elmex |
1.1 |
|
80 |
elmex |
1.4 |
# XXX: maybe update a little bit more intelligent... |
81 |
elmex |
1.3 |
$self->set_arch ($arch); |
82 |
elmex |
1.1 |
} |
83 |
|
|
|
84 |
elmex |
1.5 |
sub set_attr { |
85 |
|
|
my ($self, $key, $value) = @_; |
86 |
|
|
|
87 |
|
|
my $attr = $self->{arch}->{$key}; |
88 |
|
|
|
89 |
|
|
unless (ref $attr) { |
90 |
|
|
|
91 |
|
|
$self->update_arch ($self->{arch}, $key, $value); |
92 |
|
|
} |
93 |
|
|
} |
94 |
|
|
|
95 |
elmex |
1.2 |
sub set_arch { |
96 |
elmex |
1.3 |
my ($self, $arch, $ro) = @_; |
97 |
|
|
|
98 |
elmex |
1.4 |
$self->{arch} = $arch; |
99 |
|
|
|
100 |
elmex |
1.3 |
if ($ro) { |
101 |
|
|
|
102 |
|
|
$self->{al}->set (editable => 0); |
103 |
|
|
$self->{raw_al}->set (editable => 0); |
104 |
elmex |
1.4 |
$self->{msg_view}->set (editable => 0); |
105 |
|
|
$self->{lore_view}->set (editable => 0); |
106 |
elmex |
1.5 |
$self->{new_attrkey_entry}->set (sensitive => 0); |
107 |
|
|
$self->{new_attrval_entry}->set (sensitive => 0); |
108 |
elmex |
1.3 |
|
109 |
|
|
} else { |
110 |
|
|
|
111 |
|
|
$self->{al}->set (editable => 1); |
112 |
|
|
$self->{raw_al}->set (editable => 1); |
113 |
elmex |
1.4 |
$self->{msg_view}->set (editable => 1); |
114 |
|
|
$self->{lore_view}->set (editable => 1); |
115 |
elmex |
1.5 |
$self->{new_attrkey_entry}->set (sensitive => 1); |
116 |
|
|
$self->{new_attrval_entry}->set (sensitive => 1); |
117 |
elmex |
1.3 |
} |
118 |
|
|
|
119 |
|
|
$self->{al}->set_arch ($arch); |
120 |
|
|
$self->{raw_al}->set_arch ($arch); |
121 |
elmex |
1.4 |
$self->{msg_view}->get_buffer ()->set_text ($arch->{msg}); |
122 |
|
|
$self->{lore_view}->get_buffer ()->set_text ($arch->{lore}); |
123 |
|
|
|
124 |
|
|
$self->{arch_name_lbl}->set_text ( |
125 |
|
|
$arch->{_name} . ($arch->{name} ? " - $arch->{name}" : "") |
126 |
|
|
); |
127 |
|
|
|
128 |
elmex |
1.3 |
my $al_arch = $Crossfire::ARCH->{$arch->{_name}}; |
129 |
|
|
|
130 |
|
|
if ($al_arch) { |
131 |
|
|
|
132 |
|
|
$self->{al_arch}->set_arch ($al_arch); |
133 |
|
|
|
134 |
|
|
} else { |
135 |
elmex |
1.2 |
|
136 |
elmex |
1.3 |
$self->{al_arch}->set_arch ({ noarch => 'noarch' }); |
137 |
|
|
} |
138 |
elmex |
1.2 |
} |
139 |
|
|
|
140 |
elmex |
1.1 |
|
141 |
|
|
=head1 AUTHOR |
142 |
|
|
|
143 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
144 |
|
|
http://home.schmorp.de/ |
145 |
|
|
|
146 |
|
|
Robin Redeker <elmex@ta-sa.org> |
147 |
|
|
http://www.ta-sa.org/ |
148 |
|
|
|
149 |
|
|
=cut |
150 |
|
|
1; |