mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-11-09 13:31:25 +03:00
Merge event dispatch methods in ScriptManager
This commit is contained in:
parent
fceb498261
commit
498406bce6
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user