
What can do?

Delete item or items from listicon.
Move up or down, item or items from listicon.
Copy and paste, item or items from listicon..
Work in Win,Mac and Linux.
If you can improve it do not forget to share. Thank you and enjoy it!

Greetings to all!!

Code: Select all
;{
; -------------------------------------------------------
; -------------------------------------------------------
; -- --
; -- List Manager --
; -- Toni M. (minimy) 2014 --
; -- --
; -------------------------------------------------------
; -------------------------------------------------------
;}
;{
; This is a little listicon help/manager.
; Win, Mac, Linux compatible.
; Spectrum And Atari Not compatible ;-) Enjoy it..!!
;}
;----LISTICON
Global TListPortaPapelesRAM.s=""
Procedure TListGetCol(Lista.l)
; Column may have header name o width > 0 to work
; Return numbers of columns
Protected Txt.s, P.l
Protected Items = 0
Protected Lar= 0
For p=0 To 1000
Txt = GetGadgetItemText(Lista,-1,p)
Lar = GetGadgetItemAttribute(Lista,-1,#PB_ListIcon_ColumnWidth,p)
If Len(Txt)>0 Or (Lar>0 And Lar<1000)
Items+1
EndIf
Next p
ProcedureReturn Items
EndProcedure
Procedure TListDelete(Lista,Pregunta=0)
; Delete selected items
Protected Pos.l=0, Resp.l
If CountGadgetItems(Lista)>0
If Pregunta=1
Resp=MessageRequester("Remove","Do you really want remove this item?",#PB_MessageRequester_YesNo)
Else
Resp=#PB_MessageRequester_Yes
EndIf
If Resp=#PB_MessageRequester_Yes
Repeat
If GetGadgetItemState(Lista,Pos) & #PB_ListIcon_Selected
RemoveGadgetItem(Lista,Pos)
Pos=-1
EndIf
Pos+1
Until Pos=CountGadgetItems(Lista)
EndIf
EndIf
ProcedureReturn Resp
EndProcedure
Procedure TListDown(Lista)
; Seletcted items down
Protected BloqueoLista.l, Col.l, Lin.l, ChainA$, ChainB$, EstadoA.l, EstadoB.l
If CountGadgetItems(Lista)>1
For p=1 To CountGadgetItems(Lista)-1
If GetGadgetItemState(Lista,p) & #PB_ListIcon_Selected
BloqueoLista=p
EndIf
Next p
If BloqueoLista<CountGadgetItems(Lista)-1
Col=TListGetCol(Lista)
Lin=CountGadgetItems(Lista)
For p= Lin-2 To 0 Step -1
EstadoA=GetGadgetItemState(Lista,p)
If EstadoA=1 Or EstadoA=3
ChainA$=""
ChainB$=""
EstadoB=GetGadgetItemState(Lista,p+1)
For n=0 To Col-1
ChainA$=GetGadgetItemText(Lista,p,n)
ChainB$=GetGadgetItemText(Lista,p+1,n)
SetGadgetItemText(Lista,p,ChainB$,n)
SetGadgetItemText(Lista,p+1,ChainA$,n)
SetGadgetItemState(Lista,p,EstadoB)
SetGadgetItemState(Lista,p+1,EstadoA)
Next n
EndIf
Next p
EndIf
EndIf
EndProcedure
Procedure TListUp(Lista)
; Seletcted items up
Protected BloqueoLista.l, Col.l, Lin.l, ChainA$, ChainB$, EstadoA.l, EstadoB.l
If CountGadgetItems(Lista)>1
If GetGadgetItemState(Lista,0) & #PB_ListIcon_Selected
BloqueoLista=1
EndIf
If BloqueoLista=0
Col=TListGetCol(Lista)
Lin=CountGadgetItems(Lista)
For p= 0 To Lin-2
EstadoA=GetGadgetItemState(Lista,p+1)
If EstadoA=1 Or EstadoA=3
ChainA$=""
ChainB$=""
EstadoB=GetGadgetItemState(Lista,p)
For n=0 To Col-1
ChainA$=GetGadgetItemText(Lista,p+1,n)
ChainB$=GetGadgetItemText(Lista,p,n)
SetGadgetItemText(Lista,p+1,ChainB$,n)
SetGadgetItemText(Lista,p,ChainA$,n)
SetGadgetItemState(Lista,p+1,EstadoB)
SetGadgetItemState(Lista,p,EstadoA)
Next n
EndIf
Next p
EndIf
EndIf
EndProcedure
Procedure TListCopy(Lista)
; copy items
If CountGadgetItems(Lista)>0
Protected Col.l=-1 : Repeat : Col+1 : Until GetGadgetItemText(Lista,-1,Col)=""; : Debug Col ; Numero de columnas
Protected LCopy$=""
Protected Pos.l=0, Estado.l, n.l, a$
Repeat
If GetGadgetItemState(Lista,Pos) & #PB_ListIcon_Selected
Estado=GetGadgetItemState(Lista,Pos)
SetGadgetItemState(Lista,Pos,Estado-1)
LCopy$+Str(Estado)
For n=0 To Col-1
LCopy$+GetGadgetItemText(Lista,Pos,n)+"¬"
Next n
LCopy$+"^"
a$="Copiado: "+Str(Pos)
; Debug a$
EndIf
Pos+1
Until Pos=CountGadgetItems(Lista)
If LCopy$<>"" : TListPortaPapelesRAM=LCopy$ : EndIf
EndIf
EndProcedure
Procedure TListPaste(Lista.l)
; Paste items
Protected Sele.l, OldSele.l, Estado.l, EstadoO.l, P1.l, P2.l, Cadena$, Chain$, lugar.l, resto.l
Sele=GetGadgetState(lista)
OldSele=Sele
If TListPortaPapelesRAM<>""
If Sele>-1
Resto=CountGadgetItems(Lista)-Sele : EstadoO=GetGadgetItemState(Lista,sele)
If OldSele>-1:SetGadgetItemState(Lista,Sele,EstadoO-1):EndIf
Col=CountString(TListPortaPapelesRAM,"¬") : P1=1
Repeat
P2=FindString(TListPortaPapelesRAM,"^",P1) : Cadena$=Mid(TListPortaPapelesRAM,P1,P2-P1)+Chr(10) : P1=P2+1
Chain$="" : Estado=Val(Left(Cadena$,1))
Pos1=2
Repeat : pos2=FindString(Cadena$,"¬",pos1) : Chain$+Mid(Cadena$,pos1,pos2-pos1)+Chr(10) : pos1=pos2+1 : Until pos2=0
If P2>0
AddGadgetItem(Lista,-1,Chain$) : SetGadgetItemState(Lista,CountGadgetItems(Lista)-1,Estado)
EndIf
Until P2=0
For p=1 To resto-1 : TListUp(Lista) : Next p
Else
Resto=CountGadgetItems(Lista)-Sele : EstadoO=GetGadgetItemState(Lista,sele)
If OldSele>-1:SetGadgetItemState(Lista,Sele,EstadoO-1):EndIf
Col=CountString(TListPortaPapelesRAM,"¬") : P1=1
Repeat
P2=FindString(TListPortaPapelesRAM,"^",P1) : Cadena$=Mid(TListPortaPapelesRAM,P1,P2-P1)+Chr(10) : P1=P2+1
Chain$="" : Estado=Val(Left(Cadena$,1))
Pos1=2
Repeat : pos2=FindString(Cadena$,"¬",pos1) : Chain$+Mid(Cadena$,pos1,pos2-pos1)+Chr(10) : pos1=pos2+1 : Until pos2=0
If P2>0
AddGadgetItem(Lista,lugar,Chain$) : If lugar > -1 : SetGadgetItemState(Lista,lugar,Estado) : Else : SetGadgetItemState(Lista,CountGadgetItems(Lista)-1,Estado) : EndIf
EndIf
Until P2=0
EndIf
EndIf
EndProcedure
;{ Example
CompilerIf Not #PB_Compiler_IsIncludeFile
Window_0 = OpenWindow(#PB_Any, 438, 83, 643, 400, "List Manager", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If Window_0
ListIcon_0 = ListIconGadget(#PB_Any, 10, 20, 520, 350, "Gadget_0", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(ListIcon_0,1,"kaka",200)
;SendMessage_(GadgetID(ListIcon_0), #LVM_SETCOLUMNWIDTH, 0, #LVSCW_AUTOSIZE_USEHEADER) ; Only windows ;-)
Button_1 = ButtonGadget(#PB_Any, 535, 20, 80, 25, "clear list")
Button_2 = ButtonGadget(#PB_Any, 535, 50, 80, 25, "add item")
Button_3 = ButtonGadget(#PB_Any, 535, 80, 80, 25, "move up")
Button_4 = ButtonGadget(#PB_Any, 535, 110, 80, 25, "move down")
Button_5 = ButtonGadget(#PB_Any, 535, 140, 80, 25, "copy")
Button_6 = ButtonGadget(#PB_Any, 535, 170, 80, 25, "paste")
Button_7 = ButtonGadget(#PB_Any, 535, 200, 80, 25, "Delete")
EndIf
Repeat
Event = WaitWindowEvent(1)
Select Event
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = ListIcon_0
ElseIf EventGadget = Button_1
ClearGadgetItems(ListIcon_0)
ElseIf EventGadget = Button_2
AddGadgetItem(ListIcon_0,-1, Str(Random(99999999))+Chr(10)+"more... "+Str(Random(99999999)) )
ElseIf EventGadget = Button_3
TListUp(ListIcon_0)
ElseIf EventGadget = Button_4
TListDown(ListIcon_0)
ElseIf EventGadget = Button_5
TListCopy(ListIcon_0)
ElseIf EventGadget = Button_6
TListPaste(ListIcon_0)
ElseIf EventGadget = Button_7
TListDelete(ListIcon_0)
EndIf
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = Window_0
CloseWindow(Window_0)
Window_0 = 0
Break
EndIf
EndSelect
ForEver
CompilerEndIf
;}