view raw
Nathan Campos Nathan Campos - 10 months ago 84
Objective-C Question

Open File Dialog Box

I'm learning Objective-C and trying to develop a simple zipper application, but I stopped when now, when I need to insert a button at my dialog and this button opens a Open File Dialog that will select a file to compress, but I never used a Open File Dialog, then how I can open it and store the user selected file in a

? Thanks.

Remember that I'm using GNUstep(Linux).


In case someone else needs this answer, here it is:

 int i;
  // Create the File Open Dialog class.
  NSOpenPanel* openDlg = [NSOpenPanel openPanel];

  // Enable the selection of files in the dialog.
  [openDlg setCanChooseFiles:YES];

  // Multiple files not allowed
  [openDlg setAllowsMultipleSelection:NO];

  // Can't select a directory
  [openDlg setCanChooseDirectories:NO];

  // Display the dialog. If the OK button was pressed,
  // process the files.
  if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
   // Get an array containing the full filenames of all
   // files and directories selected.
   NSArray* files = [openDlg filenames];

   // Loop through all the files and process them.
   for( i = 0; i < [files count]; i++ )
   NSString* fileName = [files objectAtIndex:i];