I have been using the “MacIcon Classes” of macoslib, (the latest version, June 6), to display icons of a folderitem in a dropdown menu.
It works in XOJO 2019R1 but not in any version newer than that.
I am using macOS Catalina version 10.15.2 and I am getting these 4 errors…
FileManager.GetFSRefFromFolderItem, line 16
Type “FolderItem” has no member named “MacFSRef”
theFSRef = new FSRef(f.MacFSRef)
FileManager.GetFSRefFromFolderItem, line 16
There is more than one method with this name but this does not match any of the available signatures.
theFSRef = new FSRef(f.MacFSRef)
MacIcon.Draw, line 18
This item does not exist
grafPort = g.Handle(Graphics.handleTypeCGrafPtr)
MacIcon.Draw, line 18
There is more than one method with this name but this does not match any of the available signatures.
grafPort = g.Handle(Graphics.handleTypeCGrafPtr)
I am testing using Run, I cannot Build, on XOJO 2019r3.2
I would need some help here, this is beyond my capability, below is the code I am using, could you advise how to modify it to be able to use your recommendation?
// Make the base item, this is what will be doing the popping up
dim base as new MenuItem
dim mItem as MenuItem
Dim i, j as integer
j = 0
Dim TheDesktop as FolderItem = SpecialFolder.Desktop
If TheDesktop.Count < 1 then
msgbox "There are no items on the Desktop"
else
Dim item As folderitem
Dim TheIcon as MacIcon
Dim TheDesktopFilesTrueItemIcon as Picture
for i = 1 to TheDesktop.Count
item = TheDesktop.TrueItem(i)
TheIcon = MacIcon.NewIconFromFolderItem(item)
TheDesktopFilesTrueItemIcon = TheIcon
TheIcon.size = 18
If Trim(TheDesktop.TrueItem(i).DisplayName) = "" or TheDesktop.TrueItem(i).DisplayName.Left(2) = "• " or Trim(TheDesktop.TrueItem(i).DisplayName) = ".DS_Store" then
'Ignore these items
else
mItem = New MenuItem
mItem.Text = TheDesktop.TrueItem(i).DisplayName
mItem.Icon = TheIcon // TheDesktopFileTrueItemIcon
base.Append(mItem)
j = j + 1
end if
next i
end if
'msgbox str(j)
If j = 0 then
msgbox "There are no items on the Desktop."
Return True
else
End if
// Add a Separator
base.Append(new MenuItem(MenuItem.TextSeparator))
// Now display the menu
dim hitItem as MenuItem
hitItem = base.PopUp
if hitItem <> nil then
msgbox hitItem.Text
End if
Return True
although you should really move your code to more modern calls, the following should help you restore MacIcon functionalities.
If there is no NSClassFromString function in your project, create the following method in a module with global scope:
Public Function NSClassFromString(aClassName as CFStringRef) as Ptr
Declare Function NSClassFromString Lib "AppKit.framework" ( aClassName as CFStringRef ) As Ptr
Return NSClassFromString( aClassName )
End Function
In FileManager, replace the code for GetFSRefFromFolderItem with the following:
declare function URLWithString lib CocoaLib selector "URLWithString:" ( id as Ptr, URLString as CFStringRef ) as Ptr
declare function CFURLGetFSRef lib CarbonLib (CFURLRef as Ptr, ref as Ptr) as Boolean
dim url as Ptr = URLWithString( NSClassFromString( "NSURL" ), f.URLPath )
dim FSRef_ as new MemoryBlock( 80 )
if CFURLGetFSRef( url, FSRef_ ) then
return new FSRef( FSRef_ )
else
return nil
end if
I am not entirely sure it is going to work on Catalina but it works on Mojave.