From aea052cb6f46bef347be90f3bc4784df37dd1807 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:02:20 +0100 Subject: [PATCH] Draft: Fix AnnotationStyleEditor delete last style error (#17758) * Draft: Fix AnnotationStyleEditor delete last style error Fixes #17716. * Fix rename problem as well The on_rename function should update self.current_style as well. To avoid this scenario: 1. Create style A. 2. Create style B. 3. Rename style B to C. 4. Switch to style A. 5. Press OK. 6. Start the tool again. 7. Result: there are 3 styles A, B and C. --- .../draftguitools/gui_annotationstyleeditor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Mod/Draft/draftguitools/gui_annotationstyleeditor.py b/src/Mod/Draft/draftguitools/gui_annotationstyleeditor.py index d0545687b7..844a2fe9c9 100644 --- a/src/Mod/Draft/draftguitools/gui_annotationstyleeditor.py +++ b/src/Mod/Draft/draftguitools/gui_annotationstyleeditor.py @@ -259,8 +259,19 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest): QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.No: return - self.form.comboBoxStyles.removeItem(index) + del self.styles[style] + # We need to reset self.current_style, which is the deleted style, + # to stop on_style_changed from adding that style again: + self.current_style = None + + self.form.comboBoxStyles.currentIndexChanged.disconnect(self.on_style_changed) + self.form.comboBoxStyles.removeItem(index) + if not self.styles: + self.form.comboBoxStyles.setCurrentIndex(0) + # Update the dialog and self.current_style: + self.on_style_changed(self.form.comboBoxStyles.currentIndex()) + self.form.comboBoxStyles.currentIndexChanged.connect(self.on_style_changed) def on_rename(self): """Execute as a callback when the rename button is pressed.""" @@ -285,6 +296,7 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest): del self.styles[style] self.styles[newname] = value self.renamed[style] = newname + self.current_style = newname def on_import(self): """Import styles from a json file."""