Platforms to show: All Mac Windows Linux Cross-Platform

/MacClassic/Catalog Search/CatSearch Demo


Required plugins for this example: MBS MacClassic Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacClassic/Catalog Search/CatSearch Demo

This example is the version from Thu, 31th Jul 2019.

Project "CatSearch Demo.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class mainWindow Inherits Window
Control theList Inherits Listbox
ControlInstance theList Inherits Listbox
End Control
Control StartButton Inherits PushButton
ControlInstance StartButton Inherits PushButton
EventHandler Sub Action() StartTheSearch(WhatMenu.ListIndex+1) End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control url Inherits Label
ControlInstance url Inherits Label
End Control
Control volumePopup Inherits PopupMenu
ControlInstance volumePopup Inherits PopupMenu
EventHandler Sub Change() VolSelectionUpdate() // makes the "slow" or "fast" text visible End EventHandler
EventHandler Sub Open() RebuildVolMenu() volumePopup.ListIndex = 0 VolSelectionUpdate() // makes the "slow" or "fast" text visible End EventHandler
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control busyArrows Inherits ProgressWheel
ControlInstance busyArrows Inherits ProgressWheel
End Control
Control StopButton Inherits PushButton
ControlInstance StopButton Inherits PushButton
EventHandler Sub Action() theSearchTask.Stop() End EventHandler
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control WhatMenu Inherits PopupMenu
ControlInstance WhatMenu Inherits PopupMenu
EventHandler Sub Open() me.ListIndex = 0 End EventHandler
End Control
Control FastTxt Inherits Label
ControlInstance FastTxt Inherits Label
End Control
Control SlowTxt Inherits Label
ControlInstance SlowTxt Inherits Label
End Control
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean if x>url.left and x<url.left+url.width and y>url.top and y<url.top+url.height then url.textcolor = RGB(255,0,0) return true end if End EventHandler
EventHandler Sub MouseDrag(X As Integer, Y As Integer) if x>url.left and x<url.left+url.width and y>url.top and y<url.top+url.height then url.textcolor = RGB(255,0,0) else url.textcolor = RGB(0,0,255) end if End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer) url.textcolor = RGB(0,0,255) if x>url.left and x<url.left+url.width and y>url.top and y<url.top+url.height then ShowURL url.text end if End EventHandler
Sub RebuildVolMenu() // This routines rebuilds the volume popup menu // It is not a good solution, however, because // it does not properly update the list whenever // the user mounts or unmounts another volume. // To do that better, one should use a timer to // regularly check the list of available volumes, // and only if that changes, rebuild the popup menu. dim i as Integer, v as FolderItem volumePopup.DeleteAllRows() Redim volumeList(-1) for i = 0 to VolumeCount-1 v = Volume(i) if v <> nil then volumePopup.AddRow(v.name) volumeList.Append v end next End Sub
Sub SearchFinished() busyArrows.visible = false StopButton.visible = false StartButton.visible = true WhatMenu.enabled = true volumePopup.enabled = true End Sub
Sub StartTheSearch(what as Integer) theSearchTask = new SearchTask theSearchTask.searchMode = what theSearchTask.outputList = self.theList theSearchTask.searchVolume = me.theSelectedVolume theSearchTask.Run() busyArrows.visible = true StopButton.Top = StartButton.Top StopButton.Left = StartButton.Left StopButton.visible = true StartButton.visible = false WhatMenu.enabled = false volumePopup.enabled = false End Sub
Sub VolSelectionUpdate() theSelectedVolume = volumeList(volumePopup.ListIndex) if theSelectedVolume.VolSupportsCatSearchMBS then SlowTxt.visible = false FastTxt.visible = true else SlowTxt.Top = FastTxt.Top SlowTxt.Left = FastTxt.Left SlowTxt.visible = true FastTxt.visible = false end End Sub
Property Protected theSearchTask As SearchTask
Property Protected theSelectedVolume As FolderItem
Property Protected volumeList(0) As FolderItem
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem AppleAbout = "Nothing here yet ..."
End MenuBar
Class CatSearchExc Inherits RuntimeException
End Class
Class SearchTask Inherits Thread
EventHandler Sub Run() DoTheSearch(searchMode, outputList, searchVolume) mainWindow.SearchFinished() exception exc as RuntimeException mainWindow.SearchFinished() msgBox "Oops. An Exception occured in the SearchTask." End EventHandler
Sub DoTheSearch(what as Integer, theList as ListBox, theVol as FolderItem) // this demo lists all files of type "INIT" or invisibles on the boot volume, // depending on the passed value in the "what" parameter Dim err as Integer Dim f, vol as FolderItem Dim ok, foundOne as Boolean dim cat as CatSearchMBS theList.DeleteAllRows vol = theVol if vol = nil then beep MsgBox "Vol does no longer exists - you need to re-select a vol from the popup." return end cat=new CatSearchMBS // first, open a CatSearch record cat.ResponseTimeout=1000 if not cat.Search(vol, true) then Msgbox "Oops - Cat.Search() failed" raise new CatSearchExc end if what = 1 then // we want to search for files with file type "INIT" cat.fileType="INIT" elseif what = 2 then // we want to search for invisible files Cat.FileFlags=&H4000 cat.fileflagsmask=&H4000 else // we want to search for files and folders containing the partial name "Appl" Cat.Name="Apple" cat.partialName=true end foundOne = false // the search loop do if UserCancelled or stopped then return end err = Cat.SearchNext // search next occurance of that type of files if err = 0 then // found a file f = Cat.result // get the found file (as a FolderItem) if f <> nil then // add the file to the ListBox control theList.AddRow f.NativePath foundOne = true else // this shouldn't happen msgbox "Oops - Cat.GetItem = nil?" raise new CatSearchExc end end loop until err < 0 if err = -50 then msgBox "This volume does not support the CatSearch function" elseif err = -39 then // err -39 means end of found items (or none found) if not foundOne then msgBox "No files found" end else msgBox "Oops - CatSearchNext error: " + str(err) raise new CatSearchExc end End Sub
Sub Stop() stopped = true End Sub
Property outputList As ListBox
Property searchMode As Integer
Property searchVolume As FolderItem
Property Protected stopped As Boolean
End Class
Class App Inherits Application
End Class
End Project

See also:

The items on this page are in the following plugins: MBS MacClassic Plugin.


The biggest plugin in space...