ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/MainWindow.pm
(Generate patch)

Comparing deliantra/gde/GCE/MainWindow.pm (file contents):
Revision 1.57 by elmex, Sat Apr 1 19:57:41 2006 UTC vs.
Revision 1.58 by elmex, Tue Apr 4 11:29:54 2006 UTC

4 4
5 GCE::MainWindow - the main window class for gce 5 GCE::MainWindow - the main window class for gce
6 6
7=cut 7=cut
8 8
9use Cwd; 9use Cwd qw/abs_path getcwd/;
10use Gtk2; 10use Gtk2;
11use Gtk2::Gdk::Keysyms; 11use Gtk2::Gdk::Keysyms;
12use Gtk2::SimpleMenu; 12use Gtk2::SimpleMenu;
13 13
14use Crossfire; 14use Crossfire;
33 33
34# XXX: make a recursive call from save_layout to all (interesting) sub-widgets 34# XXX: make a recursive call from save_layout to all (interesting) sub-widgets
35sub save_layout { 35sub save_layout {
36 my ($self) = @_; 36 my ($self) = @_;
37 37
38 $main::CFG->{attr_edit_on} = exists $self->{attr_edit} ? 1 : 0; 38# $main::CFG->{attr_edit_on} = exists $self->{attr_edit} ? 1 : 0;
39 $main::CFG->{stack_view_on} = exists $self->{sv} ? 1 : 0; 39 $main::CFG->{stack_view_on} = exists $self->{sv} ? 1 : 0;
40 $main::CFG->{picker_on} = exists $self->{last_pick_window} ? 1 : 0; 40 $main::CFG->{picker_on} = exists $self->{last_pick_window} ? 1 : 0;
41 $main::CFG->{main_window} = main::get_pos_and_size ($self); 41 $main::CFG->{main_window} = main::get_pos_and_size ($self);
42 $main::CFG->{map_window} = main::get_pos_and_size ($self->{last_map_window}) if $self->{last_map_window}; 42 $main::CFG->{map_window} = main::get_pos_and_size ($self->{last_map_window}) if $self->{last_map_window};
43 $main::CFG->{stack_view} = main::get_pos_and_size ($self->{sv_win}) if $self->{sv_win}; 43 $main::CFG->{stack_view} = main::get_pos_and_size ($self->{sv_win}) if $self->{sv_win};
63sub load_layout { 63sub load_layout {
64 my ($self) = @_; 64 my ($self) = @_;
65 65
66 $self->{fc_last_folders} = $main::CFG->{last_folders}; 66 $self->{fc_last_folders} = $main::CFG->{last_folders};
67 67
68 $main::CFG->{attr_edit_on} 68# $main::CFG->{attr_edit_on}
69 and $self->show_attr_editor; 69# and $self->show_attr_editor;
70 70
71 $main::CFG->{stack_view_on} 71 $main::CFG->{stack_view_on}
72 and $self->show_stack_view; 72 and $self->show_stack_view;
73 73
74 for (@{$main::CFG->{open_pickers}}) { 74 for (@{$main::CFG->{open_pickers}}) {
79sub open_map_editor { 79sub open_map_editor {
80 my ($self, $mapfile) = @_; 80 my ($self, $mapfile) = @_;
81 81
82 my $mapkey; 82 my $mapkey;
83 unless (ref $mapfile) { 83 unless (ref $mapfile) {
84 unless (File::Spec->file_name_is_absolute ($mapfile)) { 84# unless (File::Spec->file_name_is_absolute ($mapfile)) {
85 $mapfile = File::Spec->rel2abs ($mapfile); 85# $mapfile = File::Spec->rel2abs ($mapfile);
86 } 86# }
87 $mapkey = abs_path ($mapfile);
87 $mapkey = File::Spec->abs2rel ($mapfile, File::Spec->catfile ($::CFG->{MAPDIR})); 88 # File::Spec->abs2rel ($mapfile, File::Spec->catfile ($::CFG->{MAPDIR}));
89 } else {
90 $mapkey = "$mapfile";
88 } 91 }
89 92
90 # XXX: last_map_window is a dirty trick to get the position and size 93 # XXX: last_map_window is a dirty trick to get the position and size
91 # for save layout 94 # for save layout
92 95
93 unless (ref $mapfile) {
94 if (defined $self->{loaded_maps}->{$mapkey}) { 96 if (defined $self->{loaded_maps}->{$mapkey}) {
95 $self->{loaded_maps}->{$mapkey}->get_toplevel->present; 97 $self->{loaded_maps}->{$mapkey}->get_toplevel->present;
96 return; 98 return;
97 }
98 } 99 }
99 100
100 my $w = $self->{last_map_window} = GCE::MapEditor->new; 101 my $w = $self->{last_map_window} = GCE::MapEditor->new;
101 102
102 $self->{editors}->{$w} = $w; 103 $self->{editors}->{$w} = $w;
106 delete $self->{loaded_maps}->{$w->{mapkey}}; 107 delete $self->{loaded_maps}->{$w->{mapkey}};
107 delete $self->{editors}->{$w}; 108 delete $self->{editors}->{$w};
108 0; 109 0;
109 }); 110 });
110 111
111 unless (ref $mapfile) {
112 unless (-e $mapfile) {
113 quick_msg ("file '$mapfile' does not exist!", 0);
114 return;
115 }
116 $self->{loaded_maps}->{$mapkey} = $w; 112 $self->{loaded_maps}->{$mapkey} = $w;
117 }
118 113
119 $w->open_map ($mapfile, $mapkey); 114 $w->open_map ($mapfile, $mapkey);
120 115
121 ::set_pos_and_size ($w, $main::CFG->{map_window}, 500, 500, 200, 0); 116 ::set_pos_and_size ($w, $main::CFG->{map_window}, 500, 500, 200, 0);
122 117
193} 188}
194 189
195sub show_attr_editor { 190sub show_attr_editor {
196 my ($self) = @_; 191 my ($self) = @_;
197 192
198 return if $self->{attr_edit};
199
200 my $w = $self->{attr_edit_win} = Gtk2::Window->new; 193 my $w = $self->{attr_edit_win} = Gtk2::Window->new;
201 $w->set_title ("gce - edit attrs"); 194 $w->set_title ("gce - edit attrs");
202 $w->add ($self->{attr_edit} = GCE::AttrEdit->new); 195 $w->add ($self->{attr_edit} = GCE::AttrEdit->new);
203 $w->signal_connect (destroy => sub { delete $self->{attr_edit}; 0 }); 196 $w->signal_connect (destroy => sub { Gtk2->main_quit; 0 });
204 197
205 main::set_pos_and_size ($w, $main::CFG->{attr_view}, 200, 200); 198 main::set_pos_and_size ($w, $main::CFG->{attr_view}, 200, 200);
206 199
207 $w->show_all; 200 $w->show_all;
208} 201}
209 202
210sub update_attr_editor { 203sub update_attr_editor {
211 my ($self, $arch, $cb) = @_; 204 my ($self, $arch, $cb) = @_;
212 205
213 return unless $self->{attr_edit}; 206 $self->{attr_edit}
207 or die "SERIOUS BUG: Couldn't find attribut editor!";
214 208
215 $self->{attr_edit}->set_arch ($arch, $cb); 209 $self->{attr_edit}->set_arch ($arch, $cb);
216 $self->{attr_edit_win}->set_title ("gce - edit $arch->{_name}"); 210 $self->{attr_edit_win}->set_title ("gce - edit $arch->{_name}");
217} 211}
218 212
278 ] 272 ]
279 }, 273 },
280 _Dialogs => { 274 _Dialogs => {
281 item_type => '<Branch>', 275 item_type => '<Branch>',
282 children => [ 276 children => [
283 "_Attr Editor" => {
284 callback => sub { $self->show_attr_editor },
285 accelerator => "<ctrl>A"
286 },
287 "_Picker" => { 277 "_Picker" => {
288 callback => sub { $self->open_pick_window }, 278 callback => sub { $self->open_pick_window },
289 accelerator => "<ctrl>P" 279 accelerator => "<ctrl>P"
290 }, 280 },
291 "_Stack View" => { 281 "_Stack View" => {
432 $self->{edit_tool_cont} = Gtk2::VBox->new; 422 $self->{edit_tool_cont} = Gtk2::VBox->new;
433 423
434 $self->add (my $vb = Gtk2::VBox->new); 424 $self->add (my $vb = Gtk2::VBox->new);
435 $vb->pack_start ($self->build_menu, 0, 1, 0); 425 $vb->pack_start ($self->build_menu, 0, 1, 0);
436 426
437 $vb->pack_start (my $hb = $self->{pick_view_hb} = Gtk2::HBox->new, 0, 1, 0); 427# $vb->pack_start (my $hb = $self->{pick_view_hb} = Gtk2::HBox->new, 0, 1, 0);
438 $hb->pack_start ($self->{pick_view_img} = Gtk2::Image->new, 0, 1, 0); 428# $hb->pack_start ($self->{pick_view_img} = Gtk2::Image->new, 0, 1, 0);
439 $hb->pack_start ($self->{pick_view_btn} = Gtk2::Button->new, 0, 1, 0); 429# $hb->pack_start ($self->{pick_view_btn} = Gtk2::Button->new, 0, 1, 0);
440 GCE::DragHelper::set_drag_source ( 430# GCE::DragHelper::set_drag_source (
441 $self->{pick_view_btn}, arch => sub { { arch => $self->get_pick } } 431# $self->{pick_view_btn}, arch => sub { { arch => $self->get_pick } }
442 ); 432# );
443 GCE::DragHelper::set_drag_sink ( 433# GCE::DragHelper::set_drag_sink (
444 $self->{pick_view_btn}, arch => sub { $self->set_pick ($_[0]->{arch}) } 434# $self->{pick_view_btn}, arch => sub { $self->set_pick ($_[0]->{arch}) }
445 ); 435# );
446 $self->{pick_view_btn}->signal_connect (clicked => sub { 436# $self->{pick_view_btn}->signal_connect (clicked => sub {
447 $self->update_attr_editor ($self->{pick_arch}); 437# $self->update_attr_editor ($self->{pick_arch});
448 }); 438# });
449 $self->{pick_view_pb} = new_arch_pb (); 439# $self->{pick_view_pb} = new_arch_pb ();
450 440
451 $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); 441# $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0);
452 $vb->pack_start (my $tbl = $self->build_buttons, 0, 1, 0); 442 $vb->pack_start (my $tbl = $self->build_buttons, 0, 1, 0);
453 443
454 $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0); 444 $vb->pack_start (Gtk2::HSeparator->new, 0, 1, 0);
455 $vb->pack_start ($self->{edit_tool}, 0, 1, 0); 445 $vb->pack_start ($self->{edit_tool}, 0, 1, 0);
456 446
464 $self->signal_connect ('delete-event' => sub { 454 $self->signal_connect ('delete-event' => sub {
465 Gtk2->main_quit; 455 Gtk2->main_quit;
466 }); 456 });
467 457
468 ::set_pos_and_size ($self, $main::CFG->{main_window}, 150, 200, 0, 0); 458 ::set_pos_and_size ($self, $main::CFG->{main_window}, 150, 200, 0, 0);
459
460
461 $self->show_attr_editor;
469} 462}
470 463
471sub new_cb { 464sub new_cb {
472 my ($self) = @_; 465 my ($self) = @_;
473 466
523 } 516 }
524 517
525 $fc->destroy; 518 $fc->destroy;
526} 519}
527 520
528sub set_pick { 521#sub set_pick {
529 my ($self, $arch) = @_; 522# my ($self, $arch) = @_;
530 523#
531 $self->{pick_arch} = $arch; 524# $self->{pick_arch} = $arch;
532 $self->update_pick_view ($arch); 525# $self->update_pick_view ($arch);
533} 526#}
534 527
535sub get_pick { 528sub get_pick {
536 my ($self) = @_; 529 my ($self) = @_;
537 530
531 $self->{attr_edit}
532 or die "Couldn't find attribute editor! SERIOUS BUG!";
533
538 # XXX: This is just to make sure that this function always returns something 534 # XXX: This is just to make sure that this function always returns something
539 return $self->{pick_arch} || { _name => 'platinacoin' }; 535 return $self->{attr_edit}->get_arch || { _name => 'platinacoin' };
540} 536}
541 537
542=head1 AUTHOR 538=head1 AUTHOR
543 539
544 Marc Lehmann <schmorp@schmorp.de> 540 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines