Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SwiftUI DocumentGroup macOS中创建并打开新文档_Macos_Swiftui_Documentgroup - Fatal编程技术网

在SwiftUI DocumentGroup macOS中创建并打开新文档

在SwiftUI DocumentGroup macOS中创建并打开新文档,macos,swiftui,documentgroup,Macos,Swiftui,Documentgroup,如何在基于SwiftUI ReferenceFileDocument的应用程序中打开新文档窗口 背景 此macOS应用程序使用.handleEvents(:)以编程方式打开窗口组。不幸的是,这会导致一个文件/新菜单,它将这些窗口组的名称包装为“New…window”(如图所示)。未能找到覆盖该包装的方法,我试图完全使用命令组(替换:.newItem){}替换新按钮及其菜单 但是,我也未能重新生成“创建并打开新文档窗口”命令。我尝试搜索一些要发布的通知并应用.handleEvents。这只会使现有

如何在基于SwiftUI ReferenceFileDocument的应用程序中打开新文档窗口

背景 此macOS应用程序使用
.handleEvents(:)
以编程方式打开
窗口组。不幸的是,这会导致一个文件/新菜单,它将这些窗口组的名称包装为“New…window”(如图所示)。未能找到覆盖该包装的方法,我试图完全使用
命令组(替换:.newItem){}
替换新按钮及其菜单

但是,我也未能重新生成“创建并打开新文档窗口”命令。我尝试搜索一些要发布的通知并应用
.handleEvents
。这只会使现有的“打开的文档”窗口成为关键窗口。没有打开的文档,它什么也做不了

不良包装

@main
结构应用程序:应用程序{
@StateObject变量根:RootStore
var body:一些场景{
文档组{ProjectDocument()}编辑器:{doc in
DocumentGroupRoot(…)
}.commands{菜单(根:根)}
WindowGroup(“预设颜色贴图”){
..handlesExternalEvents(匹配:…)///允许多个窗口
}.handlesExternalEvents(匹配:…)
WindowGroup(“教程”){
...
}.handlesExternalEvents(匹配:…)
}
}
线路卡滞“新项目”更换

struct NewCommands:Commands{
var body:一些命令{
CommandGroup(替换:.newItem){
NewProjectButton()
}
CommandGroup(在:.newItem之后){
ImportersButtons()
}
}
私有结构NewButton:视图{
@环境(\.openURL)变量openURL
var body:一些观点{
按钮(“新项目”){openURL(ExternalEvents.New.url)}
.键盘快捷方式(“n”,修饰符:。命令)
}
}
}
@main
结构应用程序:应用程序{
@StateObject变量根:RootStore
var body:一些场景{
文档组{ProjectDocument()}编辑器:{doc in
DocumentGroupRoot(…)
.handlesExternalEvents(…)///不启用新的文档窗口
}.commands{菜单(根:根)}
.handlesExternalEvents(匹配:…)///仅使现有文档密钥窗口
...
}
}

好的,经典型。发布然后解决。解决方案是返回到共享的NSDocumentController并请求一个新文档。我会在角落里脸红的

Button("New Project") {
      NSDocumentController.shared.newDocument(nil)
}