Create a SORT command for gadget lists
Posted: Tue Jun 04, 2013 2:57 pm
Hello!
Could you create such a command?
Right now I have to:
gadgetlist->copy to array->sort array->delete gadgetlist->copy to gadget list
This is very slow.
Thanks!
Kind regards,
>Marco A.G.Pinto
---------------
Could you create such a command?
Right now I have to:
gadgetlist->copy to array->sort array->delete gadgetlist->copy to gadget list
This is very slow.
Code: Select all
; Sorts the list of synonyms
; V1.0 - 22/MAY/2013
; o Just placed a warning window saying it is not coded yet.
; V1.1 - 24/MAY/2013
; o Coded the complete procedure
; V1.2 - 27/MAY/2013
; o Sort is now non case sensitive
Procedure sort_synonyms()
If number_of_synonyms=0
MessageRequester("Warning","No synonyms found.")
ProcedureReturn 0
EndIf
Dim synonyms_array$(number_of_synonyms-1)
OpenGadgetList(#PANEL_MAIN,1)
ProgressBarGadget(#NUMBER_SYNONYMS_PROGRESS_BAR,10+100+100+100+100+100-5-5,300-3+20+3,100,20-3, 0,number_of_synonyms*3)
; Copy from list to array
AddWindowTimer(#WINDOW_MAIN,500,1)
time=ElapsedMilliseconds()
For f=0 To number_of_synonyms-1
t$=GetGadgetItemText(#PANEL_BOX_SYNONYMS,f,0)
For ff=1 To #max_number_meanings
a$=GetGadgetItemText(#PANEL_BOX_SYNONYMS,f,ff)
If a$<>"" : t$=t$+Chr(10)+a$ : EndIf
Next ff
synonyms_array$(f)=t$
; Fix to window stop responding if we click on it while adding synonyms
event = WindowEvent()
If Event = #PB_Event_Timer : EndIf
If ElapsedMilliseconds()>time+800
SetGadgetState(#NUMBER_SYNONYMS_PROGRESS_BAR, f)
time=ElapsedMilliseconds()
EndIf
Next f
RemoveWindowTimer(#WINDOW_MAIN,500)
; Sort the array and delete the list
SortArray(synonyms_array$(),#PB_Sort_Ascending|#PB_Sort_NoCase)
ClearGadgetItems(#PANEL_BOX_SYNONYMS)
t=number_of_synonyms*2
SetGadgetState(#NUMBER_SYNONYMS_PROGRESS_BAR,t)
; copy from array back to list
AddWindowTimer(#WINDOW_MAIN,500,1)
time=ElapsedMilliseconds()
For f=0 To number_of_synonyms-1
t$=synonyms_array$(f)
AddGadgetItem(#PANEL_BOX_SYNONYMS,-1,t$)
; Fix to window stop responding if we click on it while adding synonyms
event = WindowEvent()
If Event = #PB_Event_Timer : EndIf
If ElapsedMilliseconds()>time+800
t=(number_of_synonyms*2)+f
SetGadgetState(#NUMBER_SYNONYMS_PROGRESS_BAR, t)
time=ElapsedMilliseconds()
EndIf
Next f
RemoveWindowTimer(#WINDOW_MAIN,500)
t=number_of_synonyms*3
SetGadgetState(#NUMBER_SYNONYMS_PROGRESS_BAR,t)
Delay(500)
HideGadget(#NUMBER_SYNONYMS_PROGRESS_BAR,1)
CloseGadgetList()
EndProcedure
Kind regards,
>Marco A.G.Pinto
---------------