… | |
… | |
15 | |
15 | |
16 | use GCE::AttrEdit; |
16 | use GCE::AttrEdit; |
17 | use GCE::Util; |
17 | use GCE::Util; |
18 | |
18 | |
19 | use Glib::Object::Subclass Gtk2::VBox; |
19 | use Glib::Object::Subclass Gtk2::VBox; |
|
|
20 | |
|
|
21 | use Storable qw/dclone/; |
20 | |
22 | |
21 | use strict; |
23 | use strict; |
22 | |
24 | |
23 | sub INIT_INSTANCE { |
25 | sub INIT_INSTANCE { |
24 | my ($self) = @_; |
26 | my ($self) = @_; |
… | |
… | |
41 | |
43 | |
42 | if ($stack) { |
44 | if ($stack) { |
43 | for (reverse @$stack) { |
45 | for (reverse @$stack) { |
44 | # FIXME: How to change a stack with a virtual arch???? |
46 | # FIXME: How to change a stack with a virtual arch???? |
45 | next if $_->{_virtual}; |
47 | next if $_->{_virtual}; |
|
|
48 | my $ownidx = $idx; |
46 | |
49 | |
47 | #my $a = $_->{_virtual} || $_; |
50 | #my $a = $_->{_virtual} || $_; |
48 | my $a = $_; |
51 | my $a = $_; |
49 | |
52 | |
50 | # this is awful, is this really the best way? |
53 | # this is awful, is this really the best way? |
… | |
… | |
52 | |
55 | |
53 | fill_pb_from_arch ($pb, $a); |
56 | fill_pb_from_arch ($pb, $a); |
54 | |
57 | |
55 | $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
58 | $self->{stackbox}->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
56 | $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); |
59 | $hb->pack_start (my $delbtn = Gtk2::Button->new_with_label ('del'), 0, 0, 0); |
57 | do { |
|
|
58 | my $ownidx = $idx; |
|
|
59 | |
|
|
60 | $delbtn->signal_connect (clicked => sub { |
60 | $delbtn->signal_connect (clicked => sub { |
61 | |
61 | |
62 | #my $oldstack = [ @$stack ]; |
62 | #my $oldstack = [ @$stack ]; |
63 | splice @$stack, $ownidx, 1; |
63 | splice @$stack, $ownidx, 1; |
64 | |
64 | |
… | |
… | |
66 | $mapedit->set ($x, $y, $stack); |
66 | $mapedit->set ($x, $y, $stack); |
67 | |
67 | |
68 | # XXX: force an update ? maybe some more intelligent update later? |
68 | # XXX: force an update ? maybe some more intelligent update later? |
69 | $self->set_stack ($mapedit, $x, $y); |
69 | $self->set_stack ($mapedit, $x, $y); |
70 | }); |
70 | }); |
71 | }; |
|
|
72 | |
71 | |
73 | $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
72 | $hb->pack_start (my $elemhdl = new Gtk2::Button, 0, 0, 0); |
74 | $elemhdl->add (my $hb2 = Gtk2::HBox->new); |
73 | $elemhdl->add (my $hb2 = Gtk2::HBox->new); |
75 | $elemhdl->signal_connect (clicked => sub { |
74 | $elemhdl->signal_connect (clicked => sub { |
76 | $::MAINWIN->set_pick ($a); |
75 | my $ar = |
77 | $::MAINWIN->update_attr_editor ($a, sub { |
76 | GCE::ArchRef->new ( |
|
|
77 | arch => $a, |
|
|
78 | cb => sub { |
78 | $mapedit->change_begin (ref $self); |
79 | $mapedit->change_begin (ref $self); |
79 | $mapedit->change_stack ($x, $y, $stack); |
80 | $mapedit->change_stack ($x, $y, $stack); |
80 | # XXX: Put this into a generic function!!! See also EditTools.pm |
81 | # XXX: Put this into a generic function!!! See also EditTools.pm |
81 | # FIXME: Fix the automatic update on undo here! |
82 | # FIXME: Fix the automatic update on undo here! |
82 | if (my $changeset = $mapedit->change_end) { |
83 | if (my $changeset = $mapedit->change_end) { |
83 | splice @{ $mapedit->{undo_stack} ||= [] }, |
84 | splice @{ $mapedit->{undo_stack} ||= [] }, |
84 | $mapedit->{undo_stack_pos}++, 1e6, |
85 | $mapedit->{undo_stack_pos}++, 1e6, |
85 | $changeset; |
86 | $changeset; |
|
|
87 | } |
86 | } |
88 | } |
87 | }); |
89 | ); |
|
|
90 | |
|
|
91 | $::MAINWIN->update_attr_editor ($ar) |
88 | }); |
92 | }); |
89 | |
93 | |
90 | $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
94 | $hb2->pack_start (my $img = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
91 | $img->set_alignment (0, 0.5); |
95 | $img->set_alignment (0, 0.5); |
92 | |
96 | |
… | |
… | |
98 | ); |
102 | ); |
99 | $elemhdl->drag_dest_set (all => ['move'], |
103 | $elemhdl->drag_dest_set (all => ['move'], |
100 | { target => 'STRING', flags => [], info => 'TARGET_STRING' } |
104 | { target => 'STRING', flags => [], info => 'TARGET_STRING' } |
101 | ); |
105 | ); |
102 | |
106 | |
|
|
107 | GCE::DragHelper::set_drag_source ( |
|
|
108 | $elemhdl, arch => sub { |
|
|
109 | { arch => $stack->[$ownidx], stk => $stack, stk_idx => $ownidx } |
103 | do { |
110 | } |
104 | my $ownidx = $idx; |
111 | ); |
105 | |
112 | |
106 | $elemhdl->signal_connect (drag_data_get => sub { |
113 | GCE::DragHelper::set_drag_sink ( |
107 | my ($widget, $context, $data, $info, $time) = @_; |
114 | $elemhdl, arch => sub { |
|
|
115 | my ($darch) = @_; |
108 | |
116 | |
109 | $data->set ($data->target, 8, "stack:$ownidx"); |
117 | if (defined $darch->{stk_idx} and $darch->{stk} == $stack) { |
110 | }); |
118 | my $swapidx = $darch->{stk_idx}; |
|
|
119 | ($stack->[$swapidx], $stack->[$ownidx]) |
|
|
120 | = ($stack->[$ownidx], $stack->[$swapidx]); |
111 | |
121 | |
112 | # XXX: I'm unsure here, do i have to issue a get request? |
122 | } else { |
113 | # And what if i get the data twice? Wait for transaction end? |
123 | splice @$stack, $ownidx, 1, (dclone $darch->{arch}); |
114 | $elemhdl->signal_connect (drag_data_received => sub { |
124 | } |
115 | my ($widget, $context, $wx, $wy, $data, $info, $time) = @_; |
|
|
116 | |
125 | |
117 | if (($data->length >= 0) && ($data->format == 8)) { |
126 | # XXX: Insert undo here! |
|
|
127 | $mapedit->set ($x, $y, $stack); |
118 | |
128 | |
119 | $context->finish (1, 0, $time); |
|
|
120 | |
|
|
121 | if ($data->data =~ m/stack:(\d+)/) { |
|
|
122 | my $swapidx = int $1; |
|
|
123 | |
|
|
124 | ($stack->[$swapidx], $stack->[$ownidx]) |
|
|
125 | = ($stack->[$ownidx], $stack->[$swapidx]); |
|
|
126 | |
|
|
127 | # XXX: Insert undo here! |
|
|
128 | $mapedit->set ($x, $y, $stack); |
|
|
129 | |
|
|
130 | $self->set_stack ($mapedit, $x, $y); |
129 | $self->set_stack ($mapedit, $x, $y); |
131 | } |
|
|
132 | |
|
|
133 | return; |
|
|
134 | } |
|
|
135 | $context->finish (0, 0, $time); |
|
|
136 | }); |
|
|
137 | }; |
130 | } |
|
|
131 | ); |
138 | $idx--; |
132 | $idx--; |
139 | } |
133 | } |
140 | } |
134 | } |
141 | $self->show_all; |
135 | $self->show_all; |
142 | |
|
|
143 | } |
136 | } |
144 | |
137 | |
145 | =head1 AUTHOR |
138 | =head1 AUTHOR |
146 | |
139 | |
147 | Marc Lehmann <schmorp@schmorp.de> |
140 | Marc Lehmann <schmorp@schmorp.de> |