Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > question about opening associated files...

question about opening associated files...
Thread Tools
MaxPower2k3
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 12, 2003, 09:29 PM
 
I'm making an app that has a file type associated with it. I got that part working fine, the program can make the file (it's a package) and, when the file is double clicked, the app is opened/brought into focus. my question is, how do i read the file that was opened? Is there a function in the app that i can implement that will be called? Is there a notification that gets posted? I'm pretty new to this, so bear with me if this is a brutally easy question


Thanks,
Max
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 12, 2003, 10:03 PM
 
You really need to tell what language and frameworks you're using or nobody will know what you need to do.

If you're doing a Cocoa document-based application, this should work automatically for you by creating an instance of the appropriate document class. If not, but it's still a Cocoa application (my guess at what you're doing), you need to implement application:openFile: in your application's delegate.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 12, 2003, 10:08 PM
 
Originally posted by Chuckit:
You really need to tell what language and frameworks you're using or nobody will know what you need to do.

If you're doing a Cocoa document-based application, this should work automatically for you by creating an instance of the appropriate document class. If not, but it's still a Cocoa application (my guess at what you're doing), you need to implement application:openFile: in your application's delegate.
whoops, sorry. yeah, it's Cocoa/Obj-C, but not document-based. I'll give application:openFile a try.

thanks,
Max
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 12, 2003, 10:19 PM
 
well i tried using application:openFile: but it doesn't seem to work, unless i missed something. The method is this:

Code:
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { NSLog(@"Filename: %@", filename); return YES; }
but this just never runs, whether i double click on the file, or drag it over the dock icon. It also doesn't make a difference whether the app was open beforehand, or if this opens the app. did i miss something obvious, or is there something else i should do?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 12, 2003, 11:26 PM
 
You made an instance of that class your application's delegate, right?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 12, 2003, 11:31 PM
 
Originally posted by Chuckit:
You made an instance of that class your application's delegate, right?
oh... no, i don't believe i did (that i know of). how do i go about doing this?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 12, 2003, 11:44 PM
 
Simplest way: Instantiate the class in Interface Builder and connect the application's "delegate" outlet to that instance.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 12, 2003, 11:55 PM
 
Originally posted by Chuckit:
Simplest way: Instantiate the class in Interface Builder and connect the application's "delegate" outlet to that instance.
Both the 'Window' and 'File Owner' instances in IB have delegate outlets, but neither work when connected to the class... is there a different one that i should be connecting? (there's no Application instance... should i subclass NSApplication and instantiate that?)

edit: tried to instantiate a subclass of NSApplication, doesn't let me...
     
Gul Banana
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Jul 13, 2003, 12:03 AM
 
File Owner is the one you want, I think.
[vash:~] banana% killall killall
Terminated
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 13, 2003, 12:08 AM
 
ok, File Owner worked. i tried it before and it wasn't working, but i figured out that for some reason it only works from the produced .app, not from the 'build and run' button. thanks for your help
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 13, 2003, 12:56 AM
 
another quick question... how do i put unicode characters in the string? promoting the file to unicode causes all sorts of errors (thousands of them, in fact). in the InfoPlist.strings you can put in unicode characters with \U00A9 (for example) and it works fine, but in regular NSStrings an 'unknown escape sequence' warning comes up and the string just shows 'U00A9'. if i change the encoding of the string to UTF8 or Unicode, the same things happens.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 13, 2003, 01:38 AM
 
Just type in the characters. If they don't have a key combination, you can use the Unicode Hex Input method method.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 13, 2003, 02:04 AM
 
Originally posted by Chuckit:
Just type in the characters. If they don't have a key combination, you can use the Unicode Hex Input method method.
except source files aren't encoded with unicode (and promoting them to unicode screws it up completely) so inserting the characters directly isn't an option. I'm not familiar with the hex input method, though... how does that work?
     
Wevah
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Jul 13, 2003, 02:25 AM
 
The hex input allows you to hold down the Option key and type a sequence of four hex digits to display a character (as long as you have "Unicode Hex Input" in your keyboard menu and it's selected). For example: hold option, and press 2, 6, 0, 5 to type a black star.

This just displays the characters as usual though, so you'd need to promote to Unicode to display them...which as was said before doesn't work for source files. One thing you can do is put phrases that need extended Unicode chars into Localizable.strings and call NSLocalizedString() where you need the string displayed in the source...
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 02:20 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,