Verified Commit be5f636c authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/dict: support multiple dictionaries in the config dialog

Multiple dictionaries are saved in a string, split with comma ",".

FEATURE: 453878
FIXED-IN: 5.26
parent 988bcc37
Pipeline #180941 passed with stage
in 1 minute and 21 seconds
/*
SPDX-FileCopyrightText: 2013 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.20 as Kirigami
import org.kde.plasma.core 2.0 as PlasmaCore
Kirigami.OverlaySheet {
id: sheet
readonly property alias view: sheetListView
onSheetOpenChanged: {
if (sheetOpen) {
filter.text = "";
filter.forceActiveFocus()
}
}
// Need to manually set the parent when using this in a Plasma config dialog
parent: sheet.parent.parent
header: ColumnLayout {
Layout.preferredWidth: sheetListView.implicitWidth
Kirigami.Heading {
Layout.fillWidth: true
text: i18n("Add More Dictionaries")
wrapMode: Text.Wrap
}
Kirigami.SearchField {
id: filter
Layout.fillWidth: true
}
}
footer: QQC2.DialogButtonBox {
standardButtons: QQC2.DialogButtonBox.Ok
onAccepted: sheet.close()
}
ListView {
id: sheetListView
focus: true // keyboard navigation
activeFocusOnTab: true // keyboard navigation
implicitWidth: Kirigami.Units.gridUnit * 25
reuseItems: true
model: PlasmaCore.SortFilterModel {
sourceModel: dictionariesModel
filterRole: "EditRole" // id
filterRegExp: filter.text
}
delegate: QQC2.CheckDelegate {
id: checkbox
width: sheetListView.width
focus: true // keyboard navigation
text: `${model.id} (${model.description})`
checked: model.checked
onToggled: {
model.checked = checked;
sheetListView.currentIndex = index; // highlight
sheetListView.forceActiveFocus(); // keyboard navigation
}
highlighted: ListView.isCurrentItem
}
}
}
......@@ -6,10 +6,11 @@
import QtQuick 2.15
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.19 as Kirigami
import org.kde.plasma.private.dict 1.0
Page {
ColumnLayout {
id: page
property string cfg_dictionary: ""
......@@ -18,67 +19,100 @@ Page {
DictionariesModel {
id: dictionariesModel
Component.onCompleted: enabledDicts = cfg_dictionary
onEnabledDictsChanged: cfg_dictionary = enabledDicts
}
ScrollView {
anchors.fill: parent
Component.onCompleted: background.visible = true;
AvailableDictSheet {
id: sheet
}
ListView {
id: listView
model: dictionariesModel
reuseItems: true
Item {
Layout.fillWidth: true
Layout.fillHeight: true
section {
criteria: ViewSection.FirstCharacter
property: "id"
delegate: Kirigami.ListSectionHeader {
label: section
}
}
ScrollView {
anchors.fill: parent
Component.onCompleted: background.visible = true;
delegate: Kirigami.BasicListItem {
width: listView.width
ListView {
id: listView
bold: page.cfg_dictionary == model.id
highlighted: bold
model: dictionariesModel.enabledDictModel
reuseItems: true
icon: undefined
displaced: Transition {
NumberAnimation {
properties: "y"
duration: Kirigami.Units.longDuration
}
}
label: model.id
subtitle: model.description
delegate: DictItemDelegate {
width: listView.width
view: listView
onClicked: page.cfg_dictionary = model.id
onMoveRequested: {
dictionariesModel.move(oldIndex, newIndex);
}
onRemoved: {
dictionariesModel.setDisabled(index);
}
}
}
}
}
Loader {
active: dictionariesModel.loading || listView.count === 0
asynchronous: true
Loader {
active: dictionariesModel.loading || sheet.view.count === 0 || listView.count === 0
asynchronous: true
anchors.centerIn: parent
visible: active
sourceComponent: dictionariesModel.loading ? loadingPlaceHolder : (sheet.view.count === 0 ? errorPlaceHolder : emptyPlaceholder)
anchors.centerIn: parent
visible: active
Component {
id: loadingPlaceHolder
sourceComponent: dictionariesModel.loading ? loadingPlaceHolder : errorPlaceHolder
Kirigami.LoadingPlaceholder {
anchors.centerIn: parent
}
}
Component {
id: errorPlaceHolder
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: root.width - (Kirigami.Units.largeSpacing * 4)
icon.name: "network-disconnect"
text: i18n("Unable to load dictionary list")
explanation: i18nc("%2 human-readable error string", "Error code: %1 (%2)", dictionariesModel.errorCode, dictionariesModel.errorString)
}
}
Component {
id: loadingPlaceHolder
Component {
id: emptyPlaceholder
Kirigami.LoadingPlaceholder {
anchors.centerIn: parent
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: root.width - (Kirigami.Units.largeSpacing * 4)
icon.name: "edit-none"
text: i18n("No dictionaries")
}
}
}
}
Component {
id: errorPlaceHolder
RowLayout {
Layout.fillWidth: true
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: root.width - (Kirigami.Units.largeSpacing * 4)
icon.name: "network-disconnect"
text: i18n("Unable to load dictionary list")
explanation: i18nc("%2 human-readable error string", "Error code: %1 (%2)", dictionariesModel.errorCode, dictionariesModel.errorString)
Button {
enabled: sheet.view.count > 0
text: i18n("Add More…")
icon.name: "list-add"
onClicked: {
sheet.open();
}
}
}
......
/*
SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com>
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.20 as Kirigami
// External item required to make Kirigami.ListItemDragHandle work
Item {
id: delegate
property ListView view
implicitHeight : dictItem.implicitHeight
signal removed(int index)
signal moveRequested(int oldIndex, int newIndex)
Kirigami.SwipeListItem {
id: dictItem
hoverEnabled: false
RowLayout {
Kirigami.ListItemDragHandle {
listItem: dictItem
listView: delegate.view
onMoveRequested: {
delegate.moveRequested(oldIndex, newIndex);
}
}
Kirigami.BasicListItem {
Layout.fillWidth: true
hoverEnabled: false
separatorVisible: false
label: model.id
subtitle: model.description
}
}
actions: [
Kirigami.Action {
text: i18n("Delete")
iconName: "entry-delete"
onTriggered: {
delegate.removed(index);
}
}
]
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment