Author: tian
Date: Sun Apr 10 22:53:58 2016
New Revision: 2277

URL: http://svn.gna.org/viewcvs/gcstar?rev=2277&view=rev
Log:
Fixed a few bugs with picture list and implemented the removal

Modified:
    trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm
    trunk/gcstar/lib/gcstar/GCOptions.pm

Modified: trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm
URL: 
http://svn.gna.org/viewcvs/gcstar/trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm?rev=2277&r1=2276&r2=2277&view=diff
==============================================================================
--- trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm     
(original)
+++ trunk/gcstar/lib/gcstar/GCGraphicComponents/GCPictureWidgets.pm     Sun Apr 
10 22:53:58 2016
@@ -722,6 +722,16 @@
         $itemOpenWith->set_sensitive(0) if $self->isDefaultImage();
 
         $self->{imgContext}->append($itemOpenWith);
+        
+        if (exists $self->{extraStock})
+        {
+            $self->{imgContext}->append(Gtk2::SeparatorMenuItem->new);
+            $self->{extraMenu} = 
Gtk2::ImageMenuItem->new_from_stock($self->{extraStock}, undef);
+            $self->{extraMenu}->set_sensitive(!$self->{locked});
+            $self->{extraMenu}->signal_connect('activate' => 
$self->{extraCallback});
+            $self->{imgContext}->append($self->{extraMenu});
+        }
+        
         $self->{imgContext}->show_all;
 
     }
@@ -732,6 +742,13 @@
         $self->{trackState} = 1;
     }
 
+    sub addCallbackWithStock
+    {
+        my ($self, $stock, $callback) = @_;
+        $self->{extraStock} = $stock;
+        $self->{extraCallback} = $callback;
+    }
+    
     sub lock
     {
         my ($self, $locked) = @_;
@@ -886,43 +903,43 @@
                 $self->setChanged;
                 $self->forceDisplay;                
             });
-            $self->{removeButton} = GCButton->newFromStock('gtk-remove', 0);
+            #$self->{removeButton} = GCButton->newFromStock('gtk-remove', 0);
             $hboxActions->pack_start($self->{addButton}, 0, 0, 6);
-            $hboxActions->pack_start($self->{removeButton}, 0, 0, 6);
+            #$hboxActions->pack_start($self->{removeButton}, 0, 0, 6);
         }
         else
         {
-            $self->{removeButton} = GCButton->newFromStock('gtk-remove', 0);
-            $self->{clearButton} = GCButton->newFromStock('gtk-clear', 0);
-            $self->{clearButton}->signal_connect('clicked' => sub {
-                $self->clear;
-            });            
-            $hboxActions->pack_start($self->{removeButton}, 1, 0, 6);
-            $hboxActions->pack_start($self->{clearButton}, 1, 0, 6);
+            #$self->{removeButton} = GCButton->newFromStock('gtk-remove', 0);
+            #$self->{clearButton} = GCButton->newFromStock('gtk-clear', 0);
+            #$self->{clearButton}->signal_connect('clicked' => sub {
+            #    $self->clear;
+            #});            
+            #$hboxActions->pack_start($self->{removeButton}, 1, 0, 6);
+            #$hboxActions->pack_start($self->{clearButton}, 1, 0, 6);
         }
         $self->pack_start($hboxActions, 0, 0, 6)
             if $readonly < 2;
 
-        $self->{removeButton}->signal_connect('clicked' => sub {
-            my @idx = $self->{list}->get_selected_indices;
-            my $selected = $idx[0];
-            splice @{$self->{list}->{data}}, $selected, 1;
-            $selected-- if ($selected >= scalar(@{$self->{list}->{data}}));
-            $selected = 0 if $selected < 0 ;
-            $self->{list}->select($selected);
-        });
-        
-        $self->{list}->signal_connect('key-press-event' => sub {
-            my ($widget, $event) = @_;
-            my $key = Gtk2::Gdk->keyval_name($event->keyval);
-            if ((!$self->{readonly}) && ($key eq 'Delete'))
-            {
-                $self->{removeButton}->activate;
-                return 1;
-            }
-            # Let key be managed by Gtk2
-            return 0;
-        });
+        #$self->{removeButton}->signal_connect('clicked' => sub {
+        #    my @idx = $self->{list}->get_selected_indices;
+        #    my $selected = $idx[0];
+        #    splice @{$self->{list}->{data}}, $selected, 1;
+        #    $selected-- if ($selected >= scalar(@{$self->{list}->{data}}));
+        #    $selected = 0 if $selected < 0 ;
+        #    $self->{list}->select($selected);
+        #});
+        
+        #$self->{list}->signal_connect('key-press-event' => sub {
+        #    my ($widget, $event) = @_;
+        #    my $key = Gtk2::Gdk->keyval_name($event->keyval);
+        #    if ((!$self->{readonly}) && ($key eq 'Delete'))
+        #    {
+        #        $self->{removeButton}->activate;
+        #        return 1;
+        #    }
+        #    # Let key be managed by Gtk2
+        #    return 0;
+        #});
         
 
         #$self->pack_start($self->{box},1,$self->{readonly},0);
@@ -991,7 +1008,9 @@
         $colWhereToAdd = $nbChildren % $self->{itemsPerRow};
         $self->{list}->attach($widget, $colWhereToAdd, $colWhereToAdd + 1, 
$lineWhereToAdd, $lineWhereToAdd + 1,
                               ['fill', 'expand'], ['fill'], 0, 0);
-
+        $widget->addCallbackWithStock('gtk-remove' => sub {
+            $self->removeImage($widget);
+        });
 
 
 
@@ -1026,6 +1045,51 @@
 
         return $widget;
     }
+    
+    sub coordToIdx
+    {
+        my ($self, $line, $col) = @_;
+        return ($line * $self->{itemsPerRow}) + $col;
+    }
+    
+    sub idxToCoord
+    {
+        my ($self, $idx) = @_;
+        my ($line, $col);
+        $line = int($idx / $self->{itemsPerRow});
+        $col = $idx % $self->{itemsPerRow};
+        return ($line, $col);
+    }
+    
+    sub removeImage
+    {
+        my ($self, $imgToRemove) = @_;
+        #print "REMOVING $line : $col\n";
+        
+        my @imgs = $self->getOrderedChildren;
+        my $imgIdx = 0;
+        #print "IDX : $imgIdx\n";
+        #$self->{list}->remove($imgs[$imgIdx]);
+        #$imgIdx++;
+        my $found = 0;
+        while ($imgIdx <= $#imgs)
+        {
+            if ($found)
+            {
+                $self->{list}->remove($imgs[$imgIdx]);
+                my ($newLine, $newCol) = $self->idxToCoord($imgIdx - 1);
+                $self->{list}->attach($imgs[$imgIdx], $newCol, $newCol + 1, 
$newLine, $newLine + 1,
+                                      ['fill', 'expand'], ['fill'], 0, 0);
+            }
+            elsif ($imgs[$imgIdx] == $imgToRemove)
+            {
+                $found = 1;
+                $self->{list}->remove($imgs[$imgIdx]);
+            }
+            $imgIdx++;
+        }
+        $self->setChanged;
+    }
 
     sub isEmpty
     {
@@ -1034,18 +1098,34 @@
         return $self->getValue eq '';
     }
     
-    sub getValue
-    {
-        my $self = shift;
-#        my $formated = shift;
-
-        my @value;
+    sub getOrderedChildren
+    {
+        my $self = shift;
+        my @orderedChildren;
         #get_children doesn't return items in order. It seems to be in reverse 
order
         #but to be sure, we just compute its rank in the array based on 
coordinates.
         for my $img($self->{list}->get_children)
         {
-            my ($x, $y) = $self->{list}->child_get($img, qw(left-attach 
top-attach));
-            $value[($y * $self->{itemsPerRow}) + $x] = [$img->getValue];
+            my ($col, $line) = $self->{list}->child_get($img, qw(left-attach 
top-attach));
+            $orderedChildren[$self->coordToIdx($line, $col)] = $img;
+        }
+        return @orderedChildren;        
+    }
+    
+    sub getValue
+    {
+        my $self = shift;
+#        my $formated = shift;
+
+        my @value;
+         #for my $img($self->{list}->get_children)
+        #{
+        #    my ($x, $y) = $self->{list}->child_get($img, qw(left-attach 
top-attach));
+        #    $value[($y * $self->{itemsPerRow}) + $x] = [$img->getValue];
+        #}
+        for my $img($self->getOrderedChildren)
+        {
+            push @value, [$img->getValue]
         }
         
         return \@value;

Modified: trunk/gcstar/lib/gcstar/GCOptions.pm
URL: 
http://svn.gna.org/viewcvs/gcstar/trunk/gcstar/lib/gcstar/GCOptions.pm?rev=2277&r1=2276&r2=2277&view=diff
==============================================================================
--- trunk/gcstar/lib/gcstar/GCOptions.pm        (original)
+++ trunk/gcstar/lib/gcstar/GCOptions.pm        Sun Apr 10 22:53:58 2016
@@ -1605,7 +1605,7 @@
         foreach (@{$self->{fields}})
         {
             my $isShown = 0;
-            $isShown = 1 if $self->{$_}->get_active;
+            $isShown = 1 if $self->{$_} && $self->{$_}->get_active;
             $self->{show}->{$_} = $isShown;
             $hidden .= $_.'|' if !$isShown;
         }


_______________________________________________
GCstar-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gcstar-commits

Reply via email to