| 1 |
# (C) Copyright 2007-2025 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
""" The default base class for extension providers. """ |
| 11 |
|
| 12 |
|
| 13 |
# Enthought library imports. |
| 14 |
from traits.api import Event, HasTraits, provides |
| 15 |
|
| 16 |
# Local imports. |
| 17 |
from .extension_point_changed_event import ExtensionPointChangedEvent |
| 18 |
from .i_extension_provider import IExtensionProvider |
| 19 |
|
| 20 |
|
| 21 |
@provides(IExtensionProvider) |
| 22 |
class ExtensionProvider(HasTraits): |
| 23 |
"""The default base class for extension providers.""" |
| 24 |
|
| 25 |
#### 'IExtensionProvider' interface ####################################### |
| 26 |
|
| 27 |
#: The event fired when one of the provider's extension points has been |
| 28 |
#: changed (where 'changed' means that the provider has added or removed |
| 29 |
#: contributions to or from an extension point). |
| 30 |
extension_point_changed = Event(ExtensionPointChangedEvent) |
| 31 |
|
| 32 |
def get_extension_points(self): |
| 33 |
"""Return the extension points offered by the provider.""" |
| 34 |
|
| 35 |
return [] |
| 36 |
|
| 37 |
def get_extensions(self, extension_point_id): |
| 38 |
"""Return the provider's extensions to an extension point.""" |
| 39 |
|
| 40 |
return [] |
| 41 |
|
| 42 |
##### Protected 'ExtensionProvider' interface ############################# |
| 43 |
|
| 44 |
def _fire_extension_point_changed( |
| 45 |
self, extension_point_id, added, removed, index |
| 46 |
): |
| 47 |
"""Fire an extension point changed event.""" |
| 48 |
|
| 49 |
self.extension_point_changed = ExtensionPointChangedEvent( |
| 50 |
extension_point_id=extension_point_id, |
| 51 |
added=added, |
| 52 |
removed=removed, |
| 53 |
index=index, |
| 54 |
) |