Finder Icon Badging...
-
Hi List:
I am working on an application that would be much more ~compelling~ if
I were able to badge Icons in the Finder?
Is this possible? If so, does anyone have some sample code or a
resource to point me at?
Thanks,
cmp
http://www.pycs.net/cmp
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
On Feb 1, 2004, at 4:39 PM, Christopher Pavicich wrote:
> Hi List:
>
> I am working on an application that would be much more ~compelling~ if
> I were able to badge Icons in the Finder?
>
> Is this possible? If so, does anyone have some sample code or a
> resource to point me at?
Hmm. Define badge. Or perhaps icon. Do you mean to permanently
change certain files' icons to include a badge, or to temporarily mark
them with one?
Peter
-- ---<>--- --
A house without walls cannot fall.
Help build the world's largest encyclopedia at Wikipedia.org
-- ---<>--- --
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
At 16:01 -0800 02/02/2004, <cocoa-dev-request...> wrote:
> From: Peter Jaros <rjaros...>
> Subject: Re: Finder Icon Badging...
> Date: Mon, 2 Feb 2004 18:03:56 -0500
> To: Christopher Pavicich <pavicich...>
>
> On Feb 1, 2004, at 4:39 PM, Christopher Pavicich wrote:
>
>> Hi List:
>>
>> I am working on an application that would be much more ~compelling~ if
>> I were able to badge Icons in the Finder?
>>
>> Is this possible? If so, does anyone have some sample code or a
>> resource to point me at?
Sorry, I missed this question first time around.
Peter, badging is a way of overlaying another icon over a file's or folders current icon. I use this to overlay a little "XRay" tag over .txt or .rtf reports generated by XRay.
Here's the code I use, it seems to work well. Of course this has little to do with Cocoa, you must do
#include <Carbon/Carbon.h>
This little function returns YES if the badging was successful. The first argument is the full path to the item which can be a file or folder. The second argument is the badge icon in NSData format. You could generate it by reading a .icns file into NSData.
If it's a file, it assumes there's no resource fork, and it will create one; if it's a folder or package it will generate the badge as a custom icon file, and assumes there is none at the outset.
Changing this to accept existing resource forks or custom icon files is left as an exercise to the reader ;-).
BOOL AddBadgeToItem(NSString* path,NSData* tag) {
FSCatalogInfo info;
FSRef par;
FSRef ref;
Boolean dir = false;
if (tag&&Jaguar&&(FSPathMakeRef([path fileSystemRepresentation],&par,&dir)==noErr)) {
HFSUniStr255 fork = {0,{0}};
SInt16 refnum = kResFileNotOpened;
FSGetResourceForkName(&fork);
if (dir) {
memset(&info,0,sizeof(info));
((FileInfo*)(&info.finderInfo))->finderFlags = kIsInvisible;
if (FSCreateResourceFile(&par,5,(UniChar*)"\000I\000c\000o\000n\000\r",kFSCatInfoFinderInfo,&info,fork.length,fork.unicode,&ref,NULL)!=noErr) {
return NO;
}
} else {
BlockMoveData(&par,&ref,sizeof(FSRef));
if (FSCreateResourceFork(&ref,fork.length,fork.unicode,0)!=noErr) {
return NO;
}
}
if (FSOpenResourceFile(&ref,fork.length,fork.unicode,fsRdWrPerm,&refnum)!=noErr) {
return NO;
}
if (refnum!=kResFileNotOpened) {
CustomBadgeResource* cbr;
int len = [tag length];
Handle h = NewHandle(len);
if (h) {
BlockMoveData([tag bytes],*h,len);
AddResource(h,kIconFamilyType,128,"\p");
WriteResource(h);
ReleaseResource(h);
}
h = NewHandle(sizeof(CustomBadgeResource));
if (h) {
cbr = (CustomBadgeResource*)*h;
memset(cbr,0,sizeof(CustomBadgeResource));
cbr->version = kCustomBadgeResourceVersion;
cbr->customBadgeResourceID = 128;
AddResource(h,kCustomBadgeResourceType,kCustomBadgeResourceID,"\p");
WriteResource(h);
ReleaseResource(h);
}
UpdateResFile(refnum);
CloseResFile(refnum);
if (FSGetCatalogInfo(&par,kFSCatInfoFinderXInfo,&info,NULL,NULL,NULL)==noErr) {
((ExtendedFileInfo*)(&info.extFinderInfo))->extendedFinderFlags = kExtendedFlagHasCustomBadge;
FSSetCatalogInfo(&par,kFSCatInfoFinderXInfo,&info);
}
}
}
return NO;
}
Does this do what you want?
--
Rainer Brockerhoff <rainer...>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
On Feb 2, 2004, at 7:28 PM, Rainer Brockerhoff wrote:
>
> Here's the code I use, it seems to work well. Of course this has
> little to do with Cocoa, you must do
> #include <Carbon/Carbon.h>
>
>
A Cocoa solution to this problem was presented in the Cocoa Tips and
Tricks session at WWDC. The code is available to attendees on the ADC
site, and has been submitted to sample code (so everyone can have it).
Anyways, here is the relevant method from the DotView class.
- (void)updateApplicationBadge {
NSImage *appImage, *newAppImage;
NSSize newAppImageSize;
NSRect badgeRect;
// Grab the unmodified application image.
appImage = [[NSWorkspace sharedWorkspace] iconForFile:[[NSBundle
mainBundle] bundlePath]];
// Application icons should be 128 x 128
newAppImageSize = NSMakeSize(kApplicationIconImageSize,
kApplicationIconImageSize);
newAppImage = [[NSImage alloc] initWithSize:newAppImageSize];
// Compute a location for the badge. Put the badge in the upper,
right one-third of the full image.
badgeRect.size = NSMakeSize(floor((newAppImageSize.width / 3.0) +
.5), floor((newAppImageSize.height / 3.0) + .5));
badgeRect.origin = NSMakePoint(newAppImageSize.width -
NSWidth(badgeRect), newAppImageSize.height - NSHeight(badgeRect));
// Draw into the new image (the badged image)
[newAppImage lockFocus];
// First draw the unmodified app image.
[appImage drawInRect:NSMakeRect(0, 0, newAppImageSize.width,
newAppImageSize.height)
fromRect:NSMakeRect(0, 0, [appImage size].width,
[appImage size].height)
operation:NSCompositeCopy
fraction:1.0];
// Now draw the badge, (it should look like a color swatch with a
black border).
[color set];
NSRectFill(badgeRect);
[[NSColor blackColor] set];
NSFrameRect(badgeRect);
[newAppImage unlockFocus];
// Set the new icon: a badged icon.
[NSApp setApplicationIconImage:newAppImage];
[newAppImage release];
// Now that we've modified the application image that is being used
by the dock, we need to clean up the icon before the application
terminates.
if (!registeredForTerminate) {
// If we've never registered to hear about application termination, do
that now.
registeredForTerminate = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillTerminateNotification:)
name:NSApplicationWillTerminateNotification object:NSApp];
}
}
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
At 03:48 -0500 03/02/2004, Scott Anguish wrote:
> On Feb 2, 2004, at 7:28 PM, Rainer Brockerhoff wrote:
>> Here's the code I use, it seems to work well. Of course this has little to do with Cocoa, you must do
>> #include <Carbon/Carbon.h>
>> ...
>
> A Cocoa solution to this problem was presented in the Cocoa Tips and Tricks session at WWDC. The code is available to attendees on the ADC site, and has been submitted to sample code (so everyone can have it).
>
> Anyways, here is the relevant method from the DotView class.
>
> - (void)updateApplicationBadge {
> ...
Just to keep the record clear...
Scott's code (or rather the DotView code) is for Dock icon badging, which temporarily changes the application's icon in the dock. (XRay has been doing this too for over a year BTW ;-)). I believe there's a variation for changing minimized window icons in the dock, too, floating around.
However, what Christopher asked for was permanently badging an icon as seen in the Finder. This is described in the Icon Services docs at:
http://developer.apple.com/documentation/Carbon/Conceptual/Icon_Service_nd_
Utilities/03tasks/chapter_3_section_3.html
namely the 'badg' resource.
--
Rainer Brockerhoff <rainer...>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
On Feb 3, 2004, at 4:13 AM, Rainer Brockerhoff wrote:
> At 03:48 -0500 03/02/2004, Scott Anguish wrote:
>> On Feb 2, 2004, at 7:28 PM, Rainer Brockerhoff wrote:
>>> Here's the code I use, it seems to work well. Of course this has
>>> little to do with Cocoa, you must do
>>> #include <Carbon/Carbon.h>
>>> ...
>>
>> A Cocoa solution to this problem was presented in the Cocoa Tips and
>> Tricks session at WWDC. The code is available to attendees on the
>> ADC site, and has been submitted to sample code (so everyone can have
>> it).
>>
>> Anyways, here is the relevant method from the DotView class.
>>
>> - (void)updateApplicationBadge {
>> ...
>
> Just to keep the record clear...
>
> Scott's code (or rather the DotView code) is for Dock icon badging,
> which temporarily changes the application's icon in the dock. (XRay
> has been doing this too for over a year BTW ;-)). I believe there's a
> variation for changing minimized window icons in the dock, too,
> floating around.
>
> However, what Christopher asked for was permanently badging an icon as
> seen in the Finder. This is described in the Icon Services docs at:
> http://developer.apple.com/documentation/Carbon/Conceptual/
> Icon_Service_nd_Utilities/03tasks/chapter_3_section_3.html
> namely the 'badg' resource.
>
>
Ack, you're right. I've filed an enhancement request to allow
NSWorkspace to set the icon of a file, as well as get the data back.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
as far as code that works for this type of badging then..
look for Troy Stephen's Icon Family framework. That's what you need.
It allows you to set the icon for a file from an NSImage. Google
should provide the link.
On Feb 3, 2004, at 4:13 AM, Rainer Brockerhoff wrote:
> At 03:48 -0500 03/02/2004, Scott Anguish wrote:_______________________________________________
>> On Feb 2, 2004, at 7:28 PM, Rainer Brockerhoff wrote:
>>> Here's the code I use, it seems to work well. Of course this has
>>> little to do with Cocoa, you must do
>>> #include <Carbon/Carbon.h>
>>> ...
>>
>> A Cocoa solution to this problem was presented in the Cocoa Tips and
>> Tricks session at WWDC. The code is available to attendees on the
>> ADC site, and has been submitted to sample code (so everyone can have
>> it).
>>
>> Anyways, here is the relevant method from the DotView class.
>>
>> - (void)updateApplicationBadge {
>> ...
>
> Just to keep the record clear...
>
> Scott's code (or rather the DotView code) is for Dock icon badging,
> which temporarily changes the application's icon in the dock. (XRay
> has been doing this too for over a year BTW ;-)). I believe there's a
> variation for changing minimized window icons in the dock, too,
> floating around.
>
> However, what Christopher asked for was permanently badging an icon as
> seen in the Finder. This is described in the Icon Services docs at:
> http://developer.apple.com/documentation/Carbon/Conceptual/
> Icon_Service_nd_Utilities/03tasks/chapter_3_section_3.html
> namely the 'badg' resource.
>
>
> --
> Rainer Brockerhoff <rainer...>
> Belo Horizonte, Brazil
> "It's extremely unlucky to be superstitious, for no other reason
> than it is always unlucky to be colossally stupid." (Stephen Fry)
> Weblog: http://www.brockerhoff.net/bb/viewtopic.php
> _______________________________________________
> cocoa-dev mailing list | <cocoa-dev...>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
Rainer, Scott, et al.
I want to (semi-) permanently tag a documents icon. I am trying
to show SCM state in the Finder. Checkout http://scplugin.tigris.org to get an idea of what I am doing.
1. Thanks for the code. I fumbled around with IconServices for a while and I wanted to pull my hair out.
2. I think Rainer's code does what I want. I couldn;t find an example badge to use, but
when I ran it, it did replace the files icon. It took a while to for the finder to notice that
the icon changed. Is there someway around this?
Rainer, do you have an example badge that you would mind sending me off list?
3. I will check into IconFamily.
Thanks again for all your help. Its much appreciated.
CMP
On Tuesday, February 03, 2004, at 03:50PM, Scott Anguish <sanguish...> wrote:
> as far as code that works for this type of badging then..
>
> look for Troy Stephen's Icon Family framework. That's what you need.
> It allows you to set the icon for a file from an NSImage. Google
> should provide the link.
>
>
> On Feb 3, 2004, at 4:13 AM, Rainer Brockerhoff wrote:
>
>> At 03:48 -0500 03/02/2004, Scott Anguish wrote:
>>> On Feb 2, 2004, at 7:28 PM, Rainer Brockerhoff wrote:
>>>> Here's the code I use, it seems to work well. Of course this has
>>>> little to do with Cocoa, you must do
>>>> #include <Carbon/Carbon.h>
>>>> ...
>>>
>>> A Cocoa solution to this problem was presented in the Cocoa Tips and
>>> Tricks session at WWDC. The code is available to attendees on the
>>> ADC site, and has been submitted to sample code (so everyone can have
>>> it).
>>>
>>> Anyways, here is the relevant method from the DotView class.
>>>
>>> - (void)updateApplicationBadge {
>>> ...
>>
>> Just to keep the record clear...
>>
>> Scott's code (or rather the DotView code) is for Dock icon badging,
>> which temporarily changes the application's icon in the dock. (XRay
>> has been doing this too for over a year BTW ;-)). I believe there's a
>> variation for changing minimized window icons in the dock, too,
>> floating around.
>>
>> However, what Christopher asked for was permanently badging an icon as
>> seen in the Finder. This is described in the Icon Services docs at:
>> http://developer.apple.com/documentation/Carbon/Conceptual/
>> Icon_Service_nd_Utilities/03tasks/chapter_3_section_3.html
>> namely the 'badg' resource.
>>
>>
>> --
>> Rainer Brockerhoff <rainer...>
>> Belo Horizonte, Brazil
>> "It's extremely unlucky to be superstitious, for no other reason
>> than it is always unlucky to be colossally stupid." (Stephen Fry)
>> Weblog: http://www.brockerhoff.net/bb/viewtopic.php
>> _______________________________________________
>> cocoa-dev mailing list | <cocoa-dev...>
>> Help/Unsubscribe/Archives:
>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>> Do not post admin requests to the list. They will be ignored.
>
>
>
--cmp
<pavicich...>
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
Christopher,
At 16:00 -0500 03/02/2004, Christopher Pavicich wrote:
> Rainer, Scott, et al.
>
> I want to (semi-) permanently tag a documents icon. I am trying
> to show SCM state in the Finder. Checkout http://scplugin.tigris.org to get an idea of what I am doing.
OK. You want set a badge on a document to show its CVS state. Badge resources should work for that...
...however you may want to look into two issues: one, putting a badge on a file will change its modification timestamp unless you take pains to change it back afterwards; two, this will also create a resource fork for the file, causing its total size to change. No idea how CVS will handle this.
> 1. Thanks for the code. I fumbled around with IconServices for a while and I wanted to pull my hair out.
It's not the easiest of APIs to use, that's for sure; parts of it date from the original Mac and every release new stuff has been piled on.
> 2. I think Rainer's code does what I want. I couldn;t find an example badge to use, but
> when I ran it, it did replace the files icon. It took a while to for the finder to notice that
> the icon changed. Is there someway around this?
Any icon with lots of transparent space should do. Download XRay from my site, open any file with it, and generate a report in .txt format. Open the report with Resorcerer or ResEdit, you'll see a 'badg' resource and the 'icns' resource with a sample badge.
For the Finder to notice the change you have to notify it. The FNNotity function usually does that.
> Rainer, do you have an example badge that you would mind sending me off list?
Will do.
> 3. I will check into IconFamily.
I just downloaded it and looked what it does. It does not handle badges as such, although the techniques used could be adapted to generate the necessary 'icns' resource from an arbitrary picture; but you'll also need to create a 'badg' resource. Besides, in your case, you'll probably use several pre-built icons anyway.
--
Rainer Brockerhoff <rainer...>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored. -
On Tue, Feb 03, 2004 at 07:22:27PM -0200, Rainer Brockerhoff wrote:
> OK. You want set a badge on a document to show its CVS state. Badge
> resources should work for that... ...however you may want to look
> into two issues: one, putting a badge on a file will change its
> modification timestamp unless you take pains to change it back
> afterwards; two, this will also create a resource fork for the file,
> causing its total size to change. No idea how CVS will handle this.
Standard command-line CVS (and Subversion) ignore the resource fork,
so this should not be an issue as long as the modification date is set
back.
> For the Finder to notice the change you have to notify it. The FNNotity function usually does that.
Or there is a NSWorkspace equivalent in Cocoa.
--
=Nicholas Riley <njriley...> | <http://www.uiuc.edu/ph/www/njriley>
_______________________________________________
cocoa-dev mailing list | <cocoa-dev...>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.



