--- deliantra/gde/GCE/StackView.pm 2006/03/19 19:30:38 1.11 +++ deliantra/gde/GCE/StackView.pm 2006/04/04 23:21:17 1.15 @@ -18,6 +18,8 @@ use Glib::Object::Subclass Gtk2::VBox; +use Storable qw/dclone/; + use strict; sub INIT_INSTANCE { @@ -43,6 +45,7 @@ for (reverse @$stack) { # FIXME: How to change a stack with a virtual arch???? next if $_->{_virtual}; + my $ownidx = $idx; #my $a = $_->{_virtual} || $_; my $a = $_; @@ -54,9 +57,6 @@ $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); - do { - my $ownidx = $idx; - $delbtn->signal_connect (clicked => sub { #my $oldstack = [ @$stack ]; @@ -68,23 +68,27 @@ # XXX: force an update ? maybe some more intelligent update later? $self->set_stack ($mapedit, $x, $y); }); - }; $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); $elemhdl->add (my $hb2 = Gtk2::HBox->new); $elemhdl->signal_connect (clicked => sub { - $::MAINWIN->set_pick ($a); - $::MAINWIN->update_attr_editor ($a, sub { - $mapedit->change_begin (ref $self); - $mapedit->change_stack ($x, $y, $stack); - # XXX: Put this into a generic function!!! See also EditTools.pm - # FIXME: Fix the automatic update on undo here! - if (my $changeset = $mapedit->change_end) { - splice @{ $mapedit->{undo_stack} ||= [] }, - $mapedit->{undo_stack_pos}++, 1e6, - $changeset; - } - }); + my $ar = + GCE::ArchRef->new ( + arch => $a, + cb => sub { + $mapedit->change_begin (ref $self); + $mapedit->change_stack ($x, $y, $stack); + # XXX: Put this into a generic function!!! See also EditTools.pm + # FIXME: Fix the automatic update on undo here! + if (my $changeset = $mapedit->change_end) { + splice @{ $mapedit->{undo_stack} ||= [] }, + $mapedit->{undo_stack_pos}++, 1e6, + $changeset; + } + } + ); + + $::MAINWIN->update_attr_editor ($ar) }); $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); @@ -100,46 +104,35 @@ { target => 'STRING', flags => [], info => 'TARGET_STRING' } ); - do { - my $ownidx = $idx; - - $elemhdl->signal_connect (drag_data_get => sub { - my ($widget, $context, $data, $info, $time) = @_; - - $data->set ($data->target, 8, "stack:$ownidx"); - }); - - # XXX: I'm unsure here, do i have to issue a get request? - # And what if i get the data twice? Wait for transaction end? - $elemhdl->signal_connect (drag_data_received => sub { - my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; - - if (($data->length >= 0) && ($data->format == 8)) { - - $context->finish (1, 0, $time); - - if ($data->data =~ m/stack:(\d+)/) { - my $swapidx = int $1; - - ($stack->[$swapidx], $stack->[$ownidx]) - = ($stack->[$ownidx], $stack->[$swapidx]); - - # XXX: Insert undo here! - $mapedit->set ($x, $y, $stack); - - $self->set_stack ($mapedit, $x, $y); - } - - return; - } - $context->finish (0, 0, $time); - }); - }; + GCE::DragHelper::set_drag_source ( + $elemhdl, arch => sub { + { arch => $stack->[$ownidx], stk => $stack, stk_idx => $ownidx } + } + ); + + GCE::DragHelper::set_drag_sink ( + $elemhdl, arch => sub { + my ($darch) = @_; + + if (defined $darch->{stk_idx} and $darch->{stk} == $stack) { + my $swapidx = $darch->{stk_idx}; + ($stack->[$swapidx], $stack->[$ownidx]) + = ($stack->[$ownidx], $stack->[$swapidx]); + + } else { + splice @$stack, $ownidx, 1, (dclone $darch->{arch}); + } + + # XXX: Insert undo here! + $mapedit->set ($x, $y, $stack); + + $self->set_stack ($mapedit, $x, $y); + } + ); $idx--; } } $self->show_all; - } =head1 AUTHOR