how to use NSSavePanel without the option Save As?

Discussion in 'Mac Programming' started by mkristain, Oct 31, 2011.

  1. mkristain macrumors regular

    Joined:
    Aug 18, 2011
    #1
    i want to use NSSavePanel to select the saving folder location ,so i don't want to use save as option.

    i want here only folders are visible or selectable.

    please guide me how can i do this.

    thanks.
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    So you want a dialog box where the user can choose a directory? If so, then you actually want an NSOpenDialog. Set canChooseDirectories to true, and canChooseFiles and allowsMultipleSelection to false.
     
  3. mkristain thread starter macrumors regular

    Joined:
    Aug 18, 2011
    #3
    NSOpenDialog means NSOpenPanel

    Code:
    i use it like this
    
    NSOpenPanel* openPanel = [NSOpenPanel openPanel];
    		
    		
    		[openPanel setAllowsMultipleSelection:NO];
    		[openPanel setCanChooseDirectories:YES];
    		[openPanel setCanChooseFiles:NO];
    		[openPanel setCanCreateDirectories:YES];
    		[openPanel setTreatsFilePackagesAsDirectories:NO];
    		[openPanel setResolvesAliases:YES];
    			
    		[openPanel beginSheetModalForWindow:controlPanel completionHandler:^(NSInteger result) 
    		 {
    			 if (result == NSOKButton) 
    			 {
    				 
    				 [_path setStringValue:[openPanel filename]];
    				 
    				 
    			 }
    		 }];
    
    here the problem is,if i create a folder on desktop and select that folder
    than again open the NSOpenPanel after MoveToTrash the created folder,
    now create the folder with same name on desktop,now Program received signal: “EXC_BAD_ACCESS”.

    and point out here

    #0 0x940ee6a2 in TFSInfo::AddPtrReference
    #1 0x940ef7f2 in TNode::IsContainer
    #2 0x94135bbb in TNode::SetForceSync

    so please help me for this.

    thanks.
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    Please accept my sincerest apology for that mistake.


    I cannot reproduce your problem a test project under Mac OS X 10.7.2. I opened an NSOpenPanel, created a folder on my desktop and selected that folder. I then moved the newly created folder to the trash. When I opened the NSOpenPanel again, it reverted to my Documents folder. It didn't get an EXC_BAD_ACCESS signal.


    BTW The NSOpenPanel's filename is deprecated. You should be using URLs instead of string paths.
     
  5. mkristain thread starter macrumors regular

    Joined:
    Aug 18, 2011
    #5
    my Mac OS X 10.6.7,

    steps wise procedure:
    1- click browse button to open panel
    2- create a new folder on desktop an open(select) using panel
    3- move to trash newly created folder but don't empty the trash.
    4- click again browse button to open panel
    5- select desktop and create new folder with same name

    here i receive the error.
     
  6. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #6
    Sorry again. I didn't pick up on that you were selecting a second newly created folder that happened to have the same path as the now trashed, previously selected folder. I tried that but again I didn't get an EXC_BAD_ACCESS signal.

    Does the EXC_BAD_ACCESS occur as soon as as you click Create, or is it after you click Open?
     
  7. mkristain thread starter macrumors regular

    Joined:
    Aug 18, 2011
    #7
    some time on click Create, or sometimes on click Open

    why i receiving this every time,

    is there any mistake in my method to open panel?
     
  8. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #8
    I've been using your code, with one difference.

    Instead of your line:
    Code:
    [_path setStringValue:[openPanel filename]];
    
    I have:
    Code:
    NSLog(@"Selected URL: %@", [openPanel URL]);
    
     
  9. mkristain thread starter macrumors regular

    Joined:
    Aug 18, 2011
    #9
    i am using [_path setStringValue:[openPanel filename]]; because i display the selected path in this text field.
     

Share This Page