ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/AttrEdit.pm
Revision: 1.4
Committed: Thu Feb 9 18:04:43 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.3: +38 -6 lines
Log Message:
improved attribute editor

File Contents

# User Rev Content
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    
25 elmex 1.3 my $al = $self->{al} = GCE::AttrList->new (editable => 1, raw => 0);
26 elmex 1.4 $ntbook->append_page ($al, "obj attrs");
27 elmex 1.3 $al->set_arch_cb (sub { $self->update_arch (@_) });
28    
29     $al = $self->{raw_al} = GCE::AttrList->new (editable => 1);
30 elmex 1.4 $ntbook->append_page ($al, "raw attrs");
31 elmex 1.3 $al->set_arch_cb (sub { $self->update_arch (@_) });
32    
33     $al = $self->{al_arch} = GCE::AttrList->new (editable => 0);
34 elmex 1.4 $ntbook->append_page ($al, "arch attrs");
35 elmex 1.3 $al->set_arch_cb (sub { $self->update_arch (@_) });
36 elmex 1.4
37     # XXX: Implement autosave!
38     for my $type (qw/lore msg/) {
39    
40     $ntbook->append_page (my $vb = Gtk2::VBox->new, $type);
41     $vb->pack_start (my $txtv = $self->{"${type}_view"} = Gtk2::TextView->new, 1, 1, 0);
42     $vb->pack_start (my $btn = Gtk2::Button->new_with_label ("save $type"), 0, 1, 0);
43     $btn->signal_connect (clicked => sub {
44    
45     my $txtbuf = $txtv->get_buffer;
46    
47     my ($start_iter, $end_iter) = ($txtbuf->get_start_iter, $txtbuf->get_end_iter);
48     my $txt = $txtv->get_buffer ()->get_text ($start_iter, $end_iter, 0);
49    
50     $self->update_arch ($self->{arch}, $type, $txt);
51     });
52     }
53 elmex 1.3 }
54    
55     sub update_arch {
56     my ($self, $arch, $key, $value) = @_;
57    
58     if ($value ne '') {
59    
60     $arch->{$key} = $value;
61    
62     } else {
63    
64     delete $arch->{$key};
65     }
66 elmex 1.1
67 elmex 1.4 # XXX: maybe update a little bit more intelligent...
68 elmex 1.3 $self->set_arch ($arch);
69 elmex 1.1 }
70    
71 elmex 1.2 sub set_arch {
72 elmex 1.3 my ($self, $arch, $ro) = @_;
73    
74 elmex 1.4 $self->{arch} = $arch;
75    
76 elmex 1.3 if ($ro) {
77    
78     $self->{al}->set (editable => 0);
79     $self->{raw_al}->set (editable => 0);
80 elmex 1.4 $self->{msg_view}->set (editable => 0);
81     $self->{lore_view}->set (editable => 0);
82 elmex 1.3
83     } else {
84    
85     $self->{al}->set (editable => 1);
86     $self->{raw_al}->set (editable => 1);
87 elmex 1.4 $self->{msg_view}->set (editable => 1);
88     $self->{lore_view}->set (editable => 1);
89 elmex 1.3 }
90    
91     $self->{al}->set_arch ($arch);
92     $self->{raw_al}->set_arch ($arch);
93 elmex 1.4 $self->{msg_view}->get_buffer ()->set_text ($arch->{msg});
94     $self->{lore_view}->get_buffer ()->set_text ($arch->{lore});
95    
96     $self->{arch_name_lbl}->set_text (
97     $arch->{_name} . ($arch->{name} ? " - $arch->{name}" : "")
98     );
99    
100 elmex 1.3 my $al_arch = $Crossfire::ARCH->{$arch->{_name}};
101    
102     if ($al_arch) {
103    
104     $self->{al_arch}->set_arch ($al_arch);
105    
106     } else {
107 elmex 1.2
108 elmex 1.3 $self->{al_arch}->set_arch ({ noarch => 'noarch' });
109     }
110 elmex 1.2 }
111    
112 elmex 1.1
113     =head1 AUTHOR
114    
115     Marc Lehmann <schmorp@schmorp.de>
116     http://home.schmorp.de/
117    
118     Robin Redeker <elmex@ta-sa.org>
119     http://www.ta-sa.org/
120    
121     =cut
122     1;