Skip to content

Commit

Permalink
[macos] fixed creation new doc from local template
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkadushkin committed Oct 9, 2024
1 parent fca2374 commit 6972611
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
41 changes: 22 additions & 19 deletions macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6972611

Please sign in to comment.