| 249 | } |
| 250 | |
| 251 | void PluginBase::onRegister( UICodeEditor* editor ) { |
| 252 | Lock l( mMutex ); |
| 253 | |
| 254 | std::vector<Uint32> listeners; |
| 255 | |
| 256 | listeners.push_back( editor->on( Event::OnDocumentLoaded, [this, editor]( const Event* event ) { |
| 257 | Lock l( mMutex ); |
| 258 | const DocEvent* docEvent = static_cast<const DocEvent*>( event ); |
| 259 | mDocs.insert( docEvent->getDoc() ); |
| 260 | mEditorDocs[editor] = docEvent->getDoc(); |
| 261 | onDocumentLoaded( docEvent->getDoc() ); |
| 262 | } ) ); |
| 263 | |
| 264 | listeners.push_back( editor->on( Event::OnDocumentClosed, [this]( const Event* event ) { |
| 265 | { |
| 266 | Lock l( mMutex ); |
| 267 | const DocEvent* docEvent = static_cast<const DocEvent*>( event ); |
| 268 | TextDocument* doc = docEvent->getDoc(); |
| 269 | onDocumentClosed( doc ); |
| 270 | onUnregisterDocument( doc ); |
| 271 | mDocs.erase( doc ); |
| 272 | } |
| 273 | } ) ); |
| 274 | |
| 275 | listeners.push_back( editor->on( Event::OnDocumentChanged, [this, editor]( const Event* ) { |
| 276 | TextDocument* oldDoc = mEditorDocs[editor]; |
| 277 | TextDocument* newDoc = editor->getDocumentRef().get(); |
| 278 | Lock l( mMutex ); |
| 279 | mDocs.erase( oldDoc ); |
| 280 | mDocs.insert( newDoc ); |
| 281 | mEditorDocs[editor] = newDoc; |
| 282 | onDocumentChanged( editor, oldDoc ); |
| 283 | } ) ); |
| 284 | |
| 285 | onRegisterListeners( editor, listeners ); |
| 286 | |
| 287 | mEditors.insert( { editor, listeners } ); |
| 288 | if ( mDocs.count( editor->getDocumentRef().get() ) == 0 ) { |
| 289 | mDocs.insert( editor->getDocumentRef().get() ); |
| 290 | onRegisterDocument( editor->getDocumentRef().get() ); |
| 291 | } |
| 292 | mEditorDocs[editor] = editor->getDocumentRef().get(); |
| 293 | |
| 294 | onRegisterEditor( editor ); |
| 295 | } |
| 296 | |
| 297 | void PluginBase::onUnregister( UICodeEditor* editor ) { |
| 298 | onBeforeUnregister( editor ); |