mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-10-30 06:34:16 +00:00 
			
		
		
		
	Fix 27 : profile name is now validated.
This commit is contained in:
		| @@ -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,18 +66,31 @@ 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); | ||||
|                 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{ | ||||
|                 text: qsTr("Cancel") | ||||
|                 onClicked: close() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user