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.Window 2.0 | ||||||
| import QtQuick.Controls 1.1 | import QtQuick.Controls 1.1 | ||||||
| import QtQuick.Layouts 1.1 | import QtQuick.Layouts 1.1 | ||||||
|  | import QtQuick.Dialogs 1.1 | ||||||
|  |  | ||||||
| Window{ | Window{ | ||||||
|     id: insertnamedialog |     id: insertnamedialog | ||||||
|     width: 400 |     width: 400 | ||||||
|     height: 100 |     height: 100 | ||||||
|     modality: Qt.ApplicationModal |     modality: Qt.ApplicationModal | ||||||
|     title: qsTr("Save current profile") |     title: qsTr("Save new profile") | ||||||
|  |  | ||||||
|     signal nameSelected(string name) |     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{ |     ColumnLayout{ | ||||||
|         anchors.margins: 10 |         anchors.margins: 10 | ||||||
|         anchors.fill: parent |         anchors.fill: parent | ||||||
| @@ -41,16 +66,29 @@ Window{ | |||||||
|                 id: namefield |                 id: namefield | ||||||
|                 Layout.fillWidth: true |                 Layout.fillWidth: true | ||||||
|                 Component.onCompleted: forceActiveFocus() |                 Component.onCompleted: forceActiveFocus() | ||||||
|  |                 onAccepted: okbutton.clickAction() | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         RowLayout{ |         RowLayout{ | ||||||
|             anchors.right: parent.right |             anchors.right: parent.right | ||||||
|             anchors.bottom: parent.bottom |             anchors.bottom: parent.bottom | ||||||
|             Button{ |             Button{ | ||||||
|  |                 id: okbutton | ||||||
|                 text: qsTr("OK") |                 text: qsTr("OK") | ||||||
|                 onClicked: { |                 onClicked: clickAction() | ||||||
|                     nameSelected(namefield.text); |                 function clickAction(){ | ||||||
|                     close(); |                     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{ |             Button{ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user