Re: Suggesting an initial filename with document-based app?
Re: Suggesting an initial filename with document-based app?
- Subject: Re: Suggesting an initial filename with document-based app?
- From: Eric Wang <email@hidden>
- Date: Thu, 03 Jul 2003 12:30:48 -0400
on 7/3/03 7:06 AM, Matt Gemmell at email@hidden wrote:
>
On 3/7/03 at 8:57 am, Eric Wang said:
>
>
> Here's one way that might work:
>
>
>
> - (BOOL) prepareSavePanel: (NSSavePanel *) savePanel
>
> {
>
> if ([self fileName] == nil)
>
> {
>
> NSForm *form = [[savePanel contentView] viewWithTag:
>
> NSFileHandlingPanelForm];
>
>
>
> // Here you can customize the form however you want
>
> }
>
>
>
> return YES;
>
> }
>
>
Hi Eric,
>
>
This is the closest I've come so far. Within your method, quoted above,
>
this code gets the NSFormCell of the filename field:
>
>
NSForm *form = [[savePanel contentView]
>
viewWithTag:NSFileHandlingPanelForm];
>
NSFormCell *filenameCell = [form cellAtRow:0 column:0];
>
>
The problem is, I have no idea how to access the actual textfield
>
component of the NSFormCell. Unless -stringValue gives me its value, in
>
which case it's null at the time of -prepareSavePanel, leading to the
>
same problem as before. Damn.
>
>
Thanks for the suggestion though! :)
>
>
Cheers,
>
-Matt
Apparently, the form cell's stringValue is set after -prepareSavePanel is
called. The document architecture overwrites whatever value you set it to in
-prepareSavePanel. I found two ways to work around this.
One way involves the saving a reference to the save panel's form cell in an
instance variable and then overriding
-runModalSavePanelForSaveOperation:delegate:didSaveSelector:contextInfo:
like this:
- (void) runModalSavePanelForSaveOperation: (NSSaveOperationType)
saveOperation
delegate: (id) delegate
didSaveSelector: (SEL) didSaveSelector
contextInfo: (void *) contextInfo
{
[super runModalSavePanelForSaveOperation: saveOperation
delegate: delegate
didSaveSelector: didSaveSelector
contextInfo: contextInfo];
[_savePanelFormCell setStringValue: @"MyFileName"];
}
This has the ugly side effect of showing the file name set by the document
architecture for a moment as the save panel sheet rolls down.
The second method avoids this, but the code may be a bit more ugly,
depending on how you look at it. You override -prepareSavePanel: like so:
- (BOOL) prepareSavePanel: (NSSavePanel *) savePanel
{
if ([self fileName] == nil)
{
NSForm *form = [[savePanel contentView] viewWithTag:
NSFileHandlingPanelForm];
NSFormCell *formCell = [form cellAtIndex: 0];
[formCell performSelector: @selector(setStringValue:) withObject:
@"MyFileName" afterDelay: 0.0 inModes: [NSArray arrayWithObject:
NSModalPanelRunLoopMode]];
}
return YES;
}
Hope this helps,
Eric Wang
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.