I have a contextual menu plugin (XYZ.plugin) located
at "/Library/Contextual Menu Items/". This
is invoked when the user right-clicks on a
file/folder. There are custom items in the contextual
menu. Depending on the selection i need to provide a
custom icon to the file/folder.
In the Plugin Code i do something like this: I have a
file abc.txt to which I need to give a custom icon.
Now I get the IconRef of the file abc.txt and get the
IconRef of the "bsd.icns" [Icon file] file and form a
composite IconRef and apply this composite IconRef to
abc.txt file.
In my plugin i am forcing the finder to call my
overrided function -
SCFinderIconOverlayGetIconRefFromFileInfo when it
makes a call to "GetIconRefFromFileInfo" by using
mach_override("_GetIconRefFromFileInfo", NULL,
SCFinderIconOverlayGetIconRefFromFileInfo,
(void**) &gGetIconRefFromFileInfo);
and the code for
SCFinderIconOverlayGetIconRefFromFileInfo is here:
static OSStatus
SCFinderIconOverlayGetIconRefFromFileInfo(
const FSRef * inRef, UniCharCount
inFileNameLength,
const UniChar * inFileName,
FSCatalogInfoBitmap inWhichInfo,
const FSCatalogInfo * inCatalogInfo,
IconServicesUsageFlags inUsageFlags,
IconRef * outIconRef,
SInt16 * outLabel)
{
osStat = FSRefMakePath(inRef,szBuffer,MAX_PATH);
osStat = FSPathMakeRef(szBuffer,&fsRef1,&bDir);
if(strcmp(szBuffer,"/Users/Username/Desktop/Finder_OverlayIcon/abc.txt")!=0)
{
printf("FILE NOT MATCHING RET DEFAULT\n");
err = gGetIconRefFromFileInfo(inRef,
inFileNameLength,
inFileName,
inWhichInfo,
inCatalogInfo,
inUsageFlags,
outIconRef,
outLabel);
return noErr;
}
osStat = FSGetCatalogInfo (&fsRef1,
inWhichInfo,
&fsInfo1,
&hfsUni1,
&fsSpec1,
NULL);
//finder info for incoming file
finderInfo.fdCreator = kUnknownType;
finderInfo.fdType = kUnknownType;
newErr = FSpGetFInfo( &fsSpec1, &finderInfo );
//Incoming file's icon for background.
err = gGetIconRefFromFileInfo(inRef,
inFileNameLength,
inFileName,
inWhichInfo,
inCatalogInfo,
inUsageFlags,
&backgroundIconRef,
outLabel);
//bsd.icns file's icon for foreground.
osStat =
FSPathMakeRef("/Users/Username/Desktop/Finder_OverlayIcon/bsd.icns",&fsRef,&bDir);
osStat = FSGetCatalogInfo (&fsRef,
inWhichInfo,
&fsInfo,
&hfsUni,
&fsSpec,
NULL );
//even using the finderInfo.fdtype &
finderInfo.fdCreator is not useful.
newErr =
RegisterIconRefFromFSRef(kUnknownType,kUnknownType,&fsRef,&foregroundIconRef);
//the composite of the foreground and the background
icons.
newErr = CompositeIconRef(backgroundIconRef,
foregroundIconRef, &compositeIconRef);
*outIconRef = compositeIconRef; //send the composite
as the icon to be displayed for the abc.txt file
//decrement the reference count of back & foreground
Icons.
//cleanup
return noErr;
}
On testing, to my astonishment, all the files with
file extension ".txt" have a composite Icon while only
abc.txt should have the composite and the rest of the
.txt files should have their original icon. What wrong
am i doing here? Pls note that in the
SCFinderIconOverlayGetIconRefFromFileInfo function of
the plugin, i return the original icon if the file is
not abc.txt.
When i log the results, for all other files other than
abc.txt the SCFinderIconOverlayGetIconRefFromFileInfo
returns the default icon and composite icon for
abc.txt correctly.
Can any one point what mistake am i doing? I have lost
sufficient time on this. Also any one from Apple could
help me?
Thanks In advance.
________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden
This email sent to email@hidden