objective-c – NSPathControl,路径的每个组件都有d出窗口?

objective-c – NSPathControl,路径的每个组件都有d出窗口?,第1张

概述从 Apple’s sample code到 the docs,我看不到配置NSPathControl的行为类似于例如Xcode编辑器窗口中的“跳转条”: 即让它代表一个路径(或其他类型的层次结构),并使路径的每个组件成为一个可点击的d出窗口来导航层次结构..? 任何人都有运气伪造这种行为使用NSPathControlDelegate听取点击并在临时窗口中显示菜单? 看起来像一个普通的设计,人们甚 从 Apple’s sample code到 the docs,我看不到配置NSPathControl的行为类似于例如Xcode编辑器窗口中的“跳转条”:

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

任何人都有运气伪造这种行为使用NSPathControlDelegate听取点击并在临时窗口中显示菜单?

看起来像一个普通的设计,人们甚至期望一些OSS实现 – 但没有这样的运气,但谷歌搜索它..

解决方法 我创建了NSPathControl的子类,以便我可以使用mouseDown:在正确的位置d出组件单元格的上下文菜单.我还在菜单中添加了一个代表,以便按需创建更深入的菜单.

- (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,路径的每个组件都有d出窗口?全部内容,希望文章能够帮你解决objective-c – NSPathControl,路径的每个组件都有d出窗口?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1011955.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存