Skip to content

Commit

Permalink
Move need_sync logic from features to classes. Feature was expecting …
Browse files Browse the repository at this point in the history
…obsolete "parent" attribute in the update context.

git-svn-id: file:///Users/arjan/backup/gaphor/gaphor/trunk@2090 a8418922-720d-0410-834f-a69b97ada669
  • Loading branch information
amolenaar committed Sep 5, 2007
1 parent 90574e2 commit 4b46aa0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
7 changes: 7 additions & 0 deletions gaphor/diagram/classifier.py
Expand Up @@ -27,6 +27,13 @@ def save(self, save_func):
for item in self:
save_func(None, item)

def get_need_sync(self):
for item in self:
if item.need_sync:
return True

need_sync = property(get_need_sync)

def has_item(self, item):
"""
Check if the compartment already contains an item with the
Expand Down
21 changes: 11 additions & 10 deletions gaphor/diagram/feature.py
Expand Up @@ -25,6 +25,7 @@ def __init__(self, id=None):
self.text = ''
# Fool unlink code:
self.canvas = None
self.need_sync = False


# Ensure we call the right connect functions:
Expand Down Expand Up @@ -70,7 +71,7 @@ class AttributeItem(FeatureItem):

def __init__(self, id=None):
FeatureItem.__init__(self, id)
self.need_sync_attributes = False
self.need_sync = False

def on_subject_notify(self, pspec, notifiers=()):
FeatureItem.on_subject_notify(self, pspec, ('name',
Expand Down Expand Up @@ -107,13 +108,13 @@ def on_subject_notify__association(self, subject, pspec):
"""
#if self.parent:
# self.parent.sync_attributes()
self.need_sync_attributes = True
self.need_sync = True
self.request_update()

def pre_update(self, context):
if self.need_sync_attributes and context.parent:
context.parent.sync_attributes()
self.need_sync_attributes = False
# if self.need_sync and context.parent:
# context.parent.sync_attributes()
self.need_sync = False
self.update_size(self.subject.render(), context)
#super(AttributeItem, self).pre_update(context)

Expand All @@ -131,7 +132,7 @@ class OperationItem(FeatureItem):

def __init__(self, id=None):
FeatureItem.__init__(self, id)
self.need_sync_operations = False
self.need_sync = False

def on_subject_notify(self, pspec, notifiers=()):
FeatureItem.on_subject_notify(self, pspec,
Expand All @@ -142,7 +143,7 @@ def on_subject_notify(self, pspec, notifiers=()):

def postload(self):
FeatureItem.postload(self)
self.need_sync_operations = False
self.need_sync = False

def on_subject_notify__name(self, subject, pspec):
#log.debug('setting text %s' % self.subject.render() or '')
Expand All @@ -153,9 +154,9 @@ def on_subject_notify__name(self, subject, pspec):
on_subject_notify__taggedValue = on_subject_notify__name

def pre_update(self, context):
if self.need_sync_operations and context.parent:
context.parent.sync_operations()
self.need_sync_operations = False
# if self.need_sync and context.parent:
# context.parent.sync_operations()
self.need_sync = False
self.update_size(self.subject.render(), context)
#super(OperationItem, self).pre_update(context)

Expand Down
16 changes: 11 additions & 5 deletions gaphor/diagram/klass.py
@@ -1,9 +1,6 @@
"""ClassItem diagram item
"""
# vim:sw=4:et

# TODO: make loading of features work (adjust on_groupable_add)
# probably best to do is subclass Feature in OperationItem and A.Item
ClassItem diagram item
"""

from gaphas.state import observed, reversible_property

Expand Down Expand Up @@ -123,3 +120,12 @@ def on_subject_notify__ownedOperation(self, subject, pspec=None):
#log.debug('on_subject_notify__ownedOperation')
self.sync_operations()

def pre_update(self, context):
if self._attributes.need_sync:
self.sync_attributes()
if self._operations.need_sync:
self.sync_operations()
super(ClassItem, self).pre_update(context)


# vim:sw=4:et:ai

0 comments on commit 4b46aa0

Please sign in to comment.