It is currently Sat Jul 11, 2020 8:47 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject:
PostPosted: Mon Dec 17, 2001 12:12 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Fangbeast.


Code:
 ;--------------------------------------------------------------------------------------------------------------------------

Procedure GetList(SourceDirectory$, Start, Pattern$)
 
  Shared Counter
 
  If ExamineDirectory(Start, SourceDirectory$, "*.*")
    Repeat
      Type = NextDirectoryEntry()
      If Type = 2
        If DirectoryEntryName()  "." And DirectoryEntryName()  ".."
          a$ = SourceDirectory$ + DirectoryEntryName() + "\"
          GetList(a$, Start + 1, Pattern$)
          UseDirectory(Start)
        EndIf
      Else
        If Type = 1 And FindString(UCase(DirectoryEntryName()), UCase(Pattern$), 1)  0
          Place$ = SourceDirectory$ + DirectoryEntryName()
          SetGadgetText(5, "   " + Str(Counter) + " Matches")
          SetGadgetText(6, SourceDirectory$)
          AddGadgetItem(7, -1, Place$)
          Counter + 1
        EndIf
      EndIf
    Until Type = 0
  EndIf
 
EndProcedure

;-------------------------------------------------------------------------------------------------------------------------
; StartDrive$ = PathRequester("Select the Drive and the DIRectory to CATalogue please", "C:\")  ; Drive, Dir to cat
; Setup the number of gadgets for the initial display
;--------------------------------------------------------------------------------------------------------------------------

InitGadget(12)

#SearchItem = 2
#SearchLocation = 3
#StartButton = 4
#NumGadget = 5
#DirTitle = 6
#ListBox = 7
#Frame3D = 8

#ButtonLength = 125
#ButtonHeight = 25
#ButtonX = 5
#ButtonY = 15

SetGadgetFont(2)

If OpenWindow(0, 5, 5, 800, 590, #PB_Window_SystemMenu,"iFind, v2")
  If CreateGadgetList(WindowID())
    StringGadget(#SearchItem, #ButtonX, #ButtonY, #ButtonLength, #ButtonHeight,"")
    ButtonGadget(#SearchLocation, #ButtonX,45, #ButtonLength, #ButtonHeight,"Search Where?")
    ButtonGadget(#StartButton, #ButtonX,75, #ButtonLength, #ButtonHeight,"Start Searching")
    TextGadget(#NumGadget, #ButtonX, 105, #ButtonLength, #ButtonHeight, "")
    TextGadget(#DirTitle, 135, #ButtonY, 655, #ButtonHeight, "")
    ListViewGadget(#ListBox, 135, 45, 655, 500)
    Frame3DGadget(#Frame3D, 1, 1, 793, 555, "iCat Utility", 0)
  EndIf
EndIf

GadgetToolTip(2, "Type in the item you are searching for, case insensitive, don't use WildCard characters")
GadgetToolTip(3, "Select the Drive and DIRectory where you want to start your search from")
GadgetToolTip(4, "Click on this button to actually start the search from your details")
GadgetToolTip(5, "This progress bar will show you just how far into the search you are")
GadgetToolTip(6, "This box will show the name of each directory passed through by the search")
GadgetToolTip(7, "Double Click on an item in this list to launch it with the associated program")

Repeat                                                                            ; Repeat the following loop
  EventID.l = WaitWindowEvent()                                                    ; What sort of event to wait for
  If EventID = #PB_EventGadget                                                    ; What event inside event type to act on
    Select EventGadgetID()                                                       ; Check for buttons being pressed
      Case #SearchLocation                                                       ; If searchbox button pressed
      ClearGadgetItemList(#ListBox)                                               ; Clear previous searches
      StartDrive$ = PathRequester("Select Drive and DIRectory to search", "C:\")  ; Get the drive and directory
      Case #StartButton                                                           ; If Star search button pressed
      Counter = 1                                                                 ; Zero the item counter
      Target$ = GetGadgetText(#SearchItem)                                        ; Get the target data
      If StartDrive$ = ""                                                         ; If no drive selected,
        StartDrive$ = "C:\"                                                       ; Default to drive C:\
      EndIf                                                                       ; Otherwise end
      GetList(StartDrive$, 0, Target$)                                            ; Start the search
    EndSelect                                                                    ; No more choices to process
    If DoubleClick() = 1                                                          ; if an item in the list is double clicked
      ItemString$ = GetGadgetText(#ListBox)                                        ; Get the data back from it
      If RunProgram(ItemString$, "", 0)                                            ; Feed it to a DOS shell
      EndIf                                                                        ; Otherwise end
    EndIf                                                                          ; Otherwise end
    If GetGadgetState(#ListBox)  -1                                              ; If an item in the list is selected
      ToolBox$ = GetGadgetText(#ListBox)                                           ; Get the data back from it
      ToolBox$ = GetFilePart(ToolBox$)                                             ; Return only the filename
      GadgetToolTip(7, ToolBox$)                                                   ; Make it popup as a tool tip
    EndIf                                                                          ; Otherwise end
  EndIf                                                                            ; Otherwise end
Until EventID = #PB_EventCloseWindow                                               ; No more events to process

End                                                                                ; End the program


Fangles


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 17, 2001 4:41 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by fred.

Multithreaded version of the above source code, with an instant STOP gadget. Thx Fangs, your code is simply very nice .

Code:
;
; Threaded version, to demonstrate how to use efficiently a thread...
;
; Change to the orginal source code: Added ListThread(), IsSearching, GlobalStartDrive$, GlobalTarget$
;

;-------------------------------------------------------------------------------------------------------------------------
; StartDrive$ = PathRequester("Select the Drive and the DIRectory to CATalogue please", "C:\")  ; Drive, Dir to cat
; Setup the number of gadgets for the initial display
;--------------------------------------------------------------------------------------------------------------------------

InitGadget(12)

#SearchItem = 2
#SearchLocation = 3
#StartButton = 4
#NumGadget = 5
#DirTitle = 6
#ListBox = 7
#Frame3D = 8

#ButtonLength = 125
#ButtonHeight = 25
#ButtonX = 5
#ButtonY = 15

;--------------------------------------------------------------------------------------------------------------------------

Global IsSearching, GlobalStartDrive$, GlobalTarget$

Procedure GetList(SourceDirectory$, Start, Pattern$)
 
  Shared Counter
 
  If ExamineDirectory(Start, SourceDirectory$, "*.*") And IsSearching
    Repeat
      Type = NextDirectoryEntry()
      If Type = 2
        If DirectoryEntryName()  "." And DirectoryEntryName()  ".."
          a$ = SourceDirectory$ + DirectoryEntryName() + "\"
          GetList(a$, Start + 1, Pattern$)
          UseDirectory(Start)
        EndIf
      Else
        If Type = 1 And FindString(UCase(DirectoryEntryName()), UCase(Pattern$), 1)  0
          Place$ = SourceDirectory$ + DirectoryEntryName()
          SetGadgetText(5, "   " + Str(Counter) + " Matches")
          SetGadgetText(6, SourceDirectory$)
          AddGadgetItem(7, -1, Place$)
          Counter + 1
        EndIf
      EndIf
    Until Type = 0
  EndIf
 
EndProcedure


Procedure ListThread(Parameter)
  GetList(GlobalStartDrive$, 0, GlobalTarget$)
  SetGadgetText(#StartButton, "Start Searching")
  IsSearching = 0
EndProcedure

;SetGadgetFont(2)

If OpenWindow(0, 5, 5, 800, 590, #PB_Window_SystemMenu,"iFind, v2")
  If CreateGadgetList(WindowID())
    StringGadget(#SearchItem, #ButtonX, #ButtonY, #ButtonLength, #ButtonHeight,"")
    ButtonGadget(#SearchLocation, #ButtonX,45, #ButtonLength, #ButtonHeight,"Search Where?")
    ButtonGadget(#StartButton, #ButtonX,75, #ButtonLength, #ButtonHeight,"Start Searching")
    TextGadget(#NumGadget, #ButtonX, 105, #ButtonLength, #ButtonHeight, "")
    TextGadget(#DirTitle, 135, #ButtonY, 655, #ButtonHeight, "")
    ListViewGadget(#ListBox, 135, 45, 655, 500)
    Frame3DGadget(#Frame3D, 1, 1, 793, 555, "iCat Utility", 0)
  EndIf
EndIf

GadgetToolTip(2, "Type in the item you are searching for, case insensitive, don't use WildCard characters")
GadgetToolTip(3, "Select the Drive and DIRectory where you want to start your search from")
GadgetToolTip(4, "Click on this button to actually start the search from your details")
GadgetToolTip(5, "This progress bar will show you just how far into the search you are")
GadgetToolTip(6, "This box will show the name of each directory passed through by the search")
GadgetToolTip(7, "Double Click on an item in this list to launch it with the associated program")

Repeat                                                                          ; Repeat the following loop
  EventID.l = WaitWindowEvent()                                                  ; What sort of event to wait for
  If EventID = #PB_EventGadget                                                   ; What event inside event type to act on
    Select EventGadgetID()                                                       ; Check for buttons being pressed
      Case #SearchLocation                                                       ; If searchbox button pressed
        ClearGadgetItemList(#ListBox)                                               ; Clear previous searches
        GlobalStartDrive$ = PathRequester("Select Drive and DIRectory to search", "C:\")  ; Get the drive and directory
       
      Case #StartButton                                                           ; If Star search button pressed
        If IsSearching = 0
          IsSearching = 1
          ClearGadgetItemList(#ListBox)                                               ; Clear previous searches
     
          Counter = 1                                                                 ; Zero the item counter
          GlobalTarget$ = GetGadgetText(#SearchItem)                                  ; Get the target data
          If GlobalStartDrive$ = ""                                                   ; If no drive selected,
            GlobalStartDrive$ = "C:\"                                                 ; Default to drive C:\
          EndIf                                                                      ; Otherwise end
          CreateThread(@ListThread(), 0)                                              ; Start the search
          SetGadgetText(#StartButton, "Stop !")
        Else
          IsSearching = 0
          SetGadgetText(#StartButton, "Start Searching")
        EndIf
       
    EndSelect                                                                    ; No more choices to process
    If DoubleClick() = 1                                                          ; if an item in the list is double clicked
      ItemString$ = GetGadgetText(#ListBox)                                        ; Get the data back from it
      If RunProgram(ItemString$, "", 0)                                            ; Feed it to a DOS shell
      EndIf                                                                        ; Otherwise end
    EndIf                                                                          ; Otherwise end
    If GetGadgetState(#ListBox)  -1                                              ; If an item in the list is selected
      ToolBox$ = GetGadgetText(#ListBox)                                           ; Get the data back from it
      ToolBox$ = GetFilePart(ToolBox$)                                             ; Return only the filename
      GadgetToolTip(7, ToolBox$)                                                   ; Make it popup as a tool tip
    EndIf                                                                          ; Otherwise end
  EndIf                                                                            ; Otherwise end
Until EventID = #PB_EventCloseWindow                                               ; No more events to process




Fred - AlphaSND


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 19, 2001 8:35 am 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Fangbeast.

Quote:
Multithreaded version of the above source code, with an instant STOP gadget. Thx Fangs, your code is simply very nice .


fred, I've added a copy button (to copy matches in the list to a dir of your choice), An uppercase and lowercase button (to flip the case of the filenames on disk and in the list) and changed the files to load simultaenously in the listviewbox and a linked list as the listmode is only really useful for display and not major manipulation.

Should I repost the new code here?

Fangles


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 19, 2001 2:30 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by fred.

Quote:
fred, I've added a copy button (to copy matches in the list to a dir of your choice), An uppercase and lowercase button (to flip the case of the filenames on disk and in the list) and changed the files to load simultaenously in the listviewbox and a linked list as the listmode is only really useful for display and not major manipulation.

Should I repost the new code here?


Hum, yes. I think a code section would be fine, with an auto upload. Paul, could you do that ?

Fred - AlphaSND


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 19, 2001 3:40 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Paul.

Okay, I've set up a simple upload section on the PB Resources Site. Just ZIP up your PB file along with a README.TXT file describing what your code is/does and whatever other notes you would like included.

When I get more time, I will make it a little fancier but hopefully for now, it will do the job.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 20, 2001 11:53 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Fangbeast.

Quote:
Hum, yes. I think a code section would be fine, with an auto upload. Paul, could you do that ?
Fred - AlphaSND


I uploaded the first version yesterday but I added a new button last night and made the form look a whole lot better (more frames, betetr layout etc and more comments) so I will upload that a little later toad.

Fangles


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 23, 2001 1:18 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Fangbeast.

Quote:
Hum, yes. I think a code section would be fine, with an auto upload. Paul,


Uploaded another verison to the resource site and got some good feedback from a large corporation that say the PureBasic one is faster than the file searching built into Windows (Take an evil bow Fred!!)

To this one I added search and replace strings in any portion of the filename for files in the list. Next I will add insert and delete functions with the option of starting from any position defined by the user.

Of course, you guys can also write bits for it:):) (I'm having a hard time with the gui, getting a bit complicated, need an IDE that can handle Panel gadgets directly)


Fangles


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye