我正在做一些疯狂的多个文件在单个窗口内的文件为基础的架构的东西,我95%完成。如何检查响应者链?
我有这种双层文档体系结构,其中父文档打开并配置窗口,提供“子”文档列表。当用户选择其中一个孩子时,该文档将使用相同的窗口控制器打开,并在窗口中放置一个NSTextView
。窗口控制器的文档关联被更改,以便“编辑的点”和窗口标题跟踪当前选定的文档。想想一个Xcode项目,以及在编辑其中的不同文件时会发生什么。
要将代码置于伪形式,当打开子文档时,会在父文档中调用类似这样的方法。
-(void)openChildDocumentWithURL:(NSURL *)documentURL {
// Don't open the same document multiple times
NSDocument *childDocument = [documentMapTable objectForKey:documentURL];
if (childDocument == nil) {
childDocument = [[[MyDocument alloc] init] autorelease];
// Use the same window controller
// (not as bad as it looks, AppKit swaps the window's document association for us)
[childDocument addWindowController:myWindowController];
[childDocument readFromURL:documentURL ofType:@"Whatever" error:NULL];
// Cache the document
[documentMapTable setObject:childDocument forKey:documentURL];
}
// Make sure the window controller gets the document-association swapped if the doc came from our cache
[myWindowController setDocument:childDocument];
// Swap the text views in
NSTextView *currentTextView = myCurrentTextView;
NSTextView *newTextView = [childDocument textView];
[newTextView setFrame:[currentTextView frame]]; // Don't flicker
[splitView replaceSubview:currentTextView with:newTextView];
if (currentTextView != newTextView) {
[currentTextView release];
currentTextView = [newTextView retain];
}
}
这工作,我知道,窗控制器具有在任何给定的时间正确的文件关联,因为变化点和标题跟随我编辑的文件为准。但是,当我点击保存时,(CMD + S或文件 - >保存/另存为),它想要保存父文档,而不是当前文档(如[[NSDocumentController sharedDocumentController] currentDocument]
报告的那样,并且如窗口标题和改变点)。
从阅读NSResponder
文档,好像链条应该是这样的:
当前视图 - >上海华盈(重复) - >窗口 - > WindowController - >文件 - > DocumentController - >应用程序。
我不确定基于文档的架构如何设置响应者链(即如何将NSDocument
和NSDocumentController
置入链中),所以我想调试它,但我不确定在哪里寻找。我如何在任何特定时间访问响应者链?
谢谢,我不知道这是怎么发生在我身上,我非常专注于直接抓取整个堆栈的想法。 – d11wtq 2010-11-22 03:39:21