Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacClassic/FolderItem Demo
Function:
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/FolderItem Demo
This example is the version from Sun, 17th Mar 2012.
Project "FolderItem Demo.rbp"
FileTypes
Filetype anyfile
End FileTypes
Class mainWindow Inherits Window
Control OpenItBut Inherits PushButton
ControlInstance OpenItBut Inherits PushButton
EventHandler Sub Action() if theDoc = nil then MsgBox "You need to specify a document first." else OpenIt end exception exc as RuntimeException msgBox "Oops. An Exception occured!" 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 appDrop Inherits GroupBox
ControlInstance appDrop Inherits GroupBox
EventHandler Sub DropObject(obj As DragItem, action As Integer) if obj.folderItemAvailable and obj.folderItem.MacType = "APPL" then theApp = obj.folderItem appName.caption = theApp.name useFile.value = true creatorEdit.text = theApp.MacCreator else beep end End EventHandler
EventHandler Sub Open() me.AcceptFileDrop "anyfile" End EventHandler
End Control
Control appName Inherits Label
ControlInstance appName Inherits Label
End Control
Control docDrop Inherits GroupBox
ControlInstance docDrop Inherits GroupBox
EventHandler Sub DropObject(obj As DragItem, action As Integer) if obj.folderItemAvailable then if obj.folderItem.directory then beep else theDoc = obj.folderItem docName.caption = theDoc.name OpenItBut.enabled = true end end End EventHandler
EventHandler Sub Open() me.AcceptFileDrop "anyfile" End EventHandler
End Control
Control docName Inherits Label
ControlInstance docName Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control inFGCheck Inherits CheckBox
ControlInstance inFGCheck Inherits CheckBox
End Control
Control useFile Inherits RadioButton
ControlInstance useFile Inherits RadioButton
EventHandler Sub Action() if theApp = nil then beep useDefault.value = true end End EventHandler
End Control
Control useCreator Inherits RadioButton
ControlInstance useCreator Inherits RadioButton
End Control
Control creatorEdit Inherits TextField
ControlInstance creatorEdit Inherits TextField
EventHandler Function KeyDown(Key As String) As Boolean if key >= " " then useCreator.value = true end End EventHandler
End Control
Control useDefault Inherits RadioButton
ControlInstance useDefault Inherits RadioButton
End Control
Control revealBut Inherits PushButton
ControlInstance revealBut Inherits PushButton
EventHandler Sub Action() dim theCreatorApp as FolderItem if theDoc = nil then MsgBox "You need to specify a document first." else if useFile.value then theCreatorApp = theApp elseif useDefault.value then theCreatorApp = theDoc.CreatorAppMBS else theCreatorApp = theDoc.CreatorAppMBS(creatorEdit.text) end if theCreatorApp = nil then MsgBox "No application for this creator is registered in the DTDB (Desktop Database)." else RevealItemInFinder (theCreatorApp) BringFinderToFront end end End EventHandler
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 OpenIt() Dim ok as Boolean if useDefault.value then ok = theDoc.LaunchMBS(inFGCheck.Value) elseif useFile.value then ok = theDoc.OpenWithAppMBS(theApp, inFGCheck.Value) else ok = theDoc.OpenWithAppMBS(theDoc.CreatorAppMBS(creatorEdit.text), inFGCheck.Value) end if not ok then msgBox "Launch failed." end End Sub
Property theApp As FolderItem
Property theDoc 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"
End MenuBar
Module FinderAppleEvents
Sub BringFinderToFront() Dim ok as Boolean Dim ae as AppleEvent ae = NewAppleEvent ("misc", "actv", "MACS") // kAEActivate if ae <> nil then ok = ae.Send end if not ok then 'MsgBox "Oops, Activate failed unexpectedly" end End Sub
Function FinderSupportsOSL() As Boolean Dim l as Integer if not System.Gestalt("fndr", l) then l = 0 end return BitwiseAnd(l, 8) <> 0 End Function
Sub RevealItemInFinder(f as FolderItem) Dim ok as Boolean ok = sendItemAE ("misc", "mvis", "MACS", f) // kAEMakeItemVisible if not ok then 'MsgBox "Oops, Reveal failed unexpectedly" end End Sub
Sub UpdateItemInFinder(f as FolderItem) Dim err as Integer Dim ok as Boolean ok = sendItemAE ("fndr", "fupd", "MACS", f.Parent) // kAESync if ok then ok = sendItemAE ("fndr", "fupd", "MACS", f) // kAESync end if not ok then 'MsgBox "Oops, Update failed unexpectedly" end End Sub
Protected Function sendItemAE(s1 as String, s2 as String, s3 as String, f as FolderItem) As Boolean Dim ae as AppleEvent Dim list as AppleEventDescList if FinderSupportsOSL() then ae = NewAppleEvent (s1, s2, s3) if ae <> nil then list = New AppleEventDescList list.AppendFolderItem (f) ae.DescListParam("----") = list return ae.Send end end return false End Function
End Module
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo Chart Plugins