diff --git a/docs/releases/upcoming/1953.bugfix.rst b/docs/releases/upcoming/1953.bugfix.rst new file mode 100644 index 000000000..6d88deec4 --- /dev/null +++ b/docs/releases/upcoming/1953.bugfix.rst @@ -0,0 +1 @@ +Fix issues with shared "New" context menu in TreeEditor (#1953) \ No newline at end of file diff --git a/traitsui/qt4/tree_editor.py b/traitsui/qt4/tree_editor.py index ddb0ac9fc..728526538 100644 --- a/traitsui/qt4/tree_editor.py +++ b/traitsui/qt4/tree_editor.py @@ -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: @@ -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)) diff --git a/traitsui/wx/tree_editor.py b/traitsui/wx/tree_editor.py index a32d92b81..ad1c2ab51 100644 --- a/traitsui/wx/tree_editor.py +++ b/traitsui/wx/tree_editor.py @@ -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))