check if form is dirty
This commit is contained in:
@@ -71,7 +71,7 @@ class HighlightingDialog(QDialog):
|
|||||||
|
|
||||||
row = row + 1
|
row = row + 1
|
||||||
self.buttons = QDialogButtonBox()
|
self.buttons = QDialogButtonBox()
|
||||||
self.buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Save)
|
self.buttons.setStandardButtons(QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok)
|
||||||
self.buttons.accepted.connect(self._save)
|
self.buttons.accepted.connect(self._save)
|
||||||
self.buttons.rejected.connect(self.close)
|
self.buttons.rejected.connect(self.close)
|
||||||
form_grid.addWidget(self.buttons, row, 0, 1, 2)
|
form_grid.addWidget(self.buttons, row, 0, 1, 2)
|
||||||
@@ -126,6 +126,16 @@ class HighlightingDialog(QDialog):
|
|||||||
self.list.setCurrentIndex(index.sibling(selected_index + 1, 0))
|
self.list.setCurrentIndex(index.sibling(selected_index + 1, 0))
|
||||||
|
|
||||||
def _save(self):
|
def _save(self):
|
||||||
|
|
||||||
|
if self._is_dirty():
|
||||||
|
unsaved = QMessageBox(QMessageBox.Icon.Question, self.tr("unsaved changes"),
|
||||||
|
self.tr("You have unsaved changes. Continue?"))
|
||||||
|
unsaved.setStandardButtons(QMessageBox.StandardButton.Cancel)
|
||||||
|
unsaved.addButton(QPushButton(self.tr("Continue")), QMessageBox.ButtonRole.AcceptRole)
|
||||||
|
result = unsaved.exec()
|
||||||
|
if result == QMessageBox.StandardButton.Cancel:
|
||||||
|
return
|
||||||
|
|
||||||
highlighters = []
|
highlighters = []
|
||||||
for index in range(0, self.list.count()):
|
for index in range(0, self.list.count()):
|
||||||
item: PayloadItem = self.list.item(index)
|
item: PayloadItem = self.list.item(index)
|
||||||
@@ -156,6 +166,21 @@ class HighlightingDialog(QDialog):
|
|||||||
self.hit_background_color.set_color(highlighter.hit_background_color)
|
self.hit_background_color.set_color(highlighter.hit_background_color)
|
||||||
self.line_background_color.set_color(highlighter.line_background_color)
|
self.line_background_color.set_color(highlighter.line_background_color)
|
||||||
|
|
||||||
|
def _is_dirty(self):
|
||||||
|
if len(self.list.selectedIndexes()) == 0:
|
||||||
|
dirty = False
|
||||||
|
if len(self.list.selectedIndexes()) == 1:
|
||||||
|
item: PayloadItem = self.list.currentItem()
|
||||||
|
highlighter: HighlightRegex = item.payload
|
||||||
|
dirty = self.query.text() != highlighter.query \
|
||||||
|
or self.ignore_case.isChecked() != highlighter.ignore_case \
|
||||||
|
or self.is_regex.isChecked() != highlighter.is_regex \
|
||||||
|
or self.hit_background_color.color != highlighter.hit_background_color \
|
||||||
|
or self.line_background_color.color != highlighter.line_background_color
|
||||||
|
else:
|
||||||
|
dirty = False
|
||||||
|
return dirty
|
||||||
|
|
||||||
def _load_existing_hightlighters(self):
|
def _load_existing_hightlighters(self):
|
||||||
highlighters: [HighlightRegex] = Highlighting.read_config(self._settings)
|
highlighters: [HighlightRegex] = Highlighting.read_config(self._settings)
|
||||||
first_item = None
|
first_item = None
|
||||||
|
|||||||
Reference in New Issue
Block a user