Warning, /plasma-mobile/qmlkonsole/src/contents/ui/SavedCommandsSettings.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2020 Han Young <hanyoung@protonmail.com>
0002 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 import QtQuick
0007 import QtQuick.Controls
0008 import QtQuick.Layouts
0009 
0010 import org.kde.kirigami as Kirigami
0011 
0012 import org.kde.konsoleqml
0013 
0014 import org.kde.qmlkonsole
0015 
0016 Kirigami.ScrollablePage {
0017     id: root
0018     title: i18n("Saved Commands")
0019 
0020     property TerminalEmulator terminal
0021     property bool editMode: false
0022 
0023     actions: [
0024         Kirigami.Action {
0025             text: i18n("Add Command")
0026             icon.name: "contact-new"
0027             onTriggered: actionDialog.open()
0028         },
0029         Kirigami.Action {
0030             text: i18n("Edit")
0031             icon.name: 'entry-edit'
0032             checkable: true
0033             onCheckedChanged: root.editMode = checked
0034             visible: listView.count > 0
0035         }
0036     ]
0037 
0038     ListView {
0039         id: listView
0040         model: SavedCommandsModel
0041 
0042         Kirigami.PlaceholderMessage {
0043             anchors.verticalCenter: parent.verticalCenter
0044             anchors.left: parent.left
0045             anchors.right: parent.right
0046             anchors.leftMargin: Kirigami.Units.largeSpacing
0047             anchors.rightMargin: Kirigami.Units.largeSpacing
0048 
0049             visible: listView.count === 0
0050             icon.name: "dialog-scripts"
0051             text: i18n("No saved commands")
0052             explanation: i18n("Save commands to quickly run them without typing them out.")
0053 
0054             helpfulAction: Kirigami.Action {
0055                 icon.name: "list-add"
0056                 text: i18n("Add command")
0057                 onTriggered: actionDialog.open()
0058             }
0059         }
0060 
0061         delegate: Control {
0062             leftPadding: Kirigami.Units.largeSpacing
0063             rightPadding: Kirigami.Units.largeSpacing
0064             topPadding: Kirigami.Units.largeSpacing
0065             bottomPadding: Kirigami.Units.largeSpacing
0066             width: ListView.view.width
0067 
0068             contentItem: RowLayout {
0069                 id: row
0070 
0071                 Kirigami.Icon {
0072                     source: "dialog-scripts"
0073                 }
0074                 Label {
0075                     id: label
0076                     text: model.display
0077                     font.family: "Monospace"
0078                 }
0079                 Item {
0080                     Layout.fillWidth: true
0081                 }
0082                 ToolButton {
0083                     visible: root.editMode
0084                     icon.name: 'delete'
0085                     onClicked: {
0086                         SavedCommandsModel.removeRow(index);
0087                         showPassiveNotification(i18n("Command %1 removed", label.text));
0088                     }
0089                 }
0090             }
0091         }
0092     }
0093 
0094     Kirigami.PromptDialog {
0095         id: actionDialog
0096         title: i18n("Add Command")
0097         preferredWidth: Kirigami.Units.gridUnit * 30
0098         padding: Kirigami.Units.largeSpacing
0099         standardButtons: Dialog.Save | Dialog.Cancel
0100 
0101         onAccepted: {
0102             if (textField.text != "") {
0103                 SavedCommandsModel.addAction(textField.text);
0104                 textField.text = ""
0105             }
0106 
0107             actionDialog.close();
0108         }
0109 
0110         contentItem: RowLayout {
0111             TextField {
0112                 id: textField
0113                 font.family: "Monospace"
0114                 Layout.fillWidth: true
0115             }
0116         }
0117     }
0118 }