Merge event dispatch methods in ScriptManager

This commit is contained in:
1024jp 2021-09-20 21:53:26 +09:00
parent fceb498261
commit 498406bce6
2 changed files with 10 additions and 22 deletions

View File

@ -427,7 +427,7 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingHolder {
}
if !saveOperation.isAutosaving {
ScriptManager.shared.dispatchEvent(documentSaved: self)
ScriptManager.shared.dispatch(event: .documentSaved, document: self)
}
}
}
@ -741,7 +741,7 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingHolder {
// [caution] This method may be called from a background thread due to concurrent-opening.
// -> This method won't be invoked on Resume. (2015-01-26)
ScriptManager.shared.dispatchEvent(documentOpened: self)
ScriptManager.shared.dispatch(event: .documentOpened, document: self)
}

View File

@ -142,27 +142,15 @@ final class ScriptManager: NSObject, NSFilePresenter {
/// Dispatch an Apple Event that notifies the given document was opened.
///
/// - Parameter document: The document that was opened.
func dispatchEvent(documentOpened document: Document) {
/// - Parameters:
/// - eventType: The event trigger to perform script.
/// - document: The target document.
func dispatch(event eventType: ScriptingEventType, document: Document) {
let eventType = ScriptingEventType.documentOpened
guard let scripts = self.scriptHandlersTable[eventType], !scripts.isEmpty else { return }
let event = self.createEvent(by: document, eventID: eventType.eventID)
self.dispatch(event, handlers: scripts)
}
/// Dispatch an Apple Event that notifies the given document was opened.
///
/// - Parameter document: The document that was opened.
func dispatchEvent(documentSaved document: Document) {
let eventType = ScriptingEventType.documentSaved
guard let scripts = self.scriptHandlersTable[eventType], !scripts.isEmpty else { return }
guard
let scripts = self.scriptHandlersTable[eventType],
!scripts.isEmpty
else { return }
let event = self.createEvent(by: document, eventID: eventType.eventID)