You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Fix GDScript translation parser for FileDialog.add_filter() two-parameter format
The parser only handled the single-parameter semicolon format and thew an error with two-parameter format. This fix supports both formats. Co-authored-by: Danil Alexeev <dalexeev12@yandex.ru>
This commit is contained in:
@@ -383,9 +383,14 @@ void GDScriptEditorTranslationParserPlugin::_assess_call(const GDScriptParser::C
|
|||||||
_add_id(p_call->arguments[1]->reduced_value, p_call->arguments[1]->start_line);
|
_add_id(p_call->arguments[1]->reduced_value, p_call->arguments[1]->start_line);
|
||||||
}
|
}
|
||||||
} else if (function_name == fd_add_filter) {
|
} else if (function_name == fd_add_filter) {
|
||||||
// Extract the 'JPE Images' in this example - get_node("FileDialog").add_filter("*.jpg; JPE Images").
|
if (p_call->arguments.size() == 1) {
|
||||||
if (!p_call->arguments.is_empty()) {
|
// The first parameter may contain a description, like `"*.jpg; JPEG Images"`.
|
||||||
_extract_fd_filter_string(p_call->arguments[0], p_call->arguments[0]->start_line);
|
_extract_fd_filter_string(p_call->arguments[0], p_call->arguments[0]->start_line);
|
||||||
|
} else if (p_call->arguments.size() >= 2) {
|
||||||
|
// The second optional parameter can be a description.
|
||||||
|
if (_is_constant_string(p_call->arguments[1])) {
|
||||||
|
_add_id(p_call->arguments[1]->reduced_value, p_call->arguments[1]->start_line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (function_name == fd_set_filter) {
|
} else if (function_name == fd_set_filter) {
|
||||||
// Extract from `get_node("FileDialog").set_filters(<filter array>)`.
|
// Extract from `get_node("FileDialog").set_filters(<filter array>)`.
|
||||||
@@ -396,11 +401,16 @@ void GDScriptEditorTranslationParserPlugin::_assess_call(const GDScriptParser::C
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptEditorTranslationParserPlugin::_extract_fd_filter_string(const GDScriptParser::ExpressionNode *p_expression, int p_line) {
|
void GDScriptEditorTranslationParserPlugin::_extract_fd_filter_string(const GDScriptParser::ExpressionNode *p_expression, int p_line) {
|
||||||
// Extract the name in "extension ; name".
|
// Extract the description from `"filter; Description"` format.
|
||||||
|
// The description part is optional, so we skip if it's missing or empty.
|
||||||
if (_is_constant_string(p_expression)) {
|
if (_is_constant_string(p_expression)) {
|
||||||
PackedStringArray arr = p_expression->reduced_value.operator String().split(";", true);
|
const PackedStringArray arr = p_expression->reduced_value.operator String().split(";", true, 1);
|
||||||
ERR_FAIL_COND_MSG(arr.size() != 2, "Argument for setting FileDialog has bad format.");
|
if (arr.size() >= 2) {
|
||||||
_add_id(arr[1].strip_edges(), p_line);
|
const String description = arr[1].strip_edges();
|
||||||
|
if (!description.is_empty()) {
|
||||||
|
_add_id(description, p_line);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user