Skip Menu |

This queue is for tickets about the Tk-Tree CPAN distribution.

Report information
The Basics
Id: 28888
Status: resolved
Priority: 0/
Queue: Tk-Tree

People
Owner: Nobody in particular
Requestors: MTHURN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 4.7
Fixed in: (no value)



Subject: DirTree's folder sort order is wrong on Windows (patch attached)
Tk::DirTree sorts its folder list case-sensitively, but on Windows we want case-INsensitive order. Here is a drop-in replacement for the add_to_tree function. The changed lines are noted with my name in comment. ============= BEGIN SNIPPET ============== sub add_to_tree { my( $w, $dir, $name, $parent ) = @_; my $iWin32 = ($^O =~ m!win32!i); # added by Martin Thurn my $dirSortable = $iWin32 ? uc $dir : $dir; # added by Martin Thurn my $image = $w->cget('-image'); if ( !UNIVERSAL::isa($image, 'Tk::Image') ) { $image = $w->Getimage( $image ); } my $mode = 'none'; $mode = 'open' if $w->has_subdir( $dir ); my @args = (-image => $image, -text => $name); if( $parent ) { # Add in alphabetical order. foreach my $sib ($w->infoChildren( $parent )) { my $sibSortable = $iWin32 ? uc $sib : $sib; # added by Martin Thurn # if( $sib gt $dir ) { # commented out by Martin Thurn if( $sibSortable gt $dirSortable ) { # added by Martin Thurn push @args, (-before => $sib); last; } } } $w->add( $dir, @args ); $w->setmode( $dir, $mode ); } ============= END SNIPPET ============== -- - - Martin 'Kingpin' Thurn
On Sat Aug 18 15:01:18 2007, MTHURN wrote: Show quoted text
> Tk::DirTree sorts its folder list case-sensitively, but on Windows we > want case-INsensitive order. Here is a drop-in replacement for the > add_to_tree function. The changed lines are noted with my name in
comment. Show quoted text
> > ============= BEGIN SNIPPET ============== > sub add_to_tree { > my( $w, $dir, $name, $parent ) = @_; > > my $iWin32 = ($^O =~ m!win32!i); # added by Martin Thurn > my $dirSortable = $iWin32 ? uc $dir : $dir; # added by Martin Thurn > my $image = $w->cget('-image'); > if ( !UNIVERSAL::isa($image, 'Tk::Image') ) { > $image = $w->Getimage( $image ); > } > my $mode = 'none'; > $mode = 'open' if $w->has_subdir( $dir ); > > my @args = (-image => $image, -text => $name); > if( $parent ) { # Add in alphabetical order. > foreach my $sib ($w->infoChildren( $parent )) { > my $sibSortable = $iWin32 ? uc $sib : $sib; # added by Martin > Thurn > # if( $sib gt $dir ) { # commented out by Martin Thurn > if( $sibSortable gt $dirSortable ) { # added by Martin Thurn > push @args, (-before => $sib); > last; > } > } > } > > $w->add( $dir, @args ); > $w->setmode( $dir, $mode ); > } > ============= END SNIPPET ============== >
Can you check if the actual sort order is *locale dependent* and not just case insensitive? That is, how are filenames with German umlauts sorted: is a word with "ä" between "a" and "b" or after "z"? And is it possible to send a patch using the diff command, preferably "diff -up oldfile newfile"? This makes it much more easier to read. Regards, Slaven
On Sat Nov 03 17:41:17 2007, SREZIC wrote: Show quoted text
> Can you check if the actual sort order is *locale dependent* and not > just case insensitive? That is, how are filenames with German umlauts > sorted: is a word with "ä" between "a" and "b" or after "z"?
Yes, I suppose so. And beyond just the locale, if the goal is to make the Tk::DirTree sort the same way as Windows Explorer, you'd have to find a way to dip into the Windows API for filename sorting. (For example, "A2.txt" comes before "A111.txt") Show quoted text
> And is it possible to send a patch using the diff command, preferably > "diff -up oldfile newfile"? This makes it much more easier to read.
OK, attached to this msg -- - - Martin 'Kingpin' Thurn
--- DirTree.pm 2007-11-16 13:02:16.000000000 -0500 +++ DirTree.pm.martin 2007-11-16 13:03:04.578125000 -0500 @@ -127,7 +127,8 @@ sub OpenCmd { sub add_to_tree { my( $w, $dir, $name, $parent ) = @_; - + my $iWin32 = ($^O =~ m!win32!i); + my $dirSortable = $iWin32 ? uc $dir : $dir; my $image = $w->cget('-image'); if ( !UNIVERSAL::isa($image, 'Tk::Image') ) { $image = $w->Getimage( $image ); @@ -138,7 +139,8 @@ sub add_to_tree { my @args = (-image => $image, -text => $name); if( $parent ) { # Add in alphabetical order. foreach my $sib ($w->infoChildren( $parent )) { - if( $sib gt $dir ) { + my $sibSortable = $iWin32 ? uc $sib : $sib; + if( $sibSortable gt $dirSortable ) { push @args, (-before => $sib); last; }
Subject: Re: [rt.cpan.org #28888] DirTree's folder sort order is wrong on Windows (patch attached)
Date: 16 Nov 2007 23:18:52 +0100
To: bug-Tk-Tree [...] rt.cpan.org
From: Slaven Rezic <slaven [...] rezic.de>
"Martin Thurn via RT" <bug-Tk-Tree@rt.cpan.org> writes: Show quoted text
> Queue: Tk-Tree > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=28888 > > > On Sat Nov 03 17:41:17 2007, SREZIC wrote: >
> > Can you check if the actual sort order is *locale dependent* and not > > just case insensitive? That is, how are filenames with German umlauts > > sorted: is a word with "ä" between "a" and "b" or after "z"?
> > Yes, I suppose so. And beyond just the locale, if the goal is to make > the Tk::DirTree sort the same way as Windows Explorer, you'd have to > find a way to dip into the Windows API for filename sorting. (For > example, "A2.txt" comes before "A111.txt")
Hmm, this would need something like Sort::Naturally. Show quoted text
>
> > And is it possible to send a patch using the diff command, preferably > > "diff -up oldfile newfile"? This makes it much more easier to read.
> > OK, attached to this msg >
Can you try this alternative patch? This one uses "use locale", which is hopefully doing the right thing (both sorting ä between a and b, and do the case insensitive sorting). Additionally, I found out that Tk::DirTree did not display directories with high-bit characters at all. The patch tries to workaround this. "Workaround", because there's no perl way of doing file names right with repect to the filesystem's encoding. Regards, Slaven

Message body is not shown because sender requested not to inline it.

-- Slaven Rezic - slaven <at> rezic <dot> de tkrevdiff - graphical display of diffs between revisions (RCS, CVS or SVN) http://ptktools.sourceforge.net/#tkrevdiff
Subject: RE: [rt.cpan.org #28888] DirTree's folder sort order is wrong on Windows (patch attached)
Date: Sat, 17 Nov 2007 10:44:23 -0500
To: <bug-Tk-Tree [...] rt.cpan.org>
From: "Martin Thurn" <mthurn [...] verizon.net>
Show quoted text
> Can you try this alternative patch? This one uses "use locale", which > is hopefully doing the right thing (both sorting ä between a and b, > and do the case insensitive sorting). Additionally, I found out that > Tk::DirTree did not display directories with high-bit characters at > all. The patch tries to workaround this.
Yes, that patch correctly sorts case-insensitively. (I don't have any high-bit file names to test) - - Martin
Tk-Tree-4.75 is on the way to CPAN. I am still thinking about using Sort::Naturally. Regards, Slaven