Re: Best way to manage double-clicked files?
Re: Best way to manage double-clicked files?
- Subject: Re: Best way to manage double-clicked files?
- From: Lee Ann Rucker <email@hidden>
- Date: Sat, 10 Dec 2011 17:00:20 -0800 (PST)
Try the application delegate method application:openFile: - it gets called before the NSDocument handling gets a shot at it.
----- Original Message -----
From: "C.W. Betts" <email@hidden>
To: "julius" <email@hidden>, "Cocoa Development" <email@hidden>
Sent: Saturday, December 10, 2011 4:51:44 PM
Subject: Re: Best way to manage double-clicked files?
On Dec 10, 2011, at 8:23 AM, julius wrote:
> On Fri, 09 Dec 2011 13:14:26 -0700 C.W. Betts wrote
>>
>> What is the best way to handle double-clicked files in an application that doesn't use documents? The reason I ask is because a project I'm working on, PCSX-R, currently uses NSDocument subclasses to handle opening of files double-clicked in the Finder. However, the readFromFileWrapper:ofType:error: function returns NO even if the file is loaded to prevent the document window from popping up (I have it se with no close buttons; the window is called modally), but it shows an error that the file wasn't opened, despite it being so. Should I use a different way of managing double-clicked files, or is there a function that I should overload on my NSDocument subclass?
>>
>> ------------------------------
> Hi,
> not sure if understand your question.
>
> I am assuming
> 1. you want program to start from double click of document file
> 2. you want to be able to open program by clicking application file but do not want the app to open an empty document window.
>
I want it so that when I double-click a file in Finder, a window pops up and lets me select an option, then the window goes away. I'm wondering if NSDocument is the best way to do this, or if another method would be better suited. This is the current code I'm using for the memory card chooser:
- (int)showMemoryCardChooserForFile:(NSString *)theFile
{
if (!changeMemCardSheet) {
[NSBundle loadNibNamed:[self windowNibName] owner:self];
}
[cardPath setObjectValue:theFile];
[NSApp runModalForWindow:changeMemCardSheet];
[NSApp endSheet:changeMemCardSheet];
[changeMemCardSheet orderOut:self];
return memChosen;
}
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
{
int chosen = [self showMemoryCardChooserForFile:[fileWrapper filename]];
if (chosen == 0) {
return NO;
} else {
[ConfigurationController setMemoryCard:chosen toPath:[[self fileURL] path]];
//TODO: make this return YES so that "File Can't be Opened" dialog box doesn't pop up, but the window itself doesn't stay on the screen.
return NO;
}
}
It is returning NO because if I return YES, after the modal window pops up, a button is pressed that will dismiss the modal dialog, the window pops up again, non-modal this time, making the button that would have closed it not work. But because I return NO, a message pops up that says the file could not be opened. I want to fix that if at all possible.
I already discovered the fix for no. 2._______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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