Also remove apply button from auto-replace settings
This commit is contained in:
@@ -30,7 +30,7 @@ from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||
from PyQt5.QtGui import QCloseEvent, QColor
|
||||
from PyQt5.QtWidgets import (
|
||||
QAbstractItemView, QApplication, QColorDialog, QDialogButtonBox,
|
||||
QHBoxLayout, QLineEdit, QMenu, QStackedWidget, QToolButton, QTreeWidget,
|
||||
QHBoxLayout, QLineEdit, QMenu, QStackedWidget, QTreeWidget,
|
||||
QTreeWidgetItem, QVBoxLayout, QWidget
|
||||
)
|
||||
|
||||
@@ -660,15 +660,12 @@ class _ReplacePage(NFixedPage):
|
||||
self.editKey.setPlaceholderText(self.tr("Select item to edit"))
|
||||
self.editKey.setEnabled(False)
|
||||
self.editKey.setMaxLength(40)
|
||||
self.editKey.textEdited.connect(self._onKeyEdit)
|
||||
|
||||
self.editValue = QLineEdit(self)
|
||||
self.editValue.setEnabled(False)
|
||||
self.editValue.setMaxLength(80)
|
||||
|
||||
self.applyButton = QToolButton(self)
|
||||
self.applyButton.setText(self.tr("Apply"))
|
||||
self.applyButton.setSizePolicy(QtSizeMinimum, QtSizeMinimumExpanding)
|
||||
self.applyButton.clicked.connect(self._applyChanges)
|
||||
self.editValue.setMaxLength(250)
|
||||
self.editValue.textEdited.connect(self._onValueEdit)
|
||||
|
||||
# Assemble
|
||||
self.listControls = QVBoxLayout()
|
||||
@@ -679,7 +676,6 @@ class _ReplacePage(NFixedPage):
|
||||
self.editBox = QHBoxLayout()
|
||||
self.editBox.addWidget(self.editKey, 4)
|
||||
self.editBox.addWidget(self.editValue, 5)
|
||||
self.editBox.addWidget(self.applyButton, 0)
|
||||
|
||||
self.mainBox = QVBoxLayout()
|
||||
self.mainBox.addWidget(self.listBox, 1)
|
||||
@@ -711,7 +707,7 @@ class _ReplacePage(NFixedPage):
|
||||
new = {}
|
||||
for n in range(self.listBox.topLevelItemCount()):
|
||||
if item := self.listBox.topLevelItem(n):
|
||||
if key := self._stripNotAllowed(item.text(self.C_KEY)):
|
||||
if key := self._stripKey(item.text(self.C_KEY)):
|
||||
new[key] = item.text(self.C_REPL)
|
||||
return new
|
||||
|
||||
@@ -723,13 +719,29 @@ class _ReplacePage(NFixedPage):
|
||||
# Private Slots
|
||||
##
|
||||
|
||||
@pyqtSlot(str)
|
||||
def _onKeyEdit(self, text: str) -> None:
|
||||
"""Update the key text."""
|
||||
if (item := self._getSelectedItem()) and (key := self._stripKey(text)):
|
||||
item.setText(self.C_KEY, f"<{key}>")
|
||||
self._changed = True
|
||||
return
|
||||
|
||||
@pyqtSlot(str)
|
||||
def _onValueEdit(self, text: str) -> None:
|
||||
"""Update the value text."""
|
||||
if item := self._getSelectedItem():
|
||||
item.setText(self.C_REPL, text)
|
||||
self._changed = True
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _selectionChanged(self) -> None:
|
||||
"""Extract the details from the selected item and populate the
|
||||
edit form.
|
||||
"""
|
||||
if item := self._getSelectedItem():
|
||||
self.editKey.setText(self._stripNotAllowed(item.text(self.C_KEY)))
|
||||
self.editKey.setText(self._stripKey(item.text(self.C_KEY)))
|
||||
self.editValue.setText(item.text(self.C_REPL))
|
||||
self.editKey.setEnabled(True)
|
||||
self.editValue.setEnabled(True)
|
||||
@@ -742,18 +754,6 @@ class _ReplacePage(NFixedPage):
|
||||
self.editValue.setEnabled(False)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _applyChanges(self) -> None:
|
||||
"""Save the form data into the list widget."""
|
||||
if item := self._getSelectedItem():
|
||||
key = self._stripNotAllowed(self.editKey.text())
|
||||
value = self.editValue.text()
|
||||
if key and value:
|
||||
item.setText(self.C_KEY, f"<{key}>")
|
||||
item.setText(self.C_REPL, value)
|
||||
self._changed = True
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _addEntry(self) -> None:
|
||||
"""Add a new list entry."""
|
||||
@@ -779,6 +779,6 @@ class _ReplacePage(NFixedPage):
|
||||
return items[0]
|
||||
return None
|
||||
|
||||
def _stripNotAllowed(self, key: str) -> str:
|
||||
def _stripKey(self, key: str) -> str:
|
||||
"""Clean up the replace key string."""
|
||||
return "".join(c for c in key if c.isalnum())
|
||||
|
||||
@@ -349,7 +349,6 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
|
||||
# Nothing to save or delete
|
||||
replace.listBox.clearSelection()
|
||||
replace._applyChanges()
|
||||
replace._delEntry()
|
||||
assert replace.listBox.topLevelItemCount() == 2
|
||||
|
||||
@@ -361,13 +360,8 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
|
||||
# Edit the entry
|
||||
replace.listBox.setCurrentItem(replace.listBox.topLevelItem(2))
|
||||
replace.editKey.setText("")
|
||||
for c in "Th is ":
|
||||
qtbot.keyClick(replace.editKey, c, delay=KEY_DELAY)
|
||||
replace.editValue.setText("")
|
||||
for c in "With This Stuff ":
|
||||
qtbot.keyClick(replace.editValue, c, delay=KEY_DELAY)
|
||||
qtbot.mouseClick(replace.applyButton, QtMouseLeft)
|
||||
replace._onKeyEdit("Th is ")
|
||||
replace._onValueEdit("With This Stuff ")
|
||||
assert replace.listBox.topLevelItem(2).text(0) == "<This>" # type: ignore
|
||||
assert replace.listBox.topLevelItem(2).text(1) == "With This Stuff " # type: ignore
|
||||
|
||||
|
||||
Reference in New Issue
Block a user