NSTextView如何禁用'You don’t own the file “xxx” and don’t have permission to write to it.'
NSTextView how to disable 'You don’t own the file “xxx” and don’t have permission to write to it.'
我的基于文档的应用程序中有一个 NSTextView
。如果我打开一个我只有读取权限的文件并修改 NSTextView
的内容,我会收到一个对话框,说明:
You don’t own the file “xxx” and don’t have permission to write to it.
但是这个文本视图实际上并没有与我打开的文档进行交互。是否可以通过某种方式取消 NSTextView 的这种行为?
我想出的代码如下:
#import <JRSwizzle/JRSwizzle.h>
@implementation NSDocument (Swizzle)
+ (void) load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSError * error = nil;
SEL srcSelection = NSSelectorFromString(@"_checkAutosavingThenUpdateChangeCount:");
SEL dstSelector = @selector(MyCheckAutosavingThenUpdateChangeCount:);
[[NSDocument class] jr_swizzleMethod: srcSelection
withMethod: dstSelector
error: &error];
NSLog(@"Error: %@", error);
});
} // End of load
- (void) MyCheckAutosavingThenUpdateChangeCount: (unsigned long long) arg1
{
// On updateChangeCount, we are going to catch if the firstresponder is our query window.
// If the first responder is, then we will not mark a change. This is for two reasons:
// 1. This is an sqlite app. Editing the query editor dosen't actually update our
// document.
// 2. If we do mark the document as updated and the query editor marks a change, we get
// a popup stating that the document cant be updated, needs to be duplicated, yada, yada.
NSWindow * keyWindow = [[NSApplication sharedApplication] keyWindow];
if(NULL != keyWindow)
{
NSResponder * responder = keyWindow.firstResponder;
// My code uses a NSTextView subclass. For copy/paste I'm just entering NSTextView.
if([responder isKindOfClass: NSClassFromString(@"NSTextView")])
{
return;
}
}
[self MyCheckAutosavingThenUpdateChangeCount: arg1];
} // End of MyCheckAutosavingThenUpdateChangeCount
我的基于文档的应用程序中有一个 NSTextView
。如果我打开一个我只有读取权限的文件并修改 NSTextView
的内容,我会收到一个对话框,说明:
You don’t own the file “xxx” and don’t have permission to write to it.
但是这个文本视图实际上并没有与我打开的文档进行交互。是否可以通过某种方式取消 NSTextView 的这种行为?
我想出的代码如下:
#import <JRSwizzle/JRSwizzle.h>
@implementation NSDocument (Swizzle)
+ (void) load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSError * error = nil;
SEL srcSelection = NSSelectorFromString(@"_checkAutosavingThenUpdateChangeCount:");
SEL dstSelector = @selector(MyCheckAutosavingThenUpdateChangeCount:);
[[NSDocument class] jr_swizzleMethod: srcSelection
withMethod: dstSelector
error: &error];
NSLog(@"Error: %@", error);
});
} // End of load
- (void) MyCheckAutosavingThenUpdateChangeCount: (unsigned long long) arg1
{
// On updateChangeCount, we are going to catch if the firstresponder is our query window.
// If the first responder is, then we will not mark a change. This is for two reasons:
// 1. This is an sqlite app. Editing the query editor dosen't actually update our
// document.
// 2. If we do mark the document as updated and the query editor marks a change, we get
// a popup stating that the document cant be updated, needs to be duplicated, yada, yada.
NSWindow * keyWindow = [[NSApplication sharedApplication] keyWindow];
if(NULL != keyWindow)
{
NSResponder * responder = keyWindow.firstResponder;
// My code uses a NSTextView subclass. For copy/paste I'm just entering NSTextView.
if([responder isKindOfClass: NSClassFromString(@"NSTextView")])
{
return;
}
}
[self MyCheckAutosavingThenUpdateChangeCount: arg1];
} // End of MyCheckAutosavingThenUpdateChangeCount