mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-07 20:31:31 +00:00
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:
@@ -83,6 +83,7 @@ NBox {
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
NSearchableComboBox {
|
||||
id: comboBox
|
||||
model: availableWidgets
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user