Warning, /office/klevernotes/src/contents/ui/dialogs/NamingDialog.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2022 Louis Schul <schul9louis@gmail.com> 0003 0004 import QtQuick 2.15 0005 0006 import org.kde.kirigami 2.19 as Kirigami 0007 import org.kde.kirigamiaddons.formcard 1.0 as FormCard 0008 0009 import org.kde.Klever 1.0 0010 0011 Kirigami.PromptDialog { 0012 id: textPromptDialog 0013 0014 readonly property QtObject nameField: nameField 0015 0016 property bool newItem 0017 property string useCase 0018 property string shownName 0019 property string parentPath 0020 property QtObject callingAction 0021 property alias textFieldText: nameField.text 0022 0023 title: i18nc("@title:dialog", "Choose a name") 0024 0025 standardButtons: Kirigami.Dialog.Apply | Kirigami.Dialog.Cancel 0026 0027 onApplied: { 0028 const error = checkName() 0029 if (error === "") { 0030 textPromptDialog.close() 0031 callingAction.name = nameField.text.trim() 0032 return 0033 } 0034 throwError(error) 0035 nameField.forceActiveFocus() 0036 } 0037 onOpened: { 0038 nameField.forceActiveFocus() 0039 } 0040 onRejected: { 0041 callingAction.isActive = false 0042 } 0043 0044 FormCard.FormTextFieldDelegate { 0045 id: nameField 0046 0047 label: i18nc("As in 'a name'", "Name:") 0048 text: shownName 0049 maximumLength: 40 0050 0051 leftPadding: Kirigami.Units.largeSpacing 0052 rightPadding: Kirigami.Units.largeSpacing 0053 0054 Keys.onPressed: function(event) { 0055 if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { 0056 textPromptDialog.applied() 0057 } 0058 } 0059 } 0060 0061 function throwError(error) { 0062 let component = Qt.createComponent("qrc:/contents/ui/dialogs/NamingErrorDialog.qml") 0063 0064 if (component.status == Component.Ready) { 0065 var dialog = component.createObject(textPromptDialog); 0066 dialog.error = error 0067 dialog.useCase = useCase 0068 dialog.nameField = nameField 0069 dialog.open() 0070 } 0071 } 0072 0073 function checkName() { 0074 // The user just pressed apply without renaming the object 0075 if (textFieldText === shownName && !textPromptDialog.newItem) return "" 0076 0077 const name = textFieldText.trim() 0078 const error = KleverUtility.isProperPath(parentPath,name) 0079 if (error !== "") return error 0080 0081 if (name === Config.categoryDisplayName) return "exist" 0082 0083 return "" 0084 } 0085 }