From f5e367d9312b64a54510e1050784de16f5b7141f Mon Sep 17 00:00:00 2001 From: Alexander Yuzhin Date: Thu, 4 Jul 2019 13:46:54 +0300 Subject: [PATCH] [macos] Handle close event from editors --- .../Common/ASCCommonViewController.mm | 24 +++++++++++++++++++ .../Controllers/Common/ASCEventsController.mm | 7 ++++++ macos/ONLYOFFICE/Code/Utils/ASCConstants.h | 1 + 3 files changed, 32 insertions(+) diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm index e5dd24663..283068a01 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm @@ -222,6 +222,11 @@ name:CEFEventNameEditorAppReady object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(onCEFEditorEvent:) + name:CEFEventNameEditorEvent + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onCEFEditorAppActionRequest:) name:CEFEventNameEditorAppActionRequest @@ -1524,6 +1529,25 @@ } } +- (void)onCEFEditorEvent:(NSNotification *)notification { + if (notification && notification.userInfo) { + id json = notification.userInfo; + + NSString * viewId = json[@"viewId"]; + NSDictionary * data = json[@"data"]; + + if (viewId && data) { + NSString * action = data[@"action"]; + + if (action && [action isEqualToString:@"close"]) { + if (ASCTabView * tab = [self.tabsControl tabWithUUID:viewId]) { + [self.tabsControl removeTab:tab selected:NO]; + } + } + } + } +} + - (void)onCEFEditorAppActionRequest:(NSNotification *)notification { if (notification && notification.userInfo) { id json = notification.userInfo; diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm b/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm index 1c8e825aa..06e30b805 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm @@ -556,6 +556,13 @@ public: userInfo:@{ @"viewId": [NSString stringWithFormat:@"%d", senderId] }]; + } else if (cmd.find(L"editor:event") != std::wstring::npos) { + [[NSNotificationCenter defaultCenter] postNotificationName:CEFEventNameEditorEvent + object:nil + userInfo:@{ + @"viewId": [NSString stringWithFormat:@"%d", senderId], + @"data": [[NSString stringWithstdwstring:param] dictionary] + }]; } else if (cmd.find(L"editor:request") != std::wstring::npos) { NSMutableDictionary * params = [NSMutableDictionary dictionaryWithDictionary:@{@"viewId": [NSString stringWithFormat:@"%d", senderId]}]; [params addEntriesFromDictionary:[[NSString stringWithstdwstring:param] dictionary]]; diff --git a/macos/ONLYOFFICE/Code/Utils/ASCConstants.h b/macos/ONLYOFFICE/Code/Utils/ASCConstants.h index 27ab149aa..a5d348169 100644 --- a/macos/ONLYOFFICE/Code/Utils/ASCConstants.h +++ b/macos/ONLYOFFICE/Code/Utils/ASCConstants.h @@ -113,6 +113,7 @@ static NSString * const CEFEventNameSaveBeforSign = @"CEF_saveBeforeSi static NSString * const CEFEventNameOpenSSLCertificate = @"CEF_openSSLCertificate"; static NSString * const CEFEventNameEditorDocumentReady = @"CEF_editorDocumentReady"; static NSString * const CEFEventNameEditorAppReady = @"CEF_editorAppReady"; +static NSString * const CEFEventNameEditorEvent = @"CEF_editorEvent"; static NSString * const CEFEventNameEditorAppActionRequest = @"CEF_editorAppActionRequest"; static NSString * const CEFEventNameEditorOpenFolder = @"CEF_editorOpenFolder"; static NSString * const CEFEventNameDocumentFragmentBuild = @"CEF_documentFragmentBuild";