diff --git a/gui/wxpython/history/tree.py b/gui/wxpython/history/tree.py index 3701fefb001..b5488c23d0e 100644 --- a/gui/wxpython/history/tree.py +++ b/gui/wxpython/history/tree.py @@ -216,6 +216,10 @@ def _popupMenuCommand(self): """Create popup menu for commands""" menu = Menu() + copyItem = wx.MenuItem(menu, wx.ID_ANY, _("&Copy")) + menu.AppendItem(copyItem) + self.Bind(wx.EVT_MENU, self.OnCopyCmd, copyItem) + item = wx.MenuItem(menu, wx.ID_ANY, _("&Remove")) menu.AppendItem(item) self.Bind(wx.EVT_MENU, self.OnRemoveCmd, item) @@ -658,3 +662,25 @@ def OnDoubleClick(self, node): self.CollapseNode(node, recursive=False) else: self.ExpandNode(node, recursive=False) + + def OnCopyCmd(self, event): + """Copy selected cmd to clipboard""" + self.DefineItems(self.GetSelected()) + if not self.selected_command: + return + + selected_command = self.selected_command[0] + command = selected_command.data["name"] + + # Copy selected command to clipboard + try: + if wx.TheClipboard.Open(): + try: + wx.TheClipboard.SetData(wx.TextDataObject(command)) + self.showNotification.emit( + message=_("Command <{}> copied to clipboard").format(command) + ) + finally: + wx.TheClipboard.Close() + except wx.PyWidgetError: + self.showNotification.emit(message=_("Failed to copy command to clipboard"))