Skip to content

Commit

Permalink
gui: Add Copy command feature to GUI History panel
Browse files Browse the repository at this point in the history
  • Loading branch information
aniket2405 committed Jan 8, 2025
1 parent 970a8f8 commit 08f2d28
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions gui/wxpython/history/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -658,3 +662,27 @@ 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")
)

0 comments on commit 08f2d28

Please sign in to comment.