Permalink
Browse files

removing given/when

  • Loading branch information...
1 parent 87a6bbf commit 1db1a93953096f5ec463ae6e43a09fc802e39239 @bart9h committed Jan 27, 2014
Showing with 199 additions and 209 deletions.
  1. +15 −13 src/Menu.pm
  2. +41 −41 src/Picture.pm
  3. +9 −10 src/Tags.pm
  4. +40 −42 src/Text.pm
  5. +26 −28 src/View.pm
  6. +68 −75 src/main.pm
View
@@ -56,19 +56,21 @@ sub do
my $N = scalar @{$self->{items}};
$self->{activated} = undef;
- given ($command) {
- when (/^(k|up)$/) { $self->{cursor}-- }
- when (/^(j|down)$/) { $self->{cursor}++ }
- when (/^(g-g|home)$/) { $self->{cursor} = 0 }
- when (/^(end)$/) { $self->{cursor} = $N - 1 }
- when (/^(q|escape|close)$/) { $self->leave }
- when (/^shift-([a-z0-9])$/) { $self->pvt__jump($1) }
- when (/^(l|space|enter|return)$/) {
- $self->{activated} = $self->{items}->[$self->{cursor}];
- }
- default {
- return 0;
- }
+ if ($command =~ /^(k|up)$/) { $self->{cursor}-- }
+ elsif ($command =~ /^(j|down)$/) { $self->{cursor}++ }
+ elsif ($command =~ /^(g-g|home)$/) { $self->{cursor} = 0 }
+ elsif ($command =~ /^(end)$/) { $self->{cursor} = $N - 1 }
+ elsif ($command =~ /^(q|escape|close)$/) {
+ $self->leave;
+ }
+ elsif ($command =~ /^shift-([a-z0-9])$/) {
+ $self->pvt__jump($1);
+ }
+ elsif ($command =~ /^(l|space|enter|return)$/) {
+ $self->{activated} = $self->{items}->[$self->{cursor}];
+ }
+ else {
+ return 0;
}
$self->{cursor} = 0 if $self->{cursor} < 0;
View
@@ -81,52 +81,52 @@ sub develop
my $file = $self->guess_source($app) or return;
my $cmd;
- given ($file) {
- when (/\.ufraw$/i) {
- $cmd = "ufraw \"$file\" || gvim \"$file\"";
- }
- when (/\.cr2$/i) {
- $cmd = "ufraw \"$file\"";
- }
- when (is_pic($file)) {
- $cmd = "gimp \"$file\" &";
- }
+ if ($file =~ /\.ufraw$/i) {
+ $cmd = "ufraw \"$file\" || gvim \"$file\"";
+ }
+ elsif ($file =~ /\.cr2$/i) {
+ $cmd = "ufraw \"$file\"";
+ }
+ elsif (is_pic($file)) {
+ $cmd = "gimp \"$file\" &";
+ }
+ else {
+ return;
}
- if (defined $cmd) {
- say $cmd if dbg;
-
- my $ppm = $file; $ppm =~ s/\.[^.]+$/\.ppm/;
- my $M0 = -M $ppm;
-
- system $cmd;
-
- if ($cmd =~ /^ufraw /) {
- my $jpg = $file; $jpg =~ s/\.[^.]+$/\.jpg/;
- my $cr2 = $file; $cr2 =~ s/\.[^.]+$/\.cr2/;
- my $M1 = -M $ppm;
- if ($M1 and (not $M0 or $M0 != $M1)) { # new .ppm was created
- if (-s $jpg) { # jpg already exists
- if (-w $jpg) { # if it's writeable, remove
- unlink $jpg and say "removed \"$jpg\"";
+
+ say $cmd if dbg;
+
+ my $ppm = $file; $ppm =~ s/\.[^.]+$/\.ppm/;
+ my $M0 = -M $ppm;
+
+ system $cmd;
+
+ if ($cmd =~ /^ufraw /) {
+ my $jpg = $file; $jpg =~ s/\.[^.]+$/\.jpg/;
+ my $cr2 = $file; $cr2 =~ s/\.[^.]+$/\.cr2/;
+ my $M1 = -M $ppm;
+ if ($M1 and (not $M0 or $M0 != $M1)) { # new .ppm was created
+ if (-s $jpg) { # jpg already exists
+ if (-w $jpg) { # if it's writeable, remove
+ unlink $jpg and say "removed \"$jpg\"";
+ }
+ else { # if read-only, backup
+ my $bk = $jpg; $bk =~ s/jpg$/original.jpg/;
+ if (-s $bk and not -w $bk) { # backup already exists
+ unlink $jpg and say "\"$bk\" exists, \"$jpg\" removed";
}
- else { # if read-only, backup
- my $bk = $jpg; $bk =~ s/jpg$/original.jpg/;
- if (-s $bk and not -w $bk) { # backup already exists
- unlink $jpg and say "\"$bk\" exists, \"$jpg\" removed";
- }
- else { # create backup
- unlink $bk and say "\"$bk\" removed" if -e $bk;
- rename $jpg, $bk and say "\"$jpg\" -> \"$bk\"";
- }
+ else { # create backup
+ unlink $bk and say "\"$bk\" removed" if -e $bk;
+ rename $jpg, $bk and say "\"$jpg\" -> \"$bk\"";
}
}
- -e $jpg and die "\"$jpg\" still exists";
- $cmd = "convert -sharpen 3x1 -quality 90 \"$ppm\" \"$jpg\" && exiftool -tagsFromFile \"$cr2\" \"$jpg\"";
- my $base = $jpg; $base =~ s{/([^/]+)$}{$1};
- $cmd = "($cmd && rm -v \"$ppm\" && notify-send \"$base\") &";
- say $cmd;
- system $cmd;
}
+ -e $jpg and die "\"$jpg\" still exists";
+ $cmd = "convert -sharpen 3x1 -quality 90 \"$ppm\" \"$jpg\" && exiftool -tagsFromFile \"$cr2\" \"$jpg\"";
+ my $base = $jpg; $base =~ s{/([^/]+)$}{$1};
+ $cmd = "($cmd && rm -v \"$ppm\" && notify-send \"$base\") &";
+ say $cmd;
+ system $cmd;
}
}
}#
View
@@ -92,16 +92,15 @@ sub repeat_last_edit
{my ($self) = @_;
foreach my $tag (keys %{$singleton{last_edit}}) {
- given ($singleton{last_edit}->{$tag}) {
- when (1) {
- $self->{tags}->{$tag} = 1;
- }
- when (0) {
- delete $self->{tags}->{$tag};
- }
- default {
- die;
- }
+ my $t = $singleton{last_edit}->{$tag};
+ if ($t == 1) {
+ $self->{tags}->{$tag} = 1;
+ }
+ elsif ($t == 0) {
+ delete $self->{tags}->{$tag};
+ }
+ else {
+ die;
}
}
View
@@ -75,57 +75,55 @@ sub print
my $color = $self->{white};
for (my $i = 0; $i < $#args; $i += 2) {
my ($cmd, $arg) = ($args[$i], $args[$i+1]);
- given ($cmd) {
- when (/font/) {
- $self->{font} = $arg;
- }
- when (/color/) {
- $color = $self->{$arg};
- }
- when (/text/) {
- my $font = $self->{fonts}->[$self->{font}]->{fill} or confess;
- my $font_border = $self->{fonts}->[$self->{font}]->{border} or confess;
-
- my ($w) = @{ SDL::TTF::size_text($font, $arg) };
-
- if ($mode eq 'layout')
- {#{my} when in layout mode, just calculate the bounding box
-
- my $h = SDL::TTF::font_height($font);
- if (not defined $taller_font or $h > $taller_font_height) {
- $taller_font = $font;
- $taller_font_height = $h;
- }
+ if ($cmd eq 'font') {
+ $self->{font} = $arg;
+ }
+ elsif ($cmd eq 'color') {
+ $color = $self->{$arg};
+ }
+ elsif ($cmd eq 'text') {
+ my $font = $self->{fonts}->[$self->{font}]->{fill} or confess;
+ my $font_border = $self->{fonts}->[$self->{font}]->{border} or confess;
- $box_width += $w;
- }#
- else
- {#{my} in draw mode, render the text, increment x position
+ my ($w) = @{ SDL::TTF::size_text($font, $arg) };
- my $x0 = $self->{x};
- my $y0 = $self->{y} + $taller_font_ascent - SDL::TTF::font_ascent($font);
+ if ($mode eq 'layout')
+ {#{my} when in layout mode, just calculate the bounding box
- sub do_print
- {my ($font, $surf, $x, $y, $color, $text) = @_;
+ my $h = SDL::TTF::font_height($font);
+ if (not defined $taller_font or $h > $taller_font_height) {
+ $taller_font = $font;
+ $taller_font_height = $h;
+ }
- my $ts = SDL::TTF::render_text_solid($font, $text, $color);
- my $r = SDL::Rect->new($x, $y, SDL::Surface::w($ts), SDL::Surface::w($ts));
- SDL::Video::blit_surface($ts, undef, $surf, $r);
- }#
+ $box_width += $w;
+ }#
+ else
+ {#{my} in draw mode, render the text, increment x position
- for(my $x = $x0-1; $x <= $x0+1; $x+=2) {
- for(my $y = $y0-1; $y <= $y0+1; $y+=2) {
- do_print($font_border, $surf, $x, $y, $self->{black}, $arg);
- }
- }
+ my $x0 = $self->{x};
+ my $y0 = $self->{y} + $taller_font_ascent - SDL::TTF::font_ascent($font);
- do_print($font, $surf, $x0, $y0, $color, $arg);
+ sub do_print
+ {my ($font, $surf, $x, $y, $color, $text) = @_;
- $self->{x} += $w;
+ my $ts = SDL::TTF::render_text_solid($font, $text, $color);
+ my $r = SDL::Rect->new($x, $y, SDL::Surface::w($ts), SDL::Surface::w($ts));
+ SDL::Video::blit_surface($ts, undef, $surf, $r);
}#
- }
- default { confess }
+
+ for(my $x = $x0-1; $x <= $x0+1; $x+=2) {
+ for(my $y = $y0-1; $y <= $y0+1; $y+=2) {
+ do_print($font_border, $surf, $x, $y, $self->{black}, $arg);
+ }
+ }
+
+ do_print($font, $surf, $x0, $y0, $color, $arg);
+
+ $self->{x} += $w;
+ }#
}
+ else { confess }
}
if ($mode eq 'layout')
View
@@ -120,34 +120,32 @@ sub seek
{my ($self, $dir, $itr) = @_;
$itr //= $self->{picitr};
- given ($dir) {
- when (/^first$/) {
- $itr->first;
- $self->pvt__filter or $self->seek('+1');
- }
- when (/^last$/) {
- $itr->last;
- $self->pvt__filter or $self->seek('-1');
- }
- when (/^[+-]/) {
- $dir =~ s/line/$self->{cols}/e;
- $dir =~ s/page/$self->{cols}*$self->{rows}/e;
-
- my $d = $dir>0?1:-1;
- $self->pvt__filter or warn 'invalid itr';
- my $valid_itr = $itr->dup; # backup
- while(1) {
- if ($itr->seek($d)) {
- $self->pvt__filter or next;
- $valid_itr = $itr->dup; # update
- $self->{page_cursor} += $d;
- $dir -= $d;
- return 1 if $dir == 0;
- }
- else {
- %$itr = %$valid_itr; # restore
- return 0;
- }
+ if ($dir eq 'first') {
+ $itr->first;
+ $self->pvt__filter or $self->seek('+1');
+ }
+ elsif ($dir eq 'last') {
+ $itr->last;
+ $self->pvt__filter or $self->seek('-1');
+ }
+ elsif ($dir =~ /^[+-]/) {
+ $dir =~ s/line/$self->{cols}/e;
+ $dir =~ s/page/$self->{cols}*$self->{rows}/e;
+
+ my $d = $dir>0?1:-1;
+ $self->pvt__filter or warn 'invalid itr';
+ my $valid_itr = $itr->dup; # backup
+ while(1) {
+ if ($itr->seek($d)) {
+ $self->pvt__filter or next;
+ $valid_itr = $itr->dup; # update
+ $self->{page_cursor} += $d;
+ $dir -= $d;
+ return 1 if $dir == 0;
+ }
+ else {
+ %$itr = %$valid_itr; # restore
+ return 0;
}
}
}
Oops, something went wrong.

0 comments on commit 1db1a93

Please sign in to comment.