In the Nav Services world one could specify kNavDontConfirmReplacement
as an option to create a NavDialogRef
that would not ask the user to confirm the replacement of a file when saving with a file name that already exists. How do I specify an equivalent behavior with the Cocoa NSSavePanel
?
相关问题
- Xcode debugger displays incorrect values for varia
- Is there a way to report errors in Apple documenta
- Advice for supporting both Mac and Windows Desktop
- Avoid cmake to add the flags -search_paths_first a
- NSOutlineView drag line stuck + blue border
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- ImportError: No module named twisted.persisted.sty
- How can I vertically align my status bar item text
- Converting (u)int64_t to NSNumbers
Here's how it can be done:
- (NSString*)panel:(id)sender userEnteredFilename:(NSString*)filename confirmed:(BOOL)okFlag
in your delegateokFlag
isfalse
, returnfilename
filename
as anNSString*
in your delegateNSSavePanel
returns to your code, pull the value of filename from your delegate method, and discard whatever filenameNSSavePanel
told you (which should be your unique string).Since
userEnteredFilename:
is called by the OS before the confirm-replace check is made it gives you a chance to get what the user specified without letting the OS in on the secret. The unique string will assure that the confirm-replace dialog is not popped accidentally.Gross but efficacious.
Your customers is going to expect the exact confirmation alert when faced with a NSSavePanel, so don't customize it.
I'm not sure what kind of customized confirm-overwrite dialog you are planning, but might I suggest you use a NSOpenPanel instead, and customize this dialog box with a "Create New File" button? (I believe you can do this via setAccessoryView API.)
For example, if you are asking your customer to choose a file to append new data to, the NSOpenPanel will work quite well; and if the customer want to save the new data to a new file (instead of appending to an existing file), the "Create New File" button is just an additional click.
No, there is no easy way to do this with NSSavePanel. In theory you could extend NSSavePanel with a category and override certain private methods. I took a quick look though and there is nothing simple about it.