Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change "Open" to "Select" in the NSOpenPanel?

In my Application i need to show the select file dialog, I am making use of the NSOpenPanel which allows to select the file, code is as shown below,

- (IBAction)sendFileButtonAction:(id)sender{

    NSOpenPanel* openDlg = [NSOpenPanel openPanel];

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

    // Enable the selection of directories in the dialog.
    [openDlg setCanChooseDirectories:YES];

    // 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( int i = 0; i < [files count]; i++ )
        {
            NSString* fileName = [files objectAtIndex:i];
            [self log:fileName];

            // Do something with the filename.
        }
    }

}

everything works perfect, but i am facing only one issue, while opening the file, it shows the Open and Cancel button, Is there any way to rename the open button to “Select” button, or do i need to use some other Cocoa Resource.

like image 841
Amitg2k12 Avatar asked Apr 11 '11 12:04

Amitg2k12


2 Answers

Add this line:

[openDlg setPrompt:@"Select"]; 
like image 81
Anne Avatar answered Sep 22 '22 17:09

Anne


Thanks a lot for the question and answers. I have replaced deprecated methods and it seems to work fine. Sorry not yet sure about editing other people answers (new to contributing here).

 - (IBAction)sendFileButtonAction:(id)sender{      NSOpenPanel* openDlg = [NSOpenPanel openPanel];      // Enable the selection of files in the dialog.     [openDlg setCanChooseFiles:YES];      // Enable the selection of directories in the dialog.     [openDlg setCanChooseDirectories:YES];      // Change "Open" dialog button to "Select"     [openDlg setPrompt:@"Select"];      // Display the dialog.  If the OK button was pressed,     // process the files.     if ( [openDlg runModal] == NSModalResponseOK )     {         // Get an array containing the full filenames of all         // files and directories selected.         NSArray* files = [openDlg URLs];          // Loop through all the files and process them.         for( int i = 0; i < [files count]; i++ )         {             NSString* fileName = [files objectAtIndex:i];             NSLog(@"file: %@", fileName);             // Do something with the filename.         }     } } 
like image 28
Justas Avatar answered Sep 23 '22 17:09

Justas