ExplorerGadget replace value item dynamically

Share your advanced PureBasic knowledge/code with the community.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

ExplorerGadget replace value item dynamically

Post by Kwai chang caine »

Hello at all

One time is not usual, it's me who give a little tips :oops:

I have searched several weeks to modify dynamically an ExplorerGadget.
The most of time with complicated things : CallBack, SubClassing, ... without succes (Normal way, for KCC) :|
And in fact, the solution is very simple :shock:

The main problem is the LeftDoubleClic, not recognized by the ExplorerGadget for the folders :shock: :|

Obviously...if you have better...i'm not jealous...i keep :mrgreen:

Code: Select all

#ExpListG = 0
Global Dim TabloItems.s(0)

Procedure ChangeName()
 
 Dim TabloItems.s(10000)
 MaxIndex = CountGadgetItems(#ExpListG)
 
 For i = 0 To MaxIndex - 1
 
  TabloItems(i) = GetGadgetItemText(#ExpListG, i, 0)   
  SetGadgetItemText(#ExpListG, i, "Kcc_" + TabloItems(i), 0)

 Next
 
 ReDim TabloItems(MaxIndex)

EndProcedure

If OpenWindow(0,0,0,400,300, "File Selection", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
 
 ExplorerListGadget(#ExpListG, 10, 10, 380, 180, "Kcc VirtualXplorer", #PB_Explorer_MultiSelect|#PB_Explorer_AlwaysShowSelection|#PB_Explorer_FullRowSelect)
 ChangeName()

 Repeat
 
  Event = WaitWindowEvent()
 
  If EventType() = #PB_EventType_LeftClick
 
  Start = GetTickCount_()
  GetAsyncKeyState_(#VK_LBUTTON) 
  
  Repeat : Until GetAsyncKeyState_(#VK_LBUTTON) <> 0 Or GetTickCount_() - Start > GetDoubleClickTime_() 
     
  If GetTickCount_() - Start < GetDoubleClickTime_() ; Double Click 

    Index = GetGadgetState(#ExpListG)
    
    If Index <> - 1
     
     Item$ = GetGadgetItemText(#ExpListG, Index)
     Chemin$ = GetGadgetText(#ExpListG)
          
     If Item$ <> "Kcc_.."
      
      NouveauChemin$ = Chemin$ + TabloItems(Index)
      If Right(NouveauChemin$,1)<>"\" : NouveauChemin$+"\":EndIf
     
     Else 
     
      MaxSlash = CountString(Chemin$, "\")
      NouveauChemin$ = ""
      
      For i = 1 To MaxSlash - 1
       NouveauChemin$ + StringField(Chemin$, i, "\") + "\"
      Next
            
     EndIf
      
     SetGadgetText(#ExpListG, NouveauChemin$)
     ChangeName()
     
    EndIf 
   
   EndIf
     
  EndIf
  
 Until Event = #PB_Event_CloseWindow 
 
EndIf 
Have a good day
Last edited by Kwai chang caine on Tue Dec 20, 2016 3:57 pm, edited 2 times in total.
ImageThe happiness is a road...
Not a destination
Damion12
User
User
Posts: 81
Joined: Tue Oct 30, 2012 1:39 am

Re: ExplorerGadget replace value item dynamically

Post by Damion12 »

errors out after a bit on line #48

Code: Select all

     PathAddBackslash_(@NouveauChemin$)
[code
[13:13:23] [ERROR] Line: 48
[13:13:23] [ERROR] Overflow in a string memory block.
[/code]

(it's because you're adding a slash to a memory block that isn't big enough)

this is a simple enough fix...

If Right(NouveauChemin$,1)<>"\" : NouveauChemin$+"\":EndIf ;PathAddBackslash_(@NouveauChemin$)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ExplorerGadget replace value item dynamically

Post by Kwai chang caine »

Thanks Damion12

I never have this error before in my numerous test :shock:
But i know it's possible, one time i have read this risk in a Netmaestro explanation i believe.
It's a pity, because i love this API. :D
So i fix that when even with your tips :wink:
Thanks again, to have try my code 8)

Edit:
@Damion12
Bug fixed :wink:
ImageThe happiness is a road...
Not a destination
Post Reply