Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

Commit

Permalink
Get the move_tank function working with the HList. Thanks to Kyle at
Browse files Browse the repository at this point in the history
sickduck.org for the help.
  • Loading branch information
minter committed Sep 17, 2004
1 parent 3833892 commit ce192b3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
Fri Sep 17 2004 H. Wade Minter (minter@lunenburg.org)
* Get the move_tank function working with the HList. Thanks to
Kyle at sickduck.org for the help.

Mon Sep 13 2004 H. Wade Minter (minter@lunenburg.org)
* Make nice white backgrounds by default for listboxes and entry
widgets.
Expand Down
59 changes: 44 additions & 15 deletions mrvoice.pl
Expand Up @@ -2578,11 +2578,11 @@ sub holding_tank
);
$holdingtank->Button(
-image => $arrowup,
-command => [ \&move_tank, "-1" ]
-command => [ \&move_tank, "-before" ]
)->pack( -side => 'left' );
$holdingtank->Button(
-image => $arrowdown,
-command => [ \&move_tank, "1" ]
-command => [ \&move_tank, "-after" ]
)->pack( -side => 'right' );
$tankbox = $holdingtank->Scrolled(
'HList',
Expand Down Expand Up @@ -2650,22 +2650,51 @@ sub holding_tank
sub move_tank
{

# Blatantly cribbed from Mastering Perl/Tk's Tk::NavListbox example
my $lb = $tankbox;
my $direction = shift;
my (@selection) = $lb->curselection;
my $index = $selection[0];
# Function courtesy of Kyle at sickduck.org
my $h = $tankbox;
my $direction = shift;

# Sanity checks
return if ( $index == 0 && $direction == -1 );
return if ( $index == $lb->size() - 1 && $direction == 1 );
#Do nothing unless an item is selected in the HList
return unless my $target = $h->infoAnchor;

my $newindex = $index + $direction;
#Based on direction to be moved, get index for prior/next item in HList
my $neighbor;
if ( $direction =~ /before/i )
{
$neighbor = $h->infoPrev($target);
}
else
{
$neighbor = $h->infoNext($target);
}

#infoNext/infoPrev returns no value if there is no item after/before the
#target entry. This generally means we're already at the end/beginning
#of list, so we can return with no action.
return unless $neighbor;

my $item = $lb->get($index);
$lb->delete($index);
$lb->insert( $newindex, $item );
$lb->selectionSet($newindex);
#We need to grab the text of the entry that needs to be moved
my $targettext = $h->entrycget( $target, '-text' );

#Now we can delete the entry...
$h->delete( 'entry', $target );

#then we use the passed direction ("-before" or "-after") to add
#the entry information appropriately...
$h->add(
$target,
-data => $target,
-text => $targettext,
$direction, $neighbor
);

#...and assumedly we want the newly re-inserted item to be selected...
$h->anchorSet($target);

#...and assumedly, in a scrolling list, we want to have the re-inserted
#item be visible.
$h->see($target);
return;
}

sub clear_tank
Expand Down

0 comments on commit ce192b3

Please sign in to comment.