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 > NSOpenPanel and alias wierdness

NSOpenPanel and alias wierdness
Thread Tools
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Dec 9, 2001, 05:35 AM
 
I am writing a method that puts up an NSOpenPanel so that the user can select an app of their choice from their hard-drive (or other volumes.)

From the NSOpenPanel docs:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre>& amp;lt;font size=1 face=courier>runModalForDirectory:file:type s:

- (int)runModalForDirectory NSString *)directory file NSString *)filename types NSArray *)fileTypes</font></pre><HR></BLOCKQUOTE>

Displays the receiver and begins a modal event loop that is terminated when the user clicks either OK or Cancel, resulting in the return of NSOKButton or NSCancelButton, respectively. The receiver displays the files in directory (an absolute directory path) that match the types in fileTypes (an NSArray of file extensions). If directory is nil the default directory is the application directory. If all files in a directory should appear in the browser, fileTypes should be nil. You can control whether directories and files appear in the browser with the setCanChooseDirectories: and setCanChooseFiles: methods. The filename argument specifies a particular file in directory that is selected when the Open panel is presented to the user; otherwise, filename should be nil.
there is also a shorter method more appropriate: runModalForTypes: which is the same as above but directory is nil and file is nil(i.e. we start in the Apps directory with no file pre-selected.)


This method works fine (passing filetypes an array with just one entry - ".app")

The exception - If the user selects an alias to a monolithic app (i.e. an app that doesn't use a bundle (e.g. interarchy.))

If this happens the NSOpenPanel thinks that the alias points to a directory (normally fair since an alias to an app usually points to a directory ending in .app) and when the user tries to select the alias you get the following (carbon) error:

FSOpenIterator failed:-1407

which from the docs equates to
errFSNotAFolder -1407 : 'A parameter was expected to identify a folder, but it identified some other kind of object (e.g., a file) instead. This implies that the specified object exists, but is of the wrong type. For example, one of the parameters to FSCreateFileUnicode is an FSRef of the directory where the file will be created; if the FSRef actually refers to a file, this error is returned.'
So is this a bug in my code (below) or is this a bug in NSOpenPanel?

Help! Any Ideas? I have posted this to the cocoa-dev list, but they didn't seem very interested.

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre>& amp;lt;font size=1 face=courier>
<font color = brown> NSArray *fileTypes = [NSArray arrayWithObject:<font color = orange>@"app"</font>]; </font>

<font color = brown>// We Only want to be able to select apps</font>

NSOpenPanel *oPanel = [NSOpenPanel openPanel];
[oPanel setAllowsMultipleSelection:NO];
[oPanel setResolvesAliases:NO]; <font color = brown>// This doesn't affect the problem</font>
result = [oPanel runModalForTypes: fileTypes];
<font color = brown>// equivalent to runModalForDirectory:file:types: method, using nil for both the filename and directory arguments.</font>
<font color = brown>// filename is the pre-selected file.</font>
<font color = brown>// directory is the starting directory - nil means the Applications Directory. </font>
if (result == NSOKButton) <font color = brown>// If we didn't press cancel.</font>
{
NSArray *filesToOpen = [oPanel filenames];
NSString *aFile = [filesToOpen objectAtIndex:<font color = blue>0</font>]; <font color = brown>// aFile is the path to the file we want. </font>
doStuffWithPath…
} <font color = brown>// if (result == NSOKButton)</font>
} <font color = brown>// - (IBAction)setProtocolInfo id)sender</font>
</font></pre><HR></BLOCKQUOTE>

[ 12-09-2001: Message edited by: Diggory Laycock ]

[ 12-12-2001: Message edited by: Diggory Laycock ]

[ 12-12-2001: Message edited by: Diggory Laycock ]
You know it makes sense. ☼ ☼ ☼ Growl.
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Dec 9, 2001, 10:10 PM
 
You could try the documentation for NSFileManager and use:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>- (BOOL)fileExistsAtPathNSString *)path isDirectoryBOOL *)isDirectory</font>[/code]

or you could take a look into NSWorksp ace and try:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>- (BOOL)isFilePackageAtPathNSString *)fullPath</font>[/code]

The first idea claims that it evaluates symbolic links. I am not sure how the second solutions handles that but you could give it a try, I guess.

Hope that helps,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Dec 10, 2001, 05:21 AM
 
Thanks for the tip, however I have deduced that the error occurs within the runModal.... method of NSOpenPanel. So I can't do any checking...
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
result = [oPanel runModalForTypes: fileTypes];
NSLog(<font color = orange>@"about to check result."</font>);
if (result == NSOKButton) <font color = brown>// If we didn't press cancel.</font>
{
etc...
</font>[/code]
gave the following log when I tried selecting a problem alias twice and then a valid app (all within the same openPanel session):
<font face = "courier">
2001-12-10 11:15:05.907 Vince 1.0[371] FSOpenIterator failed:-1407
2001-12-10 11:15:07.572 Vince 1.0[371] FSOpenIterator failed:-1407
2001-12-10 11:15:13.153 Vince 1.0[371] about to check result.
</font>

So I suppose either there is a bug in NSOpenPanel or I am using the wrong class to select an app from a volume.

You know it makes sense. ☼ ☼ ☼ Growl.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Dec 11, 2001, 08:43 AM
 
I've noticed that the internet pref pane has the same problem - so this must be a bug in NSOpenPanel.
You know it makes sense. ☼ ☼ ☼ Growl.
     
   
Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2