OpenSCAD: Make clearing field undoable

Also renames the clear button for clarity. Fixes #8576.
This commit is contained in:
Chris Hennes
2023-02-21 22:29:36 -06:00
parent 9e380a5bf6
commit 31799d5f13

View File

@@ -338,7 +338,7 @@ class AddSCADWidget(QtGui.QWidget):
self.textMsg.setMaximumHeight(h)
self.textMsg.resize(self.textMsg.width(),h)
self.buttonadd = QtGui.QPushButton(translate('OpenSCAD','Add'))
self.buttonclear = QtGui.QPushButton(translate('OpenSCAD','Clear'))
self.buttonclear = QtGui.QPushButton(translate('OpenSCAD','Clear code'))
self.buttonload = QtGui.QPushButton(translate('OpenSCAD','Load'))
self.buttonsave = QtGui.QPushButton(translate('OpenSCAD','Save'))
self.buttonrefresh = QtGui.QPushButton(translate('OpenSCAD','Refresh'))
@@ -357,7 +357,15 @@ class AddSCADWidget(QtGui.QWidget):
self.setLayout(layout)
self.setWindowTitle(translate('OpenSCAD','Add OpenSCAD Element'))
self.textEdit.setText(u'cube();')
self.buttonclear.clicked.connect(self.textEdit.clear)
def undoable_clear():
"""Clears the textEdit in a way that allows undo of the action"""
self.textEdit.setFocus()
self.textEdit.selectAll()
keypress = QtGui.QKeyEvent(QtGui.QKeyEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier)
QtGui.QGuiApplication.sendEvent(self.textEdit, keypress)
self.buttonclear.clicked.connect(undoable_clear)
def retranslateUi(self, widget=None):
self.buttonadd.setText(translate('OpenSCAD','Add'))
@@ -421,9 +429,9 @@ class AddSCADTask:
def loadelement(self):
filename, _ = QtGui.QFileDialog.getOpenFileName(
parent=self.form,
caption='Open file',
dir='.',
parent=self.form,
caption='Open file',
dir='.',
filter='OpenSCAD Files (*.scad)'
)
@@ -435,9 +443,9 @@ class AddSCADTask:
def saveelement(self) :
filename, _ = QtGui.QFileDialog.getSaveFileName(
parent=self.form,
caption='Open file',
dir='.',
parent=self.form,
caption='Open file',
dir='.',
filter='OpenSCAD Files (*.scad)'
)