Re: Renaming the "Cancel" button for NSOpenPanel
Re: Renaming the "Cancel" button for NSOpenPanel
- Subject: Re: Renaming the "Cancel" button for NSOpenPanel
- From: Severin Kurpiers <email@hidden>
- Date: Sat, 17 Mar 2007 09:18:37 +0100
Hi Theodore,
probably the easiest way will be to extend the class NSOpenPanel by a
category. Something like this:
1. Create the file NSOpenPanelExtension.h that contains:
#import <Cocoa/Cocoa.h>
@interface NSOpenPanel (Extension)
- (void)setCancelButtonTitle:(NSString *)newTitle;
@end
2. Create the file NSOpenPanelExtension.m that contains:
#import "NSOpenPanelExtension.h"
@implementation NSOpenPanel (Extension)
- (void)setCancelButtonTitle:(NSString *)newTitle
{
NSRect oldFrame = [_cancelButton frame];
[_cancelButton setTitle:newTitle];
[_cancelButton sizeToFit];
NSRect newFrame = [_cancelButton frame];
float delta = oldFrame.size.width - newFrame.size.width;
[_cancelButton setFrameOrigin:NSMakePoint(oldFrame.origin.x + delta,
oldFrame.origin.y)];
}
@end
3. Use it where you need it:
#import "NSOpenPanelExtension.h"
...
NSOpenPanel *panel = [NSOpenPanel openPanel];
NSString *cancelText = @"default location";
[panel setCancelButtonTitle:cancelText];
[panel beginSheetForDirectory:nil file:nil modalForWindow:window
modalDelegate:self didEndSelector:@selector(panelDidEnd:
returnCode: contextInfo:) contextInfo:nil];
...
- (void)panelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
if(returnCode == NSOKButton)
{
// do something
}
else if(returnCode == NSCancelButton)
{
// do something else
}
}
This is only the idea, there is of course some fine-tuning necessary.
The usual disclaimer (no warranty etc.) applies.
I hope this helps,
Severin Kurpiers
On Fri, 16 Mar 2007, at 21:58:32, Theodore H. Smith wrote:
Hi people,
I've got an app, that's using NSOpenPanel to choose folders. We allow
the user to choose where they export their files to.
But if they press cancel, we'll just export the file to a default
location. It's not a save feature, it's an export feature.
Anyhow, so this I think is misleading. It's not really "cancelling"
the export, it's "using the default location".
Can I rename the cancel button, to "Use Default Location" in
NSOpenPanel?
I still want the escape key to activate the "cancel" button, and I
still want it to have the NSCancelButton return code. it will still
be a "cancel" button, not cancelling the export, but cancelling the
choosing of a default location.
Any ideas anyone? I don't see the answer in the Apple documentation.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden