1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-01-31 02:01:19 +00:00

Fix 27 : profile name is now validated.

This commit is contained in:
Filippo Scognamiglio 2014-08-04 01:46:07 +02:00
parent 3d5ee0ec70
commit 1cd41ce0b9

View File

@ -22,16 +22,41 @@ import QtQuick 2.2
import QtQuick.Window 2.0
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.1
Window{
id: insertnamedialog
width: 400
height: 100
modality: Qt.ApplicationModal
title: qsTr("Save current profile")
title: qsTr("Save new profile")
signal nameSelected(string name)
MessageDialog {
id: errorDialog
title: qsTr("Error")
visible: false
function showError(message){
text = message;
open();
}
}
function validateName(name){
var profile_list = shadersettings.profiles_list;
if (name === "")
return 1;
for (var i = 0; i < profile_list.count; i++){
if(profile_list.get(i).text === name)
return 2;
}
return 0;
}
ColumnLayout{
anchors.margins: 10
anchors.fill: parent
@ -41,16 +66,29 @@ Window{
id: namefield
Layout.fillWidth: true
Component.onCompleted: forceActiveFocus()
onAccepted: okbutton.clickAction()
}
}
RowLayout{
anchors.right: parent.right
anchors.bottom: parent.bottom
Button{
id: okbutton
text: qsTr("OK")
onClicked: {
nameSelected(namefield.text);
close();
onClicked: clickAction()
function clickAction(){
var name = namefield.text;
switch(validateName(name)){
case 1:
errorDialog.showError(qsTr("The name you inserted is empty. Please choose a different one."));
break;
case 2:
errorDialog.showError(qsTr("The name you inserted already exists. Please choose a different one."));
break;
default:
nameSelected(name);
close();
}
}
}
Button{