diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm index 588fdf81d..e1a68da0a 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm @@ -748,25 +748,28 @@ - (void)onCEFCreateTab:(NSNotification *)notification { NSMutableDictionary * params = [notification.userInfo mutableCopy]; if ([params[@"action"] isEqualToNumber:@(ASCTabActionCreateLocalFileFromTemplate)]) { - NSOpenPanel * openPanel = [NSOpenPanel openPanel]; - NSMutableArray * filter = [NSMutableArray array]; - - if ( [params[@"type"] isEqualToNumber:@((int)AscEditorType::etPresentation)] ) { - [filter addObjectsFromArray:@[@"potx", @"otp"]]; - } else if ( [params[@"type"] isEqualToNumber:@((int)AscEditorType::etSpreadsheet)] ) { - [filter addObjectsFromArray:@[@"xltx", @"xltm", @"ots"]]; - } else { - [filter addObjectsFromArray:@[@"dotx", @"ott"]]; + if ( [params objectForKey:@"path"] or [params objectForKey:@"id"] ) {} + else { + NSOpenPanel * openPanel = [NSOpenPanel openPanel]; + NSMutableArray * filter = [NSMutableArray array]; + + if ( [params[@"type"] isEqualToNumber:@((int)AscEditorType::etPresentation)] ) { + [filter addObjectsFromArray:@[@"potx", @"otp"]]; + } else if ( [params[@"type"] isEqualToNumber:@((int)AscEditorType::etSpreadsheet)] ) { + [filter addObjectsFromArray:@[@"xltx", @"xltm", @"ots"]]; + } else { + [filter addObjectsFromArray:@[@"dotx", @"ott"]]; + } + + openPanel.canChooseDirectories = NO; + openPanel.allowsMultipleSelection = NO; + openPanel.canChooseFiles = YES; + openPanel.allowedFileTypes = filter; + + if ([openPanel runModal] == NSModalResponseOK) { + [params setValue:[[openPanel URL] path] forKey:@"path"]; + } else return; } - - openPanel.canChooseDirectories = NO; - openPanel.allowsMultipleSelection = NO; - openPanel.canChooseFiles = YES; - openPanel.allowedFileTypes = filter; - - if ([openPanel runModal] == NSModalResponseOK) { - [params setValue:[[openPanel URL] path] forKey:@"template"]; - } else return; } else if ([params[@"action"] isEqualToNumber:@(ASCTabActionOpenLocalRecentFile)] || [params[@"action"] isEqualToNumber:@(ASCTabActionOpenLocalFile)]) @@ -1937,7 +1940,7 @@ - (void)tabs:(ASCTabsControl *)control didAddTab:(ASCTabView *)tab { if (action == ASCTabActionCreateLocalFile ) { [cefView createFileWithName:docName type:docType]; } else { - [cefView createFileWithNameFromTemplate:docName tplpath:tab.params[@"template"]]; + [cefView createFileWithNameFromTemplate:docName tplpath:tab.params[@"path"]]; } break; diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm b/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm index ae61f87f6..5be979473 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm @@ -715,6 +715,27 @@ virtual void OnEvent(NSEditorApi::CAscCefMenuEvent* pRawEvent) @"type" : @(int(docType)), @"active" : @(YES) }]; + } else if ([nsParam hasPrefix:@"{\"template\":"]) { + NSDictionary * json = [[NSString stringWithstdwstring:param] dictionary][@"template"]; + + AscEditorType docType = AscEditorType::etDocument; + if ( [json objectForKey:@"type"] ) { + int tplType = [json[@"type"] intValue]; +// if ( tplType > AVS_OFFICESTUDIO_FILE_DOCUMENT and tplType < AVS_OFFICESTUDIO_FILE_PRESENTATION ) docType = AscEditorType::etDocument; else + if ( tplType > AVS_OFFICESTUDIO_FILE_PRESENTATION and tplType < AVS_OFFICESTUDIO_FILE_SPREADSHEET ) docType = AscEditorType::etPresentation; else + if ( tplType > AVS_OFFICESTUDIO_FILE_SPREADSHEET and tplType < AVS_OFFICESTUDIO_FILE_CROSSPLATFORM ) docType = AscEditorType::etSpreadsheet; +// else if ( tplType > AVS_OFFICESTUDIO_FILE_CROSSPLATFORM and tplType < AVS_OFFICESTUDIO_FILE_IMAGE ) {} + } + + [[NSNotificationCenter defaultCenter] postNotificationName:CEFEventNameCreateTab + object:nil + userInfo:@{ + @"action" : @(ASCTabActionCreateLocalFileFromTemplate), + @"type" : @(int(docType)), + @"active" : @(YES), + @"path" : json[@"path"], + @"id" : json[@"id"], + }]; } else { if ([nsParam isEqualToString:@"word"]) { docType = AscEditorType::etDocument;