From 35a7ed165fd2a50648cbb5d57e845236f0c0cfff Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Thu, 25 Sep 2025 00:43:04 +0200 Subject: [PATCH] BarSectionEditor: add search option (fixes #347) --- Assets/Translations/de.json | 3 ++- Assets/Translations/en.json | 3 ++- Assets/Translations/es.json | 3 ++- Assets/Translations/fr.json | 3 ++- Assets/Translations/pt.json | 3 ++- Modules/Settings/Bar/BarSectionEditor.qml | 15 ++++++++++++++- Widgets/NSearchableComboBox.qml | 9 ++++++++- 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Assets/Translations/de.json b/Assets/Translations/de.json index 589ea73e..34dd4840 100644 --- a/Assets/Translations/de.json +++ b/Assets/Translations/de.json @@ -746,7 +746,8 @@ "apply": "Anwenden" }, "section-editor": { - "placeholder": "Widget auswählen..." + "placeholder": "Widget auswählen...", + "search-placeholder": "Widgets suchen..." }, "active-window": { "show-app-icon": "App-Symbol anzeigen" diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index c7770354..4a787dbf 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -758,7 +758,8 @@ "apply": "Apply" }, "section-editor": { - "placeholder": "Select a widget to add..." + "placeholder": "Select a widget to add...", + "search-placeholder": "Search widgets..." }, "active-window": { "show-app-icon": "Show app icon" diff --git a/Assets/Translations/es.json b/Assets/Translations/es.json index 071298cf..bad22775 100644 --- a/Assets/Translations/es.json +++ b/Assets/Translations/es.json @@ -756,7 +756,8 @@ "apply": "Aplicar" }, "section-editor": { - "placeholder": "Selecciona un widget para añadir..." + "placeholder": "Selecciona un widget para añadir...", + "search-placeholder": "Buscar widgets..." }, "active-window": { "show-app-icon": "Mostrar icono de la aplicación" diff --git a/Assets/Translations/fr.json b/Assets/Translations/fr.json index a0a704d4..2915fed1 100644 --- a/Assets/Translations/fr.json +++ b/Assets/Translations/fr.json @@ -754,7 +754,8 @@ "apply": "Appliquer" }, "section-editor": { - "placeholder": "Sélectionnez un widget à ajouter..." + "placeholder": "Sélectionnez un widget à ajouter...", + "search-placeholder": "Rechercher des widgets..." }, "active-window": { "show-app-icon": "Afficher l'icône de l'application" diff --git a/Assets/Translations/pt.json b/Assets/Translations/pt.json index 9817bce2..86101c2b 100644 --- a/Assets/Translations/pt.json +++ b/Assets/Translations/pt.json @@ -756,7 +756,8 @@ "apply": "Aplicar" }, "section-editor": { - "placeholder": "Selecione um widget para adicionar..." + "placeholder": "Selecione um widget para adicionar...", + "search-placeholder": "Pesquisar widgets..." }, "active-window": { "show-app-icon": "Mostrar ícone do aplicativo" diff --git a/Modules/Settings/Bar/BarSectionEditor.qml b/Modules/Settings/Bar/BarSectionEditor.qml index 6e1fb69a..b1b9e10d 100644 --- a/Modules/Settings/Bar/BarSectionEditor.qml +++ b/Modules/Settings/Bar/BarSectionEditor.qml @@ -79,16 +79,29 @@ NBox { Item { Layout.fillWidth: true } - NComboBox { + NSearchableComboBox { id: comboBox model: availableWidgets label: "" description: "" placeholder: I18n.tr("bar.widget-settings.section-editor.placeholder") + searchPlaceholder: I18n.tr("bar.widget-settings.section-editor.search-placeholder") onSelected: key => comboBox.currentKey = key popupHeight: 340 * scaling + minimumWidth: 200 * scaling Layout.alignment: Qt.AlignVCenter + + // Re-filter when the model count changes (when widgets are loaded) + Connections { + target: availableWidgets + function onCountChanged() { + // Trigger a re-filter by clearing and re-setting the search text + var currentSearch = comboBox.searchText + comboBox.searchText = "" + comboBox.searchText = currentSearch + } + } } NIconButton { diff --git a/Widgets/NSearchableComboBox.qml b/Widgets/NSearchableComboBox.qml index be3f5e75..ed2fe374 100644 --- a/Widgets/NSearchableComboBox.qml +++ b/Widgets/NSearchableComboBox.qml @@ -53,6 +53,11 @@ RowLayout { function filterModel() { filteredModel.clear() + // Check if model exists and has items + if (!root.model || root.model.count === undefined || root.model.count === 0) { + return + } + if (searchText.trim() === "") { // If no search text, show all items for (var i = 0; i < root.model.count; i++) { @@ -242,11 +247,13 @@ RowLayout { } } - // Focus search input when popup opens + // Focus search input when popup opens and ensure model is filtered Connections { target: combo.popup function onVisibleChanged() { if (combo.popup.visible) { + // Ensure the model is filtered when popup opens + filterModel() // Small delay to ensure the popup is fully rendered Qt.callLater(function () { if (searchInput && searchInput.inputItem) {