gpt4 book ai didi

objective-c - NSPathControl 与路径的每个组件的弹出窗口?

转载 作者:太空狗 更新时间:2023-10-30 03:43:27 26 4
gpt4 key购买 nike

来自 Apple's sample code和阅读 the docs我看不出配置 NSPathControl 的行为类似于例如Xcode 编辑器窗口中的“跳转栏”:

Xcode Editor custom path control

即让它代表一条路径(或其他类型的层次结构)并使路径的每个组件成为可点击的弹出窗口以导航层次结构..?

有人幸运地使用 NSPathControlDelegate 监听点击并在临时窗口中显示菜单来伪造这种行为吗?

似乎是一种常见的设计,人们甚至会期待一些 OSS 实现 - 但还没有这样的运气,但谷歌搜索......

最佳答案

我做了一个 NSPathControl 的子类,这样我就可以使用 mouseDown: 在正确的位置弹出组件单元格的上下文菜单。我还向菜单添加了一个委托(delegate),以根据需要创建更深层次的菜单。

- (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];
}

关于objective-c - NSPathControl 与路径的每个组件的弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12708715/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com