Page 1 of 1

fast DirectoryLister/Explorergadget (Windows Api only)

Posted: Mon Sep 13, 2004 9:46 pm
by Rings
Code updated For 5.20+

Code: Select all

;Alternative (Fast) Directory Lister
; Purebasic 3.91, Windows only
; done on september,12,2004
; part of a fast mp3-player
; by Siegfried Rings
; Feel free to spread :)

SearchPath.s="C:"

#txt_Directory = 2
#LST_DIRECTORY = 3
#txt_Directory2=4
#B1=5
#B2=6
#txt_3=7

hWndMain = OpenWindow(0, 100, 200, 400, 400, "DirectoryList API", #PB_Window_SystemMenu)

TextGadget(#txt_Directory, 10,10,350,20,"")
TextGadget(#txt_Directory2, 10,30,350,20,"")

ButtonGadget(#B1,360,1,40,20,"UP")
ButtonGadget(#B2,360,25,40,20,"DN")
TextGadget(#txt_3, 360,50,40,20,"")


lv=ListViewGadget(#LST_DIRECTORY ,10,70,380,320,#LBS_SORT );| #LBS_MULTIPLESEL |#LBS_NOINTEGRALHEIGHT | #LBS_HASSTRINGS)
result=DlgDirList_(hWndMain, SearchPath.s, #LST_DIRECTORY, 2, #DDL_DRIVES |#DDL_DIRECTORY |#DDL_READWRITE )
AddKeyboardShortcut(0,#PB_Shortcut_Return  ,1)

Repeat
  event = WaitWindowEvent()
  evt=EventType()
  If evt=#PB_EventType_LeftClick       
    Select EventGadget()
      Case #b1
        SetGadgetState(#LST_DIRECTORY ,GetGadgetState(#LST_DIRECTORY )-1)
        SetGadgetText(#txt_3,Str(GetGadgetState(#LST_DIRECTORY )) )
      Case #b2
        SetGadgetState(#LST_DIRECTORY ,GetGadgetState(#LST_DIRECTORY )+1)
        SetGadgetText(#txt_3,Str(GetGadgetState(#LST_DIRECTORY )) )
    EndSelect
    
  EndIf
  If evt=#PB_EventType_LeftDoubleClick       
    Select EventGadget()
      Case #LST_DIRECTORY
        P=1
    EndSelect
  EndIf
  If event = #PB_Event_Menu
    evm=EventMenu()       
    If evm=1
      p=1
    EndIf
  EndIf
  If P=1
    
    ;If EventGadgetID()=#LST_DIRECTORY
    Entry.s=GetGadgetText(#LST_DIRECTORY)
    If Left(Entry.s,1)="["
      Entry.s=Right(Entry.s,Len(Entry.s)-1)
      Entry.s=Left(Entry.s,Len(Entry.s)-1)
      If Left(Entry.s,1)="-"
        Entry.s=Right(Entry.s,Len(Entry.s)-1)
      EndIf
      If Right(Entry.s,1)="-"
        Entry.s=Left(Entry.s,Len(Entry.s)-1)+":"
      EndIf
      SearchPath.s=Entry.s
      Debug Entry.s
      result=DlgDirList_(hWndMain, SearchPath.s, #LST_DIRECTORY, 2, #DDL_DRIVES |#DDL_DIRECTORY |#DDL_READWRITE )
    EndIf
    SetGadgetText(#txt_Directory2,Entry.s)
    ;EndIf
    P=0
  EndIf
Until event = #PB_Event_CloseWindow

Posted: Mon Sep 13, 2004 11:39 pm
by ABBKlaus
good for displaying but not good for browsing in a directory structure :

AUTOEXEC.BAT <- Filename
[-c-] <- Directoryname will be identified as Drivename :evil:
[ATI] <- Directoryname
[-a-] <- Drivename
[-c-] <- Drivename

Posted: Tue Sep 14, 2004 1:08 am
by Dare2
Heya Rings,

Thanks! This opens a new area of API for me.


And it came to pass That crack 'n' hack was born
All across the land every script kiddie Was blowin' up a storm
And the h4ck0r man got famous The business man did bitch
And at every screen there was a wannabe With a seven year itch
There was fifteen million fingers Learnin' to cut code
And you could hear the fingers clickin' And this is what they tried to load ..

Apologies to Ac/Dc

Posted: Tue Sep 14, 2004 7:53 am
by Rings
ABBKlaus wrote:good for displaying but not good for browsing in a directory structure :

AUTOEXEC.BAT <- Filename
[-c-] <- Directoryname will be identified as Drivename :evil:
[ATI] <- Directoryname
[-a-] <- Drivename
[-c-] <- Drivename
sure. as i said, its a fast alternative. And the biggest Pro of this method is that you can navigate from outside via SetGadgetState(). This is a absolutly Must if you wanna navigate without a mouse (in my case with a touchpanel-pc) .here is a modified version which shows this features:

Code: Select all

;Alternative (Fast) Directory Lister 
; Purebasic 3.91, Windows only 
; done on september,12,2004 
; part of a fast mp3-player 
; by Siegfried Rings 
; Feel free to spread :) 

SearchPath.s="C:" 

#txt_Directory = 2 
#LST_DIRECTORY = 3 
#txt_Directory2=4 
#B1=5
#B2=6
#txt_3=7

hWndMain = OpenWindow(0, 100, 200, 400, 400, #PB_Window_SystemMenu, "DirectoryList API") 
CreateGadgetList(hWndMain) 
TextGadget(#txt_Directory, 10,10,350,20,"") 
TextGadget(#txt_Directory2, 10,30,350,20,"") 

ButtonGadget(#B1,360,1,40,20,"UP")
ButtonGadget(#B2,360,25,40,20,"DN")
TextGadget(#txt_3, 360,50,40,20,"") 


lv=ListViewGadget(#LST_DIRECTORY ,10,70,380,320,#LBS_SORT );| #LBS_MULTIPLESEL |#LBS_NOINTEGRALHEIGHT | #LBS_HASSTRINGS) 
result=DlgDirList_(hWndMain, SearchPath.s, #LST_DIRECTORY, 2, #DDL_DRIVES |#DDL_DIRECTORY |#DDL_READWRITE ) 
AddKeyboardShortcut(0,#PB_Shortcut_Return  ,1) 

Repeat 
  event = WaitWindowEvent() 
  evt=EventType() 
  If evt=#PB_EventType_LeftClick        
   Select EventGadgetID()
   Case #b1
    SetGadgetState(#LST_DIRECTORY ,GetGadgetState(#LST_DIRECTORY )-1)
    SetGadgetText(#txt_3,Str(GetGadgetState(#LST_DIRECTORY )) )
   Case #b2 
    SetGadgetState(#LST_DIRECTORY ,GetGadgetState(#LST_DIRECTORY )+1)
    SetGadgetText(#txt_3,Str(GetGadgetState(#LST_DIRECTORY )) )
   EndSelect
  
  EndIf
  If evt=#PB_EventType_LeftDoubleClick        
   Select EventGadgetID()
   Case #LST_DIRECTORY 
    P=1 
   EndSelect
  EndIf 
  If event = #PB_Event_Menu 
   evm=EventMenuID()        
   If evm=1 
    p=1 
   EndIf 
  EndIf 
If P=1 

  ;If EventGadgetID()=#LST_DIRECTORY 
      Entry.s=GetGadgetText(#LST_DIRECTORY) 
      If Left(Entry.s,1)="[" 
       Entry.s=Right(Entry.s,Len(Entry.s)-1) 
       Entry.s=Left(Entry.s,Len(Entry.s)-1) 
       If Left(Entry.s,1)="-" 
        Entry.s=Right(Entry.s,Len(Entry.s)-1) 
       EndIf 
       If Right(Entry.s,1)="-" 
        Entry.s=Left(Entry.s,Len(Entry.s)-1)+":" 
       EndIf 
       SearchPath.s=Entry.s 
       Debug Entry.s 
       result=DlgDirList_(hWndMain, SearchPath.s, #LST_DIRECTORY, 2, #DDL_DRIVES |#DDL_DIRECTORY |#DDL_READWRITE ) 
      EndIf 
      SetGadgetText(#txt_Directory2,Entry.s) 
    ;EndIf 
  P=0 
EndIf 
Until event = #PB_Event_CloseWindow 
Dare2
nice song-snippet ;)