1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-04-29 03:22:37 +02:00

fix(workspace-actions): use try/finally and restore previous blocked state in refresh_profiles

Agent-Logs-Url: https://github.com/bec-project/bec_widgets/sessions/004cb4bc-5015-485e-a803-1e63876b7024

Co-authored-by: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-27 12:18:19 +00:00
committed by wyzula-jan
parent 653cbd5e3e
commit 28140b9a8a
@@ -36,84 +36,86 @@ class ProfileComboBox(QComboBox):
"""
current_text = active_profile or self.currentText()
self.blockSignals(True)
self.clear()
was_blocked = self.blockSignals(True)
try:
self.clear()
quick_profiles = self._quick_provider()
quick_set = set(quick_profiles)
quick_profiles = self._quick_provider()
quick_set = set(quick_profiles)
items: list[str] = []
if show_empty_profile:
items.append("")
items: list[str] = []
if show_empty_profile:
items.append("")
if active_profile and active_profile not in quick_set:
items.append(active_profile)
if active_profile and active_profile not in quick_set:
items.append(active_profile)
for profile in quick_profiles:
if profile not in items:
items.append(profile)
for profile in quick_profiles:
if profile not in items:
items.append(profile)
if active_profile and active_profile not in quick_set:
# keep active profile at the top when not in quick list
items.remove(active_profile)
insert_pos = 1 if show_empty_profile else 0
items.insert(insert_pos, active_profile)
if active_profile and active_profile not in quick_set:
# keep active profile at the top when not in quick list
items.remove(active_profile)
insert_pos = 1 if show_empty_profile else 0
items.insert(insert_pos, active_profile)
for profile in items:
self.addItem(profile)
idx = self.count() - 1
for profile in items:
self.addItem(profile)
idx = self.count() - 1
# Reset any custom styling
self.setItemData(idx, None, Qt.ItemDataRole.FontRole)
self.setItemData(idx, None, Qt.ItemDataRole.ToolTipRole)
self.setItemData(idx, None, Qt.ItemDataRole.ForegroundRole)
# Reset any custom styling
self.setItemData(idx, None, Qt.ItemDataRole.FontRole)
self.setItemData(idx, None, Qt.ItemDataRole.ToolTipRole)
self.setItemData(idx, None, Qt.ItemDataRole.ForegroundRole)
if profile == "":
self.setItemData(idx, "Unsaved empty workspace", Qt.ItemDataRole.ToolTipRole)
if active_profile is None:
font = QFont(self.font())
font.setItalic(True)
self.setItemData(idx, font, Qt.ItemDataRole.FontRole)
if profile == "":
self.setItemData(idx, "Unsaved empty workspace", Qt.ItemDataRole.ToolTipRole)
if active_profile is None:
font = QFont(self.font())
font.setItalic(True)
self.setItemData(idx, font, Qt.ItemDataRole.FontRole)
self.setCurrentIndex(idx)
continue
if active_profile and profile == active_profile:
tooltip = "Active workspace profile"
if profile not in quick_set:
font = QFont(self.font())
font.setItalic(True)
font.setBold(True)
self.setItemData(idx, font, Qt.ItemDataRole.FontRole)
self.setItemData(
idx, self.palette().highlight().color(), Qt.ItemDataRole.ForegroundRole
)
tooltip = "Active profile (not in quick select)"
self.setItemData(idx, tooltip, Qt.ItemDataRole.ToolTipRole)
self.setCurrentIndex(idx)
continue
elif profile not in quick_set:
self.setItemData(idx, "Not in quick select", Qt.ItemDataRole.ToolTipRole)
if active_profile and profile == active_profile:
tooltip = "Active workspace profile"
if profile not in quick_set:
font = QFont(self.font())
font.setItalic(True)
font.setBold(True)
self.setItemData(idx, font, Qt.ItemDataRole.FontRole)
self.setItemData(
idx, self.palette().highlight().color(), Qt.ItemDataRole.ForegroundRole
)
tooltip = "Active profile (not in quick select)"
self.setItemData(idx, tooltip, Qt.ItemDataRole.ToolTipRole)
self.setCurrentIndex(idx)
elif profile not in quick_set:
self.setItemData(idx, "Not in quick select", Qt.ItemDataRole.ToolTipRole)
# Restore selection if possible
if show_empty_profile and active_profile is None:
empty_idx = self.findText("")
if empty_idx >= 0:
self.setCurrentIndex(empty_idx)
else:
index = self.findText(current_text)
if index >= 0:
self.setCurrentIndex(index)
# Restore selection if possible
if show_empty_profile and active_profile is None:
empty_idx = self.findText("")
if empty_idx >= 0:
self.setCurrentIndex(empty_idx)
else:
index = self.findText(current_text)
if index >= 0:
self.setCurrentIndex(index)
if active_profile and self.currentText() != active_profile:
idx = self.findText(active_profile)
if idx >= 0:
self.setCurrentIndex(idx)
if show_empty_profile and self.currentText() == "":
self.setToolTip("Unsaved empty workspace")
elif active_profile and active_profile not in quick_set:
self.setToolTip("Active profile is not in quick select")
else:
self.setToolTip("")
self.blockSignals(False)
if active_profile and self.currentText() != active_profile:
idx = self.findText(active_profile)
if idx >= 0:
self.setCurrentIndex(idx)
if show_empty_profile and self.currentText() == "":
self.setToolTip("Unsaved empty workspace")
elif active_profile and active_profile not in quick_set:
self.setToolTip("Active profile is not in quick select")
else:
self.setToolTip("")
finally:
self.blockSignals(was_blocked)
def workspace_bundle(components: ToolbarComponents, enable_tools: bool = True) -> ToolbarBundle: