Re: Tk::DropSite question



~greg wrote:
I have reduced the following script,
but it's runnable. It's a way
to make a Tk listbox that accepts
a selection of files or folders
from Windows Explorer.

The drop handler (my "OnSourceDrop")
is apparently called individually
on each file or folder in a multiple selection.

And my question is,

is there any way to know when to call
a group-drop-handler,
to be called after all the individual
calls to OnSourceDrop() are finished
after a group drop?


One way is setting up a timer:
This one will trigger group_drop_handler 50ms after the last call to OnSourceDrop. Are groups with one element considered being groups in your case?
Otherwise you would have to add a counter...





use strict;
use warnings;
$|=1;

use Tk;
use Tk::DropSite qw(Win32);

my $Main = MainWindow->new
(
-title=>'DND'
);

my %SourceList;

my $SourceListBox = $Main->Scrolled
(
"Listbox",
-scrollbars => "osoe",
)->pack
(
-fill => 'x',
);

$SourceListBox->DropSite
(
-dropcommand => [\&OnSourceDrop,$SourceListBox],
-droptypes => 'Win32',
);

sub SourceAdd
{
my $f = shift; # file or folder
return if exists $SourceList{$f};
return if ! -e $f;
$SourceList{$f} = 1;
my $slash = -d $f ? '\\' : '';
$SourceListBox->insert('end', "$f$slash" );
$SourceListBox->yviewMoveto(1);
}

{
my $after_cb;

sub OnSourceDrop
{
my($widget, $selection) = @_;
$widget->afterCancel($after_cb);
$after_cb = $widget->after(50,\&group_drop_handler);

my $f = $widget->SelectionGet('-selection'=>$selection,'STRING');
return if ! defined $f; # is this really necessary?
SourceAdd($f);
}
}

MainLoop;

sub group_drop_handler{
print "group drop finished\n";
}

Christoph



--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
.



Relevant Pages

  • Tk::DropSite question
    ... on each file or folder in a multiple selection. ... my $SourceListBox = $Main->Scrolled ... sub SourceAdd ...
    (comp.lang.perl.modules)
  • Tk::DropSite question
    ... on each file or folder in a multiple selection. ... my $SourceListBox = $Main->Scrolled ... sub SourceAdd ...
    (comp.lang.perl.misc)
  • Re: Including Subfolders for use within Word 2003 Macro
    ... Then selected from the Tools bar, Macro, in WORD 2003 and OFFICE 2003 ... folders to look in and then I selected a folder with documents I ... the three references you list should be sufficient. ... >>where we make the actual selection. ...
    (microsoft.public.word.docmanagement)
  • Re: Changing Export Delimiter
    ... current Excel folder, which you can change while you're in the dialog. ... expand the selection from a single selected cell (as with sorting, charts, ... >> Earl Kiosterud ...
    (microsoft.public.excel.misc)
  • Re: Outlook Contacts, Export a Category of contacts
    ... Milly, on your 2nd message, I read to drag and drop my selection to the new ... contacts folder, then right-click and select ... Milly Staples [MVP - Outlook] ...
    (microsoft.public.office.misc)