mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
NSettingsIndicator: add default setting indicator (#1080)
N*Widgets: show NSettingsIndicator if settings are not default
This commit is contained in:
@@ -18,6 +18,9 @@ RowLayout {
|
||||
property string placeholder: ""
|
||||
property string searchPlaceholder: I18n.tr("placeholders.search")
|
||||
property Component delegate: null
|
||||
property bool isSettings: false
|
||||
property var defaultValue: ""
|
||||
property string settingsPath: ""
|
||||
|
||||
readonly property real preferredHeight: Style.baseWidgetSize * 1.1
|
||||
|
||||
@@ -26,6 +29,49 @@ RowLayout {
|
||||
spacing: Style.marginL
|
||||
Layout.fillWidth: true
|
||||
|
||||
readonly property bool isValueChanged: isSettings && (currentKey !== defaultValue)
|
||||
readonly property string indicatorTooltip: {
|
||||
if (!isSettings) return "";
|
||||
var displayValue = "";
|
||||
if (defaultValue === "") {
|
||||
// Try to find the display name for empty key in the model
|
||||
if (model && model.count > 0) {
|
||||
for (var i = 0; i < model.count; i++) {
|
||||
var item = model.get(i);
|
||||
if (item && item.key === "") {
|
||||
displayValue = item.name || I18n.tr("settings.indicator.system-default");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If not found in model, show "System Default" instead of "(empty)"
|
||||
if (displayValue === "") {
|
||||
displayValue = I18n.tr("settings.indicator.system-default");
|
||||
}
|
||||
} else {
|
||||
displayValue = I18n.tr("settings.indicator.system-default");
|
||||
}
|
||||
} else {
|
||||
// Try to find the display name for the default key in the model
|
||||
if (model && model.count > 0) {
|
||||
for (var i = 0; i < model.count; i++) {
|
||||
var item = model.get(i);
|
||||
if (item && item.key === defaultValue) {
|
||||
displayValue = item.name || String(defaultValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (displayValue === "") {
|
||||
displayValue = String(defaultValue);
|
||||
}
|
||||
} else {
|
||||
displayValue = String(defaultValue);
|
||||
}
|
||||
}
|
||||
return I18n.tr("settings.indicator.default-value", {
|
||||
"value": displayValue
|
||||
});
|
||||
}
|
||||
|
||||
// Filtered model for search results
|
||||
property ListModel filteredModel: ListModel {}
|
||||
property string searchText: ""
|
||||
@@ -113,6 +159,8 @@ RowLayout {
|
||||
NLabel {
|
||||
label: root.label
|
||||
description: root.description
|
||||
showIndicator: root.isSettings && root.isValueChanged
|
||||
indicatorTooltip: root.indicatorTooltip
|
||||
}
|
||||
|
||||
Item {
|
||||
@@ -339,4 +387,5 @@ RowLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user