[macos] Handle close event from editors

This commit is contained in:
Alexander Yuzhin
2019-07-04 13:46:54 +03:00
parent 6dd688d8ff
commit f5e367d931
3 changed files with 32 additions and 0 deletions

View File

@ -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;

View File

@ -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]];

View File

@ -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";