mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-01 01:59:47 +00:00
NComboBox: fix other languages display
Translations/de: update accordingly
This commit is contained in:
+39
-13
@@ -13,9 +13,7 @@ RowLayout {
|
||||
|
||||
property string label: ""
|
||||
property string description: ""
|
||||
property ListModel model: {
|
||||
|
||||
}
|
||||
property var model
|
||||
property string currentKey: ""
|
||||
property string placeholder: ""
|
||||
|
||||
@@ -26,11 +24,31 @@ RowLayout {
|
||||
spacing: Style.marginL * scaling
|
||||
Layout.fillWidth: true
|
||||
|
||||
function itemCount() {
|
||||
if (!root.model)
|
||||
return 0
|
||||
if (typeof root.model.count === 'number')
|
||||
return root.model.count
|
||||
if (Array.isArray(root.model))
|
||||
return root.model.length
|
||||
return 0
|
||||
}
|
||||
|
||||
function getItem(index) {
|
||||
if (!root.model)
|
||||
return null
|
||||
if (typeof root.model.get === 'function')
|
||||
return root.model.get(index)
|
||||
if (Array.isArray(root.model))
|
||||
return root.model[index]
|
||||
return null
|
||||
}
|
||||
|
||||
function findIndexByKey(key) {
|
||||
for (var i = 0; i < root.model.count; i++) {
|
||||
if (root.model.get(i).key === key) {
|
||||
for (var i = 0; i < itemCount(); i++) {
|
||||
var item = getItem(i)
|
||||
if (item && item.key === key)
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
@@ -48,7 +66,9 @@ RowLayout {
|
||||
model: model
|
||||
currentIndex: findIndexByKey(currentKey)
|
||||
onActivated: {
|
||||
root.selected(model.get(combo.currentIndex).key)
|
||||
var item = getItem(combo.currentIndex)
|
||||
if (item && item.key !== undefined)
|
||||
root.selected(item.key)
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
@@ -72,8 +92,8 @@ RowLayout {
|
||||
font.pointSize: Style.fontSizeM * scaling
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
elide: Text.ElideRight
|
||||
color: (combo.currentIndex >= 0 && combo.currentIndex < root.model.count) ? Color.mOnSurface : Color.mOnSurfaceVariant
|
||||
text: (combo.currentIndex >= 0 && combo.currentIndex < root.model.count) ? root.model.get(combo.currentIndex).name : root.placeholder
|
||||
color: (combo.currentIndex >= 0 && combo.currentIndex < itemCount()) ? Color.mOnSurface : Color.mOnSurfaceVariant
|
||||
text: (combo.currentIndex >= 0 && combo.currentIndex < itemCount()) ? (getItem(combo.currentIndex) ? getItem(combo.currentIndex).name : root.placeholder) : root.placeholder
|
||||
}
|
||||
|
||||
indicator: NIcon {
|
||||
@@ -115,9 +135,12 @@ RowLayout {
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
root.selected(root.model.get(index).key)
|
||||
combo.currentIndex = index
|
||||
combo.popup.close()
|
||||
var item = root.getItem(index)
|
||||
if (item && item.key !== undefined) {
|
||||
root.selected(item.key)
|
||||
combo.currentIndex = index
|
||||
combo.popup.close()
|
||||
}
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
@@ -132,7 +155,10 @@ RowLayout {
|
||||
}
|
||||
|
||||
contentItem: NText {
|
||||
text: name
|
||||
text: (function () {
|
||||
var item = root.getItem(index)
|
||||
return item && item.name ? item.name : ""
|
||||
})()
|
||||
font.pointSize: Style.fontSizeM * scaling
|
||||
color: highlighted ? Color.mOnTertiary : Color.mOnSurface
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
|
||||
Reference in New Issue
Block a user