cool-retro-term
93 строки · 2.8 Кб
1/*******************************************************************************
2* Copyright (c) 2013-2021 "Filippo Scognamiglio"
3* https://github.com/Swordfish90/cool-retro-term
4*
5* This file is part of cool-retro-term.
6*
7* cool-retro-term is free software: you can redistribute it and/or modify
8* it under the terms of the GNU General Public License as published by
9* the Free Software Foundation, either version 3 of the License, or
10* (at your option) any later version.
11*
12* This program is distributed in the hope that it will be useful,
13* but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15* GNU General Public License for more details.
16*
17* You should have received a copy of the GNU General Public License
18* along with this program. If not, see <http://www.gnu.org/licenses/>.
19*******************************************************************************/
20import QtQuick 2.2
21import QtQuick.Window 2.0
22import QtQuick.Controls 2.0
23import QtQuick.Layouts 1.1
24import QtQuick.Dialogs 1.1
25
26Window {
27id: insertnamedialog
28width: 400
29height: 100
30modality: Qt.ApplicationModal
31title: qsTr("Save new profile")
32
33property alias profileName: namefield.text
34signal nameSelected(string name)
35
36MessageDialog {
37id: errorDialog
38title: qsTr("Error")
39visible: false
40
41function showError(message) {
42text = message
43open()
44}
45}
46
47function validateName(name) {
48var profile_list = appSettings.profilesList
49if (name === "")
50return 1
51return 0
52}
53
54ColumnLayout {
55anchors.margins: 10
56anchors.fill: parent
57RowLayout {
58Label {
59text: qsTr("Name")
60}
61TextField {
62id: namefield
63Layout.fillWidth: true
64Component.onCompleted: forceActiveFocus()
65onAccepted: okbutton.clickAction()
66}
67}
68RowLayout {
69Layout.alignment: Qt.AlignBottom | Qt.AlignRight
70Button {
71id: okbutton
72text: qsTr("OK")
73onClicked: clickAction()
74function clickAction() {
75var name = namefield.text
76switch (validateName(name)) {
77case 1:
78errorDialog.showError(
79qsTr("The name you inserted is empty. Please choose a different one."))
80break
81default:
82nameSelected(name)
83close()
84}
85}
86}
87Button {
88text: qsTr("Cancel")
89onClicked: close()
90}
91}
92}
93}
94