feat(settings): Add usage badges to widget selector

Adds a visual indicator to the "Add Widget" dropdown in the Bar
settings panel to show which widgets are already in use and where.

- A small text badge ("L", "C", "R") now appears next to any widget
  that is already on a panel.
- The badges are reactive and update automatically when widgets are
  added or removed.
- This helps prevent accidental duplicate additions and makes widget
  management easier.
This commit is contained in:
loner
2025-10-14 03:40:51 +08:00
parent 158d3a1e63
commit 679224e1d9
4 changed files with 112 additions and 40 deletions
@@ -83,6 +83,7 @@ NBox {
Item {
Layout.fillWidth: true
}
NSearchableComboBox {
id: comboBox
model: availableWidgets
+40 -10
View File
@@ -300,9 +300,7 @@ ColumnLayout {
Layout.bottomMargin: Style.marginXL
}
// ---------------------------------
// Signal functions
// ---------------------------------
function _addWidgetToSection(widgetId, section) {
var newWidget = {
"id": widgetId
@@ -372,19 +370,51 @@ ColumnLayout {
}
}
// Data model functions
function getWidgetLocations(widgetId) {
if (!BarService)
return []
const instances = BarService.getAllRegisteredWidgets()
const locations = {}
for (var i = 0; i < instances.length; i++) {
if (instances[i].widgetId === widgetId) {
const section = instances[i].section
if (section === "left")
locations["L"] = true
else if (section === "center")
locations["C"] = true
else if (section === "right")
locations["R"] = true
}
}
return Object.keys(locations).join('')
}
function updateAvailableWidgetsModel() {
availableWidgets.clear()
const widgets = BarWidgetRegistry.getAvailableWidgets()
widgets.forEach(entry => {
availableWidgets.append({
"key": entry,
"name": entry,
"badgeLocations": getWidgetLocations(entry)
})
})
}
// Base list model for all combo boxes
ListModel {
id: availableWidgets
}
Component.onCompleted: {
// Fill out availableWidgets ListModel
availableWidgets.clear()
BarWidgetRegistry.getAvailableWidgets().forEach(entry => {
availableWidgets.append({
"key": entry,
"name": entry
})
})
updateAvailableWidgetsModel()
}
Connections {
target: BarService
function onActiveWidgetsChanged() {
updateAvailableWidgetsModel()
}
}
}