Page 2 of 4

Re: Sort ListIconGadget [Windows only]

Posted: Mon Feb 24, 2025 2:55 pm
by dcr3
Zapman wrote: Mon Feb 24, 2025 10:24 am Sorry, I don't understand. It's working fine with a french setting. What happens for you? What do you see?
I don't know about your settings. For me dates don't sort correctly. :!:

May be someone else can vouch for it.

Anyway try the following.
Add different dates to the listicongadget , sort it and see. Then tell me if anything is amiss.

Code: Select all

IncludeFile "ColumnSortedListIconGadget.pbi"
Enumeration Window
  #Window_0
EndEnumeration

Enumeration Gadgets
  #ListIcon_1
  #Date_1
  #Btn_AddDate
  #Btn_Remove
EndEnumeration

Global AppQuit

Procedure AddDates()
  Protected dates$
 
    dates$ = GetGadgetText(#Date_1)
    AddGadgetItem(#ListIcon_1, -1, dates$)
    
  EndProcedure
 Procedure removedates()
    RemoveGadgetItem(#ListIcon_1, GetGadgetState(#ListIcon_1))
  EndProcedure 
  
  Define flgs=#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered
  If OpenWindow(#Window_0, 0, 0,260,400, "SortDate",flgs)
    ListIconGadget(#ListIcon_1, 10, 10, 140, 380, "Date", 120)
    
    ;DateGadget(#Date_1, 160, 10, 100, 20, "%yyyy-%mm-%dd", 0);interchange these options.?
    ;DateGadget(#Date_1, 160, 10, 100, 20, "%yyyy/%mm/%dd", 0);
    DateGadget(#Date_1, 160, 10, 100, 20, "%dd-%mm-%yyyy", 0);
    ;DateGadget(#Date_1, 160, 10, 100, 20, "%dd/%mm/%yyyy", 0)
    ;DateGadget(#Date_1, 160, 10, 100, 20, "%dd.%mm.%yyyy", 0)
    
    ButtonGadget(#Btn_AddDate, 170, 40, 80, 20, "AddDate")
    ButtonGadget(#Btn_Remove, 170, 70, 80, 20, "Remove")    
  EndIf

ShowListIconSortingArrows(#ListIcon_1)
SortListIcon(#ListIcon_1, 0, #CSLI_Descent)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      AppQuit = #True
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Btn_AddDate
          AddDates()
        Case #Btn_Remove
         removedates()
      EndSelect

  EndSelect
Until AppQuit

Re: Sort ListIconGadget [Windows only]

Posted: Mon Feb 24, 2025 3:48 pm
by Mindphazer
Zapman wrote: Mon Feb 24, 2025 10:26 am
Mindphazer wrote: Sun Feb 23, 2025 9:39 pm
dcr3 wrote: Sun Feb 23, 2025 9:05 pm I think your date routine needs to be fixed. :?:
Indeed
Sorry, I don't understand. It's working fine with a french setting. What happens for you? What do you see?
With your example, when i click the header of the fourth column, the order is not right. I have dates in march then dates in february, then dates in march :

Image

I don't think it's related to french settings, as i'm french and my settings are in french !

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 2:10 am
by ChrisR
It works well, nice sharing :)

To sort the date, it seems that it is this line that is wrong in CSLI_ListIconSortCallback()

Code: Select all

If A > B Or ValF(A$) > ValF(B$) 
Waiting for your fix, it looks good if I replace the block with:

Code: Select all

  If A > 0 Or A$ = "0"
    If FindString(A$, "/") Or FindString(B$, "/")
      If A > B
        Result = AscentDescent 
      Else
        Result = -AscentDescent
      EndIf
    Else
      If A > B Or ValF(A$) > ValF(B$)
        Result = AscentDescent 
      Else
        Result = -AscentDescent
      EndIf
    EndIf
  Else ..........

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 9:30 am
by Lord
Hi!

It's missing the % before "MM" and "yyyy".
So you get a "26.MM.yyyy".

I just inserted

Code: Select all

  DateFormat$=ReplaceString(DateFormat$, ".", ".%")

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 9:43 am
by Lord
Hi ChrisR!

Your solution works, but you have also to take in account to test for a "." instead of a "/" in A$ and B$ in some circumstances.
Maybe a variable would be a solution for different time and / or date formats.

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 11:17 am
by Zapman
So, there was more than one problem with the date sorting.
Sorry for my blindness about that and many thanks to all of you for your help. I love the forum :)

I used GetLocaleInfo_() to get the local date separator and adapt the code to it.
I've also improved the sorting procedure for negative numbers.

The code has been udpated in the first post of this subject.

I hope everything is good now.

Thanks again.

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 2:07 pm
by ChrisR
Thanks for the update Luc, seems to work fine for dates :)
If they respect the date formatting

There is an inversion between the arrows and the sorting, it's fixed by inverting the AscentDescent value:

Code: Select all

If *SortInfo\AscentDescent = #CSLI_Ascent : AscentDescent = 1 : Else : AscentDescent = -1 : EndIf
and for the demo, it's probably best to define the sorting of the 1st column as ascending

Code: Select all

SortListIcon(SortListIconGagdetRef, 0, #CSLI_Ascent)

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 3:00 pm
by firace
Nice code zapman, thanks for sharing.

To be honest I still use nalor's implementation (see link). It has a few small bugs, but the reason I keep using it is that it's sooo convenient to use. To make the listicongadget sortable you only need to add one line of code and that's it!

Code: Select all

  SetWindowCallback(@ColumnClickCallback())  

Any chance you could do something similar?

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 3:43 pm
by ebs
In the US, GetLocaleInfo_() returns "M/d/yyyy" on my PC.

When your code reformats that it yields "%m/%d/%yyyy" instead of "%mm/%dd/%yyyy", so the dates are not displayed correctly.

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 5:44 pm
by Zapman
firace wrote: Tue Feb 25, 2025 3:00 pm Nice code zapman, thanks for sharing.

To be honest I still use nalor's implementation (see link). It has a few small bugs, but the reason I keep using it is that it's sooo convenient to use. To make the listicongadget sortable you only need to add one line of code and that's it!

Code: Select all

  SetWindowCallback(@ColumnClickCallback())  

Any chance you could do something similar?
It's allready done, Firace :)
All what you have to do is

Code: Select all

MakeListIconSortable(ListIconGagdet)
OR (if you want to get the gadget sortable and to see the sorting arrows):

Code: Select all

ShowListIconSortingArrows(ListIconGagdet)
The nalor's implementation is aesthetic andworks well, but it's not totally clean from my point of view:
- You can't have one sorted ListIcongadget and another one not sorted in the same window,
- In the same time, the procedure named 'GetColumnOrdrerType()' supposes that the ListIconGadget was created with the constant "#ListIcon' as number. It won't work with a #PB_Any gadget or with another constant name.
- If you need to install another callback procedure on the same windows (to colorize gadgets, for exemple) it won't be possible without some adaptations,
- Dates are correctly sorted only for english systems (thank to the forum's testers, the present version is now adaptable).
- It uses 'GetDlgCtrlID_()' to get the gadget's number from it's handle (as I did in the forst version of my code). But GetDlgCtrlID_ doesn't work on some versions of Windows, as MindPhaser and Lord noticed.
- It is not able to sort strings with accents (as in french, for exemple).
- It seems to me that it's more complicated (but I can't be objective on that point)
Thanks anymay :)

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 6:04 pm
by Zapman
ChrisR wrote: Tue Feb 25, 2025 2:07 pmThere is an inversion between the arrows and the sorting,
Thanks again for your help, ChrisR.
The right sens for the arrows depends on the logic your're runing with.
In my mind, "Ascending" means that values are growing up from up of the list to down of the list, because the top of the list is presented first.
I totally agree that the consequence (down arrow for ascending sorting) can seem inverted for certains. But an arrow pointing to the sky when values grow from up to down is too weird for me :)

But you're right about tha fact that constants where not correctly named. I got confused.
The code has been updated with sother modifications for the date's format (followin the ebs's post).
Thanks again.

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 6:14 pm
by Zapman
ebs wrote: Tue Feb 25, 2025 3:43 pmIn the US, GetLocaleInfo_() returns "M/d/yyyy" on my PC.
That's very nice to signal this, ebs. I woundn't imagine that.
I've adapted the code to comply with this type of local settings.
You can get the new version from the first message of this subject, if you want.

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 6:40 pm
by ChrisR
Zapman wrote: Tue Feb 25, 2025 6:04 pm I totally agree that the consequence (down arrow for ascending sorting) can seem inverted for certains. But an arrow pointing to the sky when values grow from up to down is too weird for me :)
Yeah, it depends on how you see it:
An arrow pointing to the sky.
Or an arrow smaller at top, larger at bottom for ascending sorting from smallest to largest value, as in Explorer

Image

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 6:49 pm
by Zapman
ChrisR wrote: Tue Feb 25, 2025 6:40 pmAn arrow pointing to the sky.
Or an arrow smaller at top, larger at bottom for ascending sorting from smallest to largest value, as in Explorer
Stop, please, you're making my head upside down :D :D
Your argument is smart and the idea to adopt the Explorer's logic is strong. I'll thing again.

Re: Sort ListIconGadget [Windows only]

Posted: Tue Feb 25, 2025 6:59 pm
by ChrisR
Remember your childhood years

Image

But I understand your logic too, from the ground to the sky, it's more poetic :wink: