Jay*_*Jay 6 cocoa objective-c nspathcontrol
从Apple的示例代码和阅读文档中我看不出配置NSPathControl
行为类似于例如Xcode Editor窗口中的" 跳转条 ":
即它代表一个路径(或其他类型的层次结构),并使路径的每个组件成为一个可点击的弹出窗口来导航层次结构..?
有人通过NSPathControlDelegate
听取点击并在临时窗口中显示菜单来运气这样的行为吗?
看起来像一个普通的设计,人们甚至期望一些OSS实现 - 但没有这样的运气,但谷歌搜索它..
小智 4
我创建了 NSPathControl 的子类,以便可以使用 mouseDown: 在正确位置弹出组件单元格的上下文菜单。我还在菜单中添加了一个委托,以根据需要创建更深的菜单。
- (void)mouseDown:(NSEvent *)event {
NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
NSPathCell *cell = self.cell;
NSPathComponentCell *componentCell = [cell pathComponentCellAtPoint:point
withFrame:self.bounds
inView:self];
NSRect componentRect = [cell rectOfPathComponentCell:componentCell
withFrame:self.bounds
inView:self];
NSMenu *menu = [componentCell menuForEvent:event
inRect:componentRect
ofView:self];
if (menu.numberOfItems > 0) {
NSUInteger selectedMenuItemIndex = 0;
for (NSUInteger menuItemIndex = 0; menuItemIndex < menu.numberOfItems; menuItemIndex++) {
if ([[menu itemAtIndex:menuItemIndex] state] == NSOnState) {
selectedMenuItemIndex = menuItemIndex;
break;
}
}
NSMenuItem *selectedMenuItem = [menu itemAtIndex:selectedMenuItemIndex];
[menu popUpMenuPositioningItem:selectedMenuItem
atLocation:NSMakePoint(NSMinX(componentRect) - 17, NSMinY(componentRect) + 2)
inView:self];
}
}
- (NSMenu *)menuForEvent:(NSEvent *)event {
if (event.type != NSLeftMouseDown) {
return nil;
}
return [super menuForEvent:event];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
866 次 |
最近记录: |