Skip to content

Commit

Permalink
Fixes for NewAction in the TreeEditor to remove shared state (#1953)
Browse files Browse the repository at this point in the history
* Fixes for NewAction in the TreeEditor to remove shared state

* Add changelog entry.

* Update comment.
  • Loading branch information
corranwebster committed Nov 4, 2022
1 parent 88719ff commit d12f6ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/releases/upcoming/1953.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issues with shared "New" context menu in TreeEditor (#1953)
9 changes: 6 additions & 3 deletions traitsui/qt4/tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def _on_tree_sel_changed(self):
editor.setUpdatesEnabled(True)

def _on_context_menu(self, pos):
"""Handles the user requesting a context menuright clicking on a tree node."""
"""Handles the user requesting a context menu on a tree node."""
nid = self._tree.itemAt(pos)

if nid is None:
Expand Down Expand Up @@ -986,8 +986,11 @@ def _on_context_menu(self, pos):
# Use the menu specified by the node:
group = menu.find_group(NewAction)
if group is not None:
# Only set it the first time:
group.id = ""
# Reset the group for the current usage in case it is shared
# - the call to `node.get_add()` is potentially dynamic and
# the callback `_menu_new_node()` captures state about this
# particular TreeEditor instance
group.clear()
actions = self._new_actions(node, object)
if len(actions) > 0:
group.insert(0, Menu(name="New", *actions))
Expand Down
7 changes: 5 additions & 2 deletions traitsui/wx/tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,11 @@ def _on_right_down(self, event):
# Use the menu specified by the node:
group = menu.find_group(NewAction)
if group is not None:
# Only set it the first time:
group.id = ""
# Reset the group for the current usage in case it is
# shared - the call to `node.get_add()` is potentially
# dynamic and the callback `_menu_new_node()` captures
# state about this particular TreeEditor instance
group.clear()
actions = self._new_actions(node, object)
if len(actions) > 0:
group.insert(0, Menu(name="New", *actions))
Expand Down

0 comments on commit d12f6ad

Please sign in to comment.