cool-retro-term

Форк
0
/
InsertNameDialog.qml 
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
*******************************************************************************/
20
import QtQuick 2.2
21
import QtQuick.Window 2.0
22
import QtQuick.Controls 2.0
23
import QtQuick.Layouts 1.1
24
import QtQuick.Dialogs 1.1
25

26
Window {
27
    id: insertnamedialog
28
    width: 400
29
    height: 100
30
    modality: Qt.ApplicationModal
31
    title: qsTr("Save new profile")
32

33
    property alias profileName: namefield.text
34
    signal nameSelected(string name)
35

36
    MessageDialog {
37
        id: errorDialog
38
        title: qsTr("Error")
39
        visible: false
40

41
        function showError(message) {
42
            text = message
43
            open()
44
        }
45
    }
46

47
    function validateName(name) {
48
        var profile_list = appSettings.profilesList
49
        if (name === "")
50
            return 1
51
        return 0
52
    }
53

54
    ColumnLayout {
55
        anchors.margins: 10
56
        anchors.fill: parent
57
        RowLayout {
58
            Label {
59
                text: qsTr("Name")
60
            }
61
            TextField {
62
                id: namefield
63
                Layout.fillWidth: true
64
                Component.onCompleted: forceActiveFocus()
65
                onAccepted: okbutton.clickAction()
66
            }
67
        }
68
        RowLayout {
69
            Layout.alignment: Qt.AlignBottom | Qt.AlignRight
70
            Button {
71
                id: okbutton
72
                text: qsTr("OK")
73
                onClicked: clickAction()
74
                function clickAction() {
75
                    var name = namefield.text
76
                    switch (validateName(name)) {
77
                    case 1:
78
                        errorDialog.showError(
79
                                    qsTr("The name you inserted is empty. Please choose a different one."))
80
                        break
81
                    default:
82
                        nameSelected(name)
83
                        close()
84
                    }
85
                }
86
            }
87
            Button {
88
                text: qsTr("Cancel")
89
                onClicked: close()
90
            }
91
        }
92
    }
93
}
94

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.