Offer clearing fields when closing code dialog
The offer is only made if the content has been copied at least once
This commit is contained in:
parent
f51e5ed878
commit
3fe735e596
1 changed files with 19 additions and 1 deletions
|
@ -53,10 +53,11 @@ class WikiCodeDialog(QDialog, Ui_WikiCode):
|
||||||
def __init__(self, code, *args, **kwargs):
|
def __init__(self, code, *args, **kwargs):
|
||||||
super(WikiCodeDialog, self).__init__(*args, **kwargs)
|
super(WikiCodeDialog, self).__init__(*args, **kwargs)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.copied = False
|
||||||
|
|
||||||
self.e_code.setPlainText(code)
|
self.e_code.setPlainText(code)
|
||||||
|
|
||||||
self.b_close.clicked.connect(self.close)
|
self.b_close.clicked.connect(self.clear_fields)
|
||||||
self.b_copy.clicked.connect(self.copy)
|
self.b_copy.clicked.connect(self.copy)
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
@ -64,6 +65,20 @@ class WikiCodeDialog(QDialog, Ui_WikiCode):
|
||||||
def copy(self):
|
def copy(self):
|
||||||
self.e_code.selectAll()
|
self.e_code.selectAll()
|
||||||
self.e_code.copy()
|
self.e_code.copy()
|
||||||
|
self.copied = True
|
||||||
|
|
||||||
|
def clear_fields(self):
|
||||||
|
"""
|
||||||
|
Show the clear fields dialog if the code was at least copied once.
|
||||||
|
"""
|
||||||
|
if self.copied:
|
||||||
|
dialog = ClearDialog()
|
||||||
|
dialog.rejected.connect(self.reject)
|
||||||
|
dialog.accepted.connect(self.accept)
|
||||||
|
dialog.exec_()
|
||||||
|
else:
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -289,6 +304,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
code = current_recipe.wikicode(writer)
|
code = current_recipe.wikicode(writer)
|
||||||
|
|
||||||
dialog = WikiCodeDialog(code)
|
dialog = WikiCodeDialog(code)
|
||||||
|
dialog.accepted.connect(self.clear)
|
||||||
|
dialog.exec_()
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
"""
|
"""
|
||||||
Clear all fields
|
Clear all fields
|
||||||
|
|
Reference in a new issue