|
| 1 | +""" |
| 2 | +This module contains various context menus used in the main GUI. |
| 3 | +Copyright 2021 Bill Dengler and open-source contributors |
| 4 | +This Source Code Form is subject to the terms of the Mozilla Public |
| 5 | +License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 | +file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 7 | +""" |
| 8 | + |
| 9 | +import gettext |
| 10 | +import wx |
| 11 | + |
| 12 | +_ = gettext.translation("treemendous", fallback=True).gettext |
| 13 | + |
| 14 | + |
| 15 | +class AddNodeMenu(wx.Menu): |
| 16 | + def __init__(self, parent): |
| 17 | + super().__init__() |
| 18 | + self.parent = parent |
| 19 | + |
| 20 | + child = wx.MenuItem( |
| 21 | + self, |
| 22 | + wx.ID_ANY, |
| 23 | + # Translators: The option for adding a child in the add node pop-up menu. |
| 24 | + _("&Child"), |
| 25 | + # Translators: Help text in the add node pop-up menu. |
| 26 | + _("Add a new node as an immediate child of the current selection"), |
| 27 | + ) |
| 28 | + self.Append(child) |
| 29 | + self.Bind(wx.EVT_MENU, self.OnChild, child) |
| 30 | + |
| 31 | + parent = wx.MenuItem( |
| 32 | + self, |
| 33 | + wx.ID_ANY, |
| 34 | + # Translators: The option for adding a parent in the add node pop-up menu. |
| 35 | + _("&Parent"), |
| 36 | + # Translators: Help text in the add node pop-up menu. |
| 37 | + _("Add a new node that contains the currently selected subtree"), |
| 38 | + ) |
| 39 | + self.Append(parent) |
| 40 | + self.Bind(wx.EVT_MENU, self.OnParent, parent) |
| 41 | + |
| 42 | + if self.parent.tree.selection != self.parent.tree.root: |
| 43 | + sibling = wx.MenuItem( |
| 44 | + self, |
| 45 | + wx.ID_ANY, |
| 46 | + # Translators: The option for adding a sibling in the add node pop-up menu. |
| 47 | + _("&Sibling"), |
| 48 | + _( |
| 49 | + # Translators: Help text in the add node pop-up menu. |
| 50 | + "Add a new node as an immediate sibling (same level) of the current selection" |
| 51 | + ), |
| 52 | + ) |
| 53 | + self.Append(sibling) |
| 54 | + self.Bind(wx.EVT_MENU, self.OnSibling, sibling) |
| 55 | + |
| 56 | + def OnChild(self, event): |
| 57 | + return self.parent.DoAddChild() |
| 58 | + |
| 59 | + def OnParent(self, event): |
| 60 | + return self.parent.DoAddParent() |
| 61 | + |
| 62 | + def OnSibling(self, event): |
| 63 | + return self.parent.DoAddSibling() |
| 64 | + |
| 65 | + |
| 66 | +class PasteDestMenu(wx.Menu): |
| 67 | + def __init__(self, parent, event): |
| 68 | + super().__init__() |
| 69 | + self.parent = parent |
| 70 | + self.event = event |
| 71 | + |
| 72 | + child = wx.MenuItem( |
| 73 | + self, |
| 74 | + wx.ID_ANY, |
| 75 | + # Translators: An option in the paste pop-up menu. |
| 76 | + _("As &child"), |
| 77 | + # Translators: Help text in the paste pop-up menu. |
| 78 | + _("Paste as an immediate child of the current selection"), |
| 79 | + ) |
| 80 | + self.Append(child) |
| 81 | + self.Bind(wx.EVT_MENU, self.OnChild, child) |
| 82 | + |
| 83 | + parent = wx.MenuItem( |
| 84 | + self, |
| 85 | + wx.ID_ANY, |
| 86 | + # Translators: An option in the paste pop-up menu. |
| 87 | + _("As &parent"), |
| 88 | + # Translators: Help text in the paste pop-up menu. |
| 89 | + _("Merge the pasteboard with the current selection."), |
| 90 | + ) |
| 91 | + self.Append(parent) |
| 92 | + self.Bind(wx.EVT_MENU, self.OnParent, parent) |
| 93 | + |
| 94 | + if self.parent.tree.selection != self.parent.tree.root: |
| 95 | + sibling = wx.MenuItem( |
| 96 | + self, |
| 97 | + wx.ID_ANY, |
| 98 | + # Translators: An option in the paste pop-up menu. |
| 99 | + _("As &sibling"), |
| 100 | + _( |
| 101 | + # Translators: Help text in the paste pop-up menu. |
| 102 | + "Paste as an immediate sibling (same level) of the current selection" |
| 103 | + ), |
| 104 | + ) |
| 105 | + self.Append(sibling) |
| 106 | + self.Bind(wx.EVT_MENU, self.OnSibling, sibling) |
| 107 | + |
| 108 | + def OnChild(self, event): |
| 109 | + return self.parent.PasteChild(self.event) |
| 110 | + |
| 111 | + def OnParent(self, event): |
| 112 | + return self.parent.PasteParent(self.event) |
| 113 | + |
| 114 | + def OnSibling(self, event): |
| 115 | + return self.parent.PasteSibling(self.event) |
| 116 | + |
| 117 | + |
| 118 | +class NodeContextMenu(wx.Menu): |
| 119 | + def __init__(self, parent): |
| 120 | + super().__init__() |
| 121 | + self.parent = parent |
| 122 | + |
| 123 | + addSubmenu = AddNodeMenu(parent) |
| 124 | + self.AppendSubMenu( |
| 125 | + addSubmenu, |
| 126 | + # Translators: An item in the node context (shift+f10) menu. |
| 127 | + _("&Add node"), |
| 128 | + help=_( |
| 129 | + # Translators: Help text in the node context (shift+F10) menu. |
| 130 | + "Add a new node relative to the current selection." |
| 131 | + ), |
| 132 | + ) |
| 133 | + |
| 134 | + edit = wx.MenuItem( |
| 135 | + self, |
| 136 | + wx.ID_EDIT, |
| 137 | + # Translators: An item in the node context (shift+f10) menu. |
| 138 | + _("Edit node...\tF2"), |
| 139 | + # Translators: Help text in the node context (shift+F10) menu. |
| 140 | + _("Edit the currently selected node."), |
| 141 | + ) |
| 142 | + self.Append(edit) |
| 143 | + |
| 144 | + up = wx.MenuItem( |
| 145 | + self, |
| 146 | + wx.ID_ANY, |
| 147 | + # Translators: An item in the node context (shift+f10) menu. |
| 148 | + _("Move up\tAlt+up"), |
| 149 | + # Translators: Help text in the node context (shift+F10) menu. |
| 150 | + _("Move subtree to previous position in parent."), |
| 151 | + ) |
| 152 | + self.Append(up) |
| 153 | + self.Bind(wx.EVT_MENU, self.OnUp, up) |
| 154 | + |
| 155 | + dn = wx.MenuItem( |
| 156 | + self, |
| 157 | + wx.ID_ANY, |
| 158 | + # Translators: An item in the node context (shift+f10) menu. |
| 159 | + _("Move down\tAlt+down"), |
| 160 | + # Translators: Help text in the node context (shift+F10) menu. |
| 161 | + _("Move subtree to next position in parent."), |
| 162 | + ) |
| 163 | + self.Append(dn) |
| 164 | + self.Bind(wx.EVT_MENU, self.OnDn, dn) |
| 165 | + |
| 166 | + delsubtree = wx.MenuItem( |
| 167 | + self, |
| 168 | + wx.ID_DELETE, |
| 169 | + # Translators: An item in the node context (shift+f10) menu. |
| 170 | + _("&Delete subtree\tDEL"), |
| 171 | + # Translators: Help text in the node context (shift+F10) menu. |
| 172 | + _("Delete this node and all of its descendants."), |
| 173 | + ) |
| 174 | + self.Append(delsubtree) |
| 175 | + |
| 176 | + def OnUp(self, event): |
| 177 | + return self.parent.OnMoveUp(event) |
| 178 | + |
| 179 | + def OnDn(self, event): |
| 180 | + return self.parent.OnMoveDown(event) |
0 commit comments