mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 13:41:03 +00:00 
			
		
		
		
	Improve path validation in ScriptCreateDialog
This commit is contained in:
		
							parent
							
								
									15ff450680
								
							
						
					
					
						commit
						a1ef1aae2b
					
				
					 2 changed files with 11 additions and 7 deletions
				
			
		|  | @ -216,7 +216,7 @@ bool ScriptCreateDialog::_validate_parent(const String &p_string) { | ||||||
| 
 | 
 | ||||||
| 	if (can_inherit_from_file && p_string.is_quoted()) { | 	if (can_inherit_from_file && p_string.is_quoted()) { | ||||||
| 		String p = p_string.substr(1, p_string.length() - 2); | 		String p = p_string.substr(1, p_string.length() - 2); | ||||||
| 		if (_validate_path(p, true) == "") { | 		if (_validate_path(p, true).is_empty()) { | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | @ -224,8 +224,11 @@ bool ScriptCreateDialog::_validate_parent(const String &p_string) { | ||||||
| 	return EditorNode::get_editor_data().is_type_recognized(p_string); | 	return EditorNode::get_editor_data().is_type_recognized(p_string); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist) { | String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist, bool *r_path_valid) { | ||||||
| 	String p = p_path.strip_edges(); | 	String p = p_path.strip_edges(); | ||||||
|  | 	if (r_path_valid) { | ||||||
|  | 		*r_path_valid = false; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	if (p.is_empty()) { | 	if (p.is_empty()) { | ||||||
| 		return TTR("Path is empty."); | 		return TTR("Path is empty."); | ||||||
|  | @ -263,6 +266,10 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if (r_path_valid) { | ||||||
|  | 		*r_path_valid = true; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// Check file extension.
 | 	// Check file extension.
 | ||||||
| 	String extension = p.get_extension(); | 	String extension = p.get_extension(); | ||||||
| 	List<String> extensions; | 	List<String> extensions; | ||||||
|  | @ -491,10 +498,9 @@ void ScriptCreateDialog::_path_changed(const String &p_path) { | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	is_path_valid = false; |  | ||||||
| 	is_new_script_created = true; | 	is_new_script_created = true; | ||||||
| 
 | 
 | ||||||
| 	path_error = _validate_path(p_path, false); | 	path_error = _validate_path(p_path, false, &is_path_valid); | ||||||
| 	if (!path_error.is_empty()) { | 	if (!path_error.is_empty()) { | ||||||
| 		validation_panel->update(); | 		validation_panel->update(); | ||||||
| 		return; | 		return; | ||||||
|  | @ -506,8 +512,6 @@ void ScriptCreateDialog::_path_changed(const String &p_path) { | ||||||
| 	if (da->file_exists(p)) { | 	if (da->file_exists(p)) { | ||||||
| 		is_new_script_created = false; | 		is_new_script_created = false; | ||||||
| 	} | 	} | ||||||
| 
 |  | ||||||
| 	is_path_valid = true; |  | ||||||
| 	validation_panel->update(); | 	validation_panel->update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -99,7 +99,7 @@ class ScriptCreateDialog : public ConfirmationDialog { | ||||||
| 	void _built_in_pressed(); | 	void _built_in_pressed(); | ||||||
| 	void _use_template_pressed(); | 	void _use_template_pressed(); | ||||||
| 	bool _validate_parent(const String &p_string); | 	bool _validate_parent(const String &p_string); | ||||||
| 	String _validate_path(const String &p_path, bool p_file_must_exist); | 	String _validate_path(const String &p_path, bool p_file_must_exist, bool *r_path_valid = nullptr); | ||||||
| 	void _parent_name_changed(const String &p_parent); | 	void _parent_name_changed(const String &p_parent); | ||||||
| 	void _template_changed(int p_template = 0); | 	void _template_changed(int p_template = 0); | ||||||
| 	void _browse_path(bool browse_parent, bool p_save); | 	void _browse_path(bool browse_parent, bool p_save); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 kobewi
						kobewi