0

我有以下设置:

NSWindow 中的 4x4(总共 16 个)按钮(标准 NSButton 按钮)网格。

当我按下热键组合 (DDHotKey) 时 NSWindow 会出现在最前面

现在,我想做的是为我的按钮提供以下功能:

  • 单击该按钮时,打开一个显示 /Applications/ 目录的对话框,并允许我选择其中列出的任何应用程序。

  • When the application is selected store it in a variable (I'm guessing) (or string?) and make it so that when the buttons Key Equivalent is pressed, that application launches

我环顾四周,我不确定该做什么或从哪里开始寻找……有什么线索吗?

我的 appdelegate.m 文件中有这个:

- (void)openDoc:(id)sender
{
    int result;
    NSArray *fileTypes = [NSArray arrayWithObject:@"td"];
    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

[oPanel setAllowsMultipleSelection:YES];
result = [oPanel runModalForDirectory:NSHomeDirectory()
                file:nil types:fileTypes];
if (result == NSOKButton) {
    NSArray *filesToOpen = [oPanel filenames];
    int i, count = [filesToOpen count];
    for (i=0; i<count; i++) {
        NSString *aFile = [filesToOpen objectAtIndex:i];
        id currentDoc = [[ToDoDoc alloc] initWithFile:aFile];
    }
}
}

如何将按钮链接到它?

4

2 回答 2

2

您可以使用NSOpenPanel来选择应用程序。

然后启动应用程序,看看这个堆栈溢出问题。

于 2011-05-13T21:36:50.157 回答
1

存储应用程序的路径,然后在您想要打开它们时。您可以使用该system()功能。

system("open -a /Applications/someApplication.app");
于 2011-05-13T21:38:08.247 回答