zoukankan      html  css  js  c++  java
  • Mac开发 - 使用CCMenu和CCMenuItem添加菜单、右击菜单、Dock菜单

    Mac开发 - 使用CCMenu和CCMenuItem添加菜单、右击菜单、Dock菜单
    1、添加一个Dock右击菜单
            NSMenu *appDockMenu = [[NSMenu alloc] initWithTitle:@"DockMenu"];
    [appDockMenu setAutoenablesItems:NO];
    NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"About" action:@selector(aboutDockAction:) keyEquivalent:@""];
    [newItem setTarget: self];
    [appDockMenu addItem:newItem];
    [newItem release];
    
    - (NSMenu *)applicationDockMenu:(NSApplication *)sender
    {
    return appDockMenu;
    }
    
    2、给一个NSView添加右击菜单
    
    NSMenu* newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Copy"]; 
            NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Copy" action:@selector(copyAction:) keyEquivalent:@""];
            [newItem setEnabled:YES];
            [newItem setTarget:self];
            [newMenu addItem:newItem];
            [newItem release];
            
            [myview setMenu:newMenu];
            [newMenu release];
    
    3、给顶部菜单栏,添加菜单
    
    NSMenu* newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"About"]; 
            NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"About"action:@selector(copyAction:) keyEquivalent:@""];
            [newItem setEnabled:YES];
            [newItem setTarget:self];
            [newMenu addItem:newItem];
            [newItem release];
            [[NSApp mainMenu] insertItem:newItem atIndex:3];
            [newMenu release];
     NSMenu *subMenu = [[NSMenu alloc]init];
    
                for (NSDictionary *dic in folderArray) {
    
                    for (NSString *folderKey in [dic allKeys]) {
    
                        NSDictionary *folderInfo = [dic objectForKey:folderKey];
    
                        NSString *appName = [folderInfo objectForKey:@"APP_NAME"];
    
                        IBDMenuItem* newItem = [[IBDMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle: appName action:@selector(moveToAction:) keyEquivalent:@""];
                        //绑定选择移动到item
                        newItem.tag = folderKey.intValue;
                        //绑定要移动的Item  考虑传值问题
                        newItem.selfIndex = index.integerValue;
                        [newItem setTarget: self];
                        [subMenu insertItem:newItem atIndex:0];
                    }
  • 相关阅读:
    CobaltStrike上线Linux主机(CrossC2)
    Active-Directory活动目录备忘录
    CVE-2020-5902 F5 BIG-IP 远程代码执行漏洞复现
    SSTI-服务端模板注入漏洞
    powershell代码混淆绕过
    绕过PowerShell执行策略方法
    "dpkg: 处理归档 /var/cache/apt/archives/libjs-jquery_3.5.1+dfsg-4_all.deb (--unpack)时出错"的解决方法
    firda安装和使用
    内网渗透-跨域攻击
    Web-Security-Learning
  • 原文地址:https://www.cnblogs.com/741162830qq/p/5156963.html
Copyright © 2011-2022 走看看