NSSavePanel:压缩“确认替换?"按钮.对话 [英] NSSavePanel: Squelching the "confirm replace?" dialog

查看:111
本文介绍了NSSavePanel:压缩“确认替换?"按钮.对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Nav Services的世界中,可以指定kNavDontConfirmReplacement作为创建NavDialogRef的选项,当使用已存在的文件名进行保存时,它不会要求用户确认文件的替换.如何指定可可NSSavePanel的等效行为?

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?

推荐答案

以下是操作方法:

  1. 添加委托以处理NSSavePanel回调
  2. 在您的代表中覆盖- (NSString*)panel:(id)sender userEnteredFilename:(NSString*)filename confirmed:(BOOL)okFlag
  3. 在代表中:
  1. Add a delegate to handle NSSavePanel callbacks
  2. Override - (NSString*)panel:(id)sender userEnteredFilename:(NSString*)filename confirmed:(BOOL)okFlag in your delegate
  3. In the delegate:
  1. 如果okFlagfalse,则返回filename
  2. 否则,请在您的代表中将filename保留为NSString*
  3. 返回一些不太可能是实际文件名的唯一字符串
  1. If okFlag is false, return filename
  2. Otherwise, retain filename as an NSString* in your delegate
  3. Return some unique string that is highly unlikely to be the name of an actual file

  • NSSavePanel返回代码时,请从委托方法中提取filename的值,并丢弃NSSavePanel告诉您的任何文件名(应为唯一字符串).
  • When NSSavePanel returns to your code, pull the value of filename from your delegate method, and discard whatever filename NSSavePanel told you (which should be your unique string).
  • 由于操作系统在进行确认替换检查之前已调用userEnteredFilename:,因此您有机会获得用户指定的内容,而无需让操作系统进入机密状态.唯一的字符串将确保不会意外弹出确认替换对话框.

    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.

    但有效.

    这篇关于NSSavePanel:压缩“确认替换?"按钮.对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆