Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / December 2005



Tip: Looking for answers? Try searching our database.

how to open 'grayed out' files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Koen - 15 Dec 2005 15:54 GMT
I am trying to make a customized open file dialog that allows the
opening of files that need root permissions, eg a file like
/etc/httpd.conf.  I can use the Authorization API to prompt a user when
saving the file. But if I use a regular open dialog, all those files are
grayed out, so I cannot even open them.

One thing I tried is the following in MyDocument:

- (IBAction)openDocument:(id)sender
{
  int         result;
  NSArray     *fileTypes = [NSArray arrayWithObject: @"conf"];
  NSOpenPanel *oPanel = [NSOpenPanel openPanel];
 
  [oPanel setAllowsMultipleSelection: NO];
 
  if (result == NSOKButton)
  {
     NSArray *filesToOpen = [oPanel filenames];
     NSString *aFile = [filesToOpen objectAtIndex: 0];

     if (aFile != nil)
     {
       // open file, etc
     }
  }
}

It works, but this will only work for .conf files, and the code needs to
be edited when I decide to open files with a different extension.

So I was wondering is this is a good approach, or that I am overseeing
something and need to use another method

As an example, TextWrangler does what I am looking for.

thanks,

- Koen.
Simon Slavin - 26 Dec 2005 01:20 GMT
On 15/12/2005, Koen wrote in message <koen-
E5D0C2.10541315122005@news1.east.earthlink.net>:

>    NSArray     *fileTypes = [NSArray arrayWithObject: @"conf"];
>
[quoted text clipped - 5 lines]
> So I was wondering is this is a good approach, or that I am overseeing
> something and need to use another method

Well, that's what the code you wrote does: see the line I quoted.  If you
don't want to have the dialog restricted to one file type, change what you
put in the array.  To find out what to put in if you want files of all
types, read the documentation for NSOpenPanel.  If you can't work out
where it is in your Xcode documentation, try here:

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Obj
C_classic/Classes/NSOpenPanel.html

By the way, I think there's something left out of your quoted code, since
you define fileTypes without uses.

Simon.
Signature

http://www.hearsay.demon.co.uk

Koen - 26 Dec 2005 03:22 GMT
In article <donmh1$764$3$8302bc10@news.demon.co.uk>,
Simon Slavin <slavins.delete.these.four.words@hearsay.demon.co.uk>
wrote:

> By the way, I think there's something left out of your quoted code, since
> you define fileTypes without uses.

Yep - the following line needs to be added before the first if:

result = [oPanel runModalForDirectory: nil file: nil types: fileTypes];

Found that a few days ago :)

- Koen.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.