Opening Files with Arbitrary Type or Extension
Opening Files with Arbitrary Type or Extension
- Subject: Opening Files with Arbitrary Type or Extension
- From: Wes Peterson <email@hidden>
- Date: Fri, 11 Aug 2006 16:42:19 -1000
I want to be able to open any file, no matter what its extension
or type. I think it must be easier than what I am doing, and
besides, I haven't yet succeeded. I'm new at cocoa, but I know a
lot more than I did a couple of months ago.
The first problem is that the file dialog won't allow the
user to choose a file unless its type is in the info.plist. I can
solve that. Then from the file dialog, I get a path or URL, and
try to open, and it won't open the files whose names are not in
the info.plist. I solved that for the Open menu item, as follows:
(Is there an easier way?) This is connected to the Open menu item:
- (IBAction) openDoc: (id) sender {
if ([fop runModalForTypes: nil]) {
NSURL *fileURL = [NSURL fileURLWithPath:
[[fop filenames] objectAtIndex: 0]];
[fileURL retain];
theDoc = [[MyDocument alloc] retain];
theDoc = [theDoc initWithContentsOfURL: fileURL
ofType:@"AnyType" error: nil];
[theDocCon addDocument: theDoc];
[theDoc makeWindowControllers];
[theDoc showWindows];
}
}
(theDocCon is a pointer to the document controller.)
Now I can open a file regardless of its type or extension.
If I close it, it goes in the "Recent Files" list. Now if I
try to open it using Open Recent, it will not open unless it
is on the info.plist. So I tried overriding the DocumentController
class method "documentClassForType" and returning "MyDocument"
for every file type, but it seems as if the Open Recent doesn't
use that to figure out that it should not open the file.
I would appreciate any and all suggestions. --Wes
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden