1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#-----------------------------------------------------------------------------
#
# Copyright (c) 2005, 2006 by Enthought, Inc.
# All rights reserved.
#
#-----------------------------------------------------------------------------
"""
A base class for editors that can be tracked by single project plugin projects.
"""
# Standard library imports.
import logging
# Enthought library imports
from enthought.envisage.workbench import DecoratedEditor
from enthought.traits.api import Instance
# Application specific imports.
from enthought.envisage.single_project.services import IPROJECT_MODEL
# Setup a logger for this module.
logger=logging.getLogger(__name__)
class ProjectEditor(DecoratedEditor):
"""
A base class for editors that can be tracked by single project plugin
projects.
"""
#########################################################################
# Attributes
#########################################################################
### public 'ProjectEditor' interface ####################################
# The project containing the resource we're editing
project = Instance('enthought.envisage.single_project.project.Project')
#########################################################################
# `object` interface
#########################################################################
#### operator methods ###################################################
def __init__(self, **traits):
"""
Constructor.
Extended to associate ourself with the current project.
"""
super(ProjectEditor, self).__init__(**traits)
# Make sure the current project knows this editor is associated with
# it's resources
model_service = self.window.application.get_service(IPROJECT_MODEL)
self.project = model_service.project
self.project.register_editor(self.resource, self)
return
#########################################################################
# 'Editor' interface.
#########################################################################
### public 'Editor' interface ###########################################
def destroy_control(self):
"""
Destroys the toolkit-specific control that represents the editor.
Extended to ensure that the current project stops associating us
with its resources.
"""
# Only do something if the editor is still open
if self.control:
logger.debug('Destroying control in ProjectEditor [%s]', self)
# Unregister from the associated project immediately.
self.project.register_editor(self.resource, self, remove=True)
super(ProjectEditor, self).destroy_control()
return
#### EOF ####################################################################
|