Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/globalPlugins/webAccess/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class KbNavMultiCategorySettingsDialog(FillableMultiCategorySettingsDialog):
def onCharHook(self, evt):
keycode = evt.GetKeyCode()
mods = evt.GetModifiers()
if keycode == wx.WXK_F6 and mods == wx.MOD_NONE:
if keycode == wx.WXK_F6 and mods | wx.MOD_SHIFT == wx.MOD_SHIFT:
if self.catListCtrl.HasFocus():
self.container.SetFocus()
else:
Expand Down
90 changes: 86 additions & 4 deletions addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,73 @@ def updateData_others(self):
value = InvalidValue(value)
updateOrDrop(data, "index", value)

def copySelector(self):
self.updateData()
data = {"webAccess.selector" : self.getData()}
import json
data = json.dumps(data, indent=4)
import api
if api.copyToClip(data):
# Translators: A message from the Rule Editor dialog
ui.message(_("Criteria data copied to clipboard"))
return
wx.Bell()

def pasteSelector(self):
self.updateData()
import api
data = api.getClipData()
if not data:
wx.Bell()
return
import json
try:
data = json.loads(data)
except Exception:
wx.Bell()
return
if not isinstance(data, dict) and len(data) == 1:
wx.Bell()
return
key, data = data.popitem()
try:
if key == "webAccess.rule":
if len(data) != 1:
wx.Bell()
return
data = data[0]["criteria"]["selector"]
elif key == "webAccess.criteria":
data = data["selector"]
elif key == "webAccess.rule":
data = data["criteria"]
if len(data) != 1:
wx.Bell()
return
data = data[0]
elif key == "webAccess.selector":
pass
else:
wx.Bell()
return
except (AttributeError, TypeError):
wx.Bell()
return
if not data or set(data.keys()) == {"start", "end"}:
wx.Bell()
return
if self.getData():
if gui.messageBox(
# Translators: A prompt for confirmation on the Criteria Editor
message=_("Replace editor content with data from the clipboard?"),
# Translators: The title of a prompt for confirmation on the Criteria Editor
caption=_("Paste"),
style=wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION,
parent=self
) != wx.YES:
return
self.getData().clear()
self.getData().update(data)

def refreshContextMacroChoices(self, initial=False):
context = self.context
dropDown = self.contextMacroDropDown
Expand Down Expand Up @@ -1251,9 +1318,9 @@ def makeSettings(self, settingsSizer):

def onCharHook(self, evt):
# Bound by MultiCategorySettingsDialog.makeSettings
keycode = evt.GetKeyCode()
keyCode = evt.GetKeyCode()
mods = evt.GetModifiers()
if keycode == wx.WXK_F5 and mods in (wx.MOD_NONE, wx.MOD_CONTROL):
if keyCode == wx.WXK_F5 and mods in (wx.MOD_NONE, wx.MOD_CONTROL):
currCat = self.currentCategory
restrictDualNodeTo = None
if mods == wx.MOD_NONE:
Expand All @@ -1263,7 +1330,7 @@ def onCharHook(self, evt):
restrictDualNodeTo = "end"
currCat.updateData()
testCriteria(self.context, restrictDualNodeTo=restrictDualNodeTo)
elif keycode == wx.WXK_F8 and mods == wx.MOD_NONE:
elif keyCode == wx.WXK_F8 and mods == wx.MOD_NONE:
from ..inspector import show
try:
node = self.context["webModule"].ruleManager.nodeManager.getCaretNode().parent
Expand All @@ -1272,9 +1339,24 @@ def onCharHook(self, evt):
return
show(parent=self, node=node)
return
elif keycode == wx.WXK_F12 and mods == wx.MOD_NONE:
elif keyCode == wx.WXK_F12 and mods == wx.MOD_NONE:
self.switchToFullEditor()
return
elif self.catListCtrl.HasFocus():
cat = self.currentCategory
if isinstance(cat, CriteriaPanel):
if (
keyCode in (ord("C"), wx.WXK_INSERT, wx.WXK_NUMPAD_INSERT)
and mods == wx.MOD_CONTROL
):
cat.copySelector()
return
elif (
keyCode == ord("V") and mods == wx.MOD_CONTROL
or keyCode in (wx.WXK_INSERT, wx.WXK_NUMPAD_INSERT) and mods == wx.MOD_SHIFT
):
cat.pasteSelector()
return
super().onCharHook(evt)

def onConvertToDualNode(self, evt):
Expand Down
162 changes: 134 additions & 28 deletions addon/globalPlugins/webAccess/gui/rule/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def makeSettings(self, settingsSizer):
listEndCol = 2
item = self.criteriaList = wx.ListBox(self)
item.Bind(wx.EVT_LISTBOX, self.onCriteriaSelected)
item.Bind(wx.EVT_CHAR_HOOK, self.onCriteriaListCharHook)
gbSizer.Add(item, pos=(row, 0), span=(6, 3), flag=wx.EXPAND)

row += 6
Expand Down Expand Up @@ -530,20 +531,112 @@ def isValid(self):
return False
return True


@guarded
def copyAlternative(self):
index = self.getIndex()
if index == wx.NOT_FOUND:
wx.Bell()
return
data = {"webAccess.criteria" : self.getData()[index]}
import json
data = json.dumps(data, indent=4)
import api
if api.copyToClip(data):
# Translators: A message from the Rule Editor dialog
ui.message(_("Criteria data copied to clipboard"))
return
wx.Bell()

def pasteAlternative(self):
import api
data = api.getClipData()
if not data:
wx.Bell()
return
import json
try:
data = json.loads(data)
except Exception:
wx.Bell()
return
if not isinstance(data, dict) and len(data) == 1:
wx.Bell()
return
key, data = data.popitem()
if key == "webAccess.rule":
try:
data = data["criteria"]
if len(data) != 1:
wx.Bell()
return
data = data[0]
except (AttributeError, TypeError):
wx.Bell()
return
elif key == "webAccess.criteria":
pass
elif key == "webAccess.selector":
data = {"selector": data}
else:
wx.Bell()
return
if criteriaEditor.isDualNode(data) and self.getRuleType() != ruleTypes.ZONE:
wx.Bell()
return
self.onNewCriteria(pastedData=data)

def onCriteriaChange(self, change: Change, index: int):
self.updateCriteriaList(index)
self.refreshParent(self.categoryParams.treeNode)

@guarded
def onNewCriteria(self, evt):
prm = self.categoryParams
def onCriteriaListCharHook(self, evt):
keyCode = evt.KeyCode
mods = evt.GetModifiers()
if keyCode == wx.WXK_DELETE and mods == wx.MOD_NONE:
self.onDeleteCriteria()
return
elif (
keyCode in (ord("C"), wx.WXK_INSERT, wx.WXK_NUMPAD_INSERT)
and mods == wx.MOD_CONTROL
):
self.copyAlternative()
return
elif (
keyCode == ord("V") and mods == wx.MOD_CONTROL
or keyCode in (wx.WXK_INSERT, wx.WXK_NUMPAD_INSERT) and mods == wx.MOD_SHIFT
):
self.pasteAlternative()
return
evt.Skip()

@guarded
def onNewCriteria(self, evt=None, pastedData=None):
listData = self.getData()
index = self.getIndex()
if index != wx.NOT_FOUND:
itemData = listData[index]
if not itemData.get("name"):
with wx.TextEntryDialog(
self,
# Translators: A prompt on the Rule editor
_("You may first provide a name for the current criteria set:"),
# Translators: The title of an input dialog in the Rule Editor dialog
_("Add alternatives"),
) as dlg:
if dlg.ShowModal() != wx.ID_OK:
return
name = dlg.Value
if name:
itemData["name"] = name
self.onCriteriaChange(Change.UPDATE, index)
context = self.context.copy()
context["new"] = True
itemData = context["data"]["criteria"] = OrderedDict({
"criteriaIndex": len(self.getData())
})
if pastedData:
itemData.update(pastedData)
if criteriaEditor.show(context, parent=self):
index = itemData.pop("criteriaIndex")
listData.insert(index, itemData)
Expand All @@ -566,9 +659,11 @@ def onEditCriteria(self, evt, convertToDualNode=False):
self.onCriteriaChange(Change.UPDATE, index)

@guarded
def onDeleteCriteria(self, evt):
prm = self.categoryParams
def onDeleteCriteria(self, evt=None):
index = self.getIndex()
if index == wx.NOT_FOUND:
wx.Bell()
return
if gui.messageBox(
# Translator: A confirmation prompt on the Rule editor
_("Are you sure you want to delete this alternative?"),
Expand Down Expand Up @@ -742,10 +837,7 @@ def makeSettings_buttons(self, gbSizer, row, col, full=True):
row = startRow
# Translators: New criteria button label
item = self.newButton = wx.Button(self, label=_("&New..."))
item.Bind(
wx.EVT_BUTTON,
self.onNewCriteria if full else self.Parent.onAddAlternative,
)
item.Bind(wx.EVT_BUTTON, self.onNewCriteria)
gbSizer.Add(item, pos=(row, col))

row += 1
Expand Down Expand Up @@ -967,9 +1059,9 @@ def initData(self, context):
self.Thaw()

def onCharHook(self, evt):
keycode = evt.GetKeyCode()
keyCode = evt.GetKeyCode()
mods = evt.GetModifiers()
if keycode == wx.WXK_F5 and mods == wx.MOD_NONE:
if keyCode == wx.WXK_F5 and mods == wx.MOD_NONE:
self.testCriteria()
return
evt.Skip()
Expand Down Expand Up @@ -1002,6 +1094,7 @@ def onCriteriaChange(self, change: Change, index: int):
dlg = parent.Parent.Parent
if change is Change.CREATION:
dlg.switchToFullEditor()
return
parent.switchToAppropriatePanel()
parent.shownPanel.initData(self.context)

Expand Down Expand Up @@ -1035,20 +1128,6 @@ def updateData(self):
self.shownPanel.updateData()

def onAddAlternative(self, evt):
data = self.getData()
if not data.get("name"):
with wx.TextEntryDialog(
self,
# Translators: A prompt on the Rule editor
_("You may first provide a name for the current criteria set:"),
# Translators: The title of an input dialog in the Rule Editor dialog
_("Add alternatives"),
) as dlg:
if dlg.ShowModal() != wx.ID_OK:
return
name = dlg.Value
if name:
data["name"] = name
self.summaryPanel.onNewCriteria(evt)

def onConvertToDualNode(self, evt):
Expand All @@ -1064,6 +1143,9 @@ def isValid(self):
def delete(self):
wx.Bell()

def pasteAlternative(self):
self.summaryPanel.pasteAlternative()

def spaceIsPressedOnTreeNode(self):
self.shownPanel.spaceIsPressedOnTreeNode()

Expand Down Expand Up @@ -1296,9 +1378,9 @@ def focusContainerControl(self, index: int):

def onCharHook(self, evt):
# Bound by TreeMultiCategorySettingsDialog.makeSettings
keycode = evt.GetKeyCode()
keyCode = evt.KeyCode
mods = evt.GetModifiers()
if keycode == wx.WXK_F8 and mods == wx.MOD_NONE:
if keyCode == wx.WXK_F8 and mods == wx.MOD_NONE:
from ..inspector import show
try:
node = self.context["webModule"].ruleManager.nodeManager.getCaretNode().parent
Expand All @@ -1307,9 +1389,33 @@ def onCharHook(self, evt):
return
show(parent=self, node=node)
return
elif keycode == wx.WXK_F12 and mods == wx.MOD_NONE:
elif keyCode == wx.WXK_F12 and mods == wx.MOD_NONE:
self.switchToFullEditor()
return
elif self.catListCtrl.HasFocus():
cat = self.currentCategory
if (
isinstance(cat, SimpleCriteriaPanel)
and keyCode in (ord("C"), wx.WXK_INSERT, wx.WXK_NUMPAD_INSERT)
and mods == wx.MOD_CONTROL
):
cat.updateData()
cat.summaryPanel.copyAlternative()
return
elif (
isinstance(cat, (AlternativesPanel, SimpleCriteriaPanel))
and (
keyCode == ord("V") and mods == wx.MOD_CONTROL
or keyCode in (wx.WXK_INSERT, wx.WXK_NUMPAD_INSERT) and mods == wx.MOD_SHIFT
)
):
if (
isinstance(cat, SimpleCriteriaPanel)
and isinstance(cat.shownPanel, SimpleSingleNodeCriteriaPanel)
):
cat.updateData()
cat.pasteAlternative()
return
super().onCharHook(evt)

def switchToFullEditor(self):
Expand Down
Loading