Skip to content

Commit 42249bb

Browse files
committed
Add @export_file_path to export raw paths (no UID)
1 parent 4a44078 commit 42249bb

File tree

14 files changed

+37
-20
lines changed

14 files changed

+37
-20
lines changed

core/core_constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ void register_global_constants() {
680680
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_ONESHOT);
681681
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_GROUP_ENABLE);
682682
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_INPUT_NAME);
683+
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_FILE_PATH);
683684
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_MAX);
684685

685686
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_NONE);

core/object/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ enum PropertyHint {
9595
PROPERTY_HINT_NO_NODEPATH, /// < this property will not contain a NodePath, regardless of type (Array, Dictionary, List, etc.). Needed for SceneTreeDock.
9696
PROPERTY_HINT_GROUP_ENABLE, ///< used to make the property's group checkable. Only use for boolean types.
9797
PROPERTY_HINT_INPUT_NAME,
98+
PROPERTY_HINT_FILE_PATH,
9899
PROPERTY_HINT_MAX,
99100
};
100101

doc/classes/@GlobalScope.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,7 @@
28172817
Hints that an integer property is a bitmask using the optionally named avoidance layers.
28182818
</constant>
28192819
<constant name="PROPERTY_HINT_FILE" value="13" enum="PropertyHint">
2820-
Hints that a [String] property is a path to a file. Editing it will show a file dialog for picking the path. The hint string can be a set of filters with wildcards like [code]"*.png,*.jpg"[/code].
2820+
Hints that a [String] property is a path to a file. Editing it will show a file dialog for picking the path. The hint string can be a set of filters with wildcards like [code]"*.png,*.jpg"[/code]. By default the file will be stored as UID whenever available. You can use [ResourceUID] methods to convert it back to path. For storing a raw path, use [constant PROPERTY_HINT_FILE_PATH].
28212821
</constant>
28222822
<constant name="PROPERTY_HINT_DIR" value="14" enum="PropertyHint">
28232823
Hints that a [String] property is a path to a directory. Editing it will show a file dialog for picking the path.
@@ -2965,7 +2965,10 @@
29652965
- If it contains [code]"show_builtin"[/code], built-in input actions are included in the selection.
29662966
- If it contains [code]"loose_mode"[/code], loose mode is enabled. This allows inserting any action name even if it's not present in the input map.
29672967
</constant>
2968-
<constant name="PROPERTY_HINT_MAX" value="44" enum="PropertyHint">
2968+
<constant name="PROPERTY_HINT_FILE_PATH" value="44" enum="PropertyHint">
2969+
Like [constant PROPERTY_HINT_FILE], but the property is stored as a raw path, not UID. That means the reference will be broken if you move the file. Consider using [constant PROPERTY_HINT_FILE] when possible.
2970+
</constant>
2971+
<constant name="PROPERTY_HINT_MAX" value="45" enum="PropertyHint">
29692972
Represents the size of the [enum PropertyHint] enum.
29702973
</constant>
29712974
<constant name="PROPERTY_USAGE_NONE" value="0" enum="PropertyUsageFlags" is_bitfield="true">

editor/editor_properties.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void EditorPropertyPath::_set_read_only(bool p_read_only) {
568568
void EditorPropertyPath::_path_selected(const String &p_path) {
569569
String full_path = p_path;
570570

571-
if (!global) {
571+
if (enable_uid) {
572572
const ResourceUID::ID id = ResourceLoader::get_resource_uid(full_path);
573573
if (id != ResourceUID::INVALID_ID) {
574574
full_path = ResourceUID::get_singleton()->id_to_text(id);
@@ -629,10 +629,11 @@ void EditorPropertyPath::update_property() {
629629
path->set_tooltip_text(full_path);
630630
}
631631

632-
void EditorPropertyPath::setup(const Vector<String> &p_extensions, bool p_folder, bool p_global) {
632+
void EditorPropertyPath::setup(const Vector<String> &p_extensions, bool p_folder, bool p_global, bool p_enable_uid) {
633633
extensions = p_extensions;
634634
folder = p_folder;
635635
global = p_global;
636+
enable_uid = p_enable_uid;
636637
}
637638

638639
void EditorPropertyPath::set_save_mode() {
@@ -3801,13 +3802,14 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
38013802
EditorPropertyLocale *editor = memnew(EditorPropertyLocale);
38023803
editor->setup(p_hint_text);
38033804
return editor;
3804-
} else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) {
3805+
} else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE || p_hint == PROPERTY_HINT_FILE_PATH) {
38053806
Vector<String> extensions = p_hint_text.split(",");
38063807
bool global = p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE || p_hint == PROPERTY_HINT_GLOBAL_SAVE_FILE;
38073808
bool folder = p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_GLOBAL_DIR;
38083809
bool save = p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_SAVE_FILE;
3810+
bool enable_uid = p_hint == PROPERTY_HINT_FILE;
38093811
EditorPropertyPath *editor = memnew(EditorPropertyPath);
3810-
editor->setup(extensions, folder, global);
3812+
editor->setup(extensions, folder, global, enable_uid);
38113813
if (save) {
38123814
editor->set_save_mode();
38133815
}

editor/editor_properties.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class EditorPropertyPath : public EditorProperty {
158158
bool folder = false;
159159
bool global = false;
160160
bool save_mode = false;
161+
bool enable_uid = false;
161162
EditorFileDialog *dialog = nullptr;
162163
LineEdit *path = nullptr;
163164
Button *path_edit = nullptr;
@@ -175,7 +176,7 @@ class EditorPropertyPath : public EditorProperty {
175176
void _notification(int p_what);
176177

177178
public:
178-
void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global);
179+
void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global, bool p_enable_uid);
179180
void set_save_mode();
180181
virtual void update_property() override;
181182
EditorPropertyPath();

editor/export/editor_export_platform_apple_embedded.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,19 +338,19 @@ void EditorExportPlatformAppleEmbedded::get_export_options(List<ExportOption> *r
338338
}
339339
}
340340

341-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
342-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_dark", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
343-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
341+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
342+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_dark", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
343+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
344344

345345
HashSet<String> used_names;
346346

347347
Vector<IconInfo> icon_infos = get_icon_infos();
348348
for (int i = 0; i < icon_infos.size(); ++i) {
349349
if (!used_names.has(icon_infos[i].preset_key)) {
350350
used_names.insert(icon_infos[i].preset_key);
351-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
352-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_dark", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
353-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_tinted", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
351+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), ""));
352+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_dark", PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), ""));
353+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_tinted", PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), ""));
354354
}
355355
}
356356
}

editor/export/project_export.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void ProjectExportDialog::_edit_preset(int p_index) {
277277
extension_vector.push_back("*." + extension);
278278
}
279279

280-
export_path->setup(extension_vector, false, true);
280+
export_path->setup(extension_vector, false, true, false);
281281
export_path->update_property();
282282
advanced_options->set_disabled(false);
283283
advanced_options->set_pressed(current->are_advanced_options_enabled());

editor/filesystem_dock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ void FileSystemDock::_update_project_settings_after_move(const HashMap<String, S
16291629
// Find all project settings of type FILE and replace them if needed.
16301630
const HashMap<StringName, PropertyInfo> prop_info = ProjectSettings::get_singleton()->get_custom_property_info();
16311631
for (const KeyValue<StringName, PropertyInfo> &E : prop_info) {
1632-
if (E.value.hint == PROPERTY_HINT_FILE) {
1632+
if (E.value.hint == PROPERTY_HINT_FILE_PATH) {
16331633
String old_path = GLOBAL_GET(E.key);
16341634
if (p_renames.has(old_path)) {
16351635
ProjectSettings::get_singleton()->set_setting(E.key, p_renames[old_path]);

editor/gui/editor_file_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ void EditorFileDialog::_bind_methods() {
22202220
ADD_PROPERTY(PropertyInfo(Variant::INT, "display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"), "set_display_mode", "get_display_mode");
22212221
ADD_PROPERTY(PropertyInfo(Variant::INT, "file_mode", PROPERTY_HINT_ENUM, "Open one,Open many,Open folder,Open any,Save"), "set_file_mode", "get_file_mode");
22222222
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_dir", PROPERTY_HINT_DIR, "", PROPERTY_USAGE_NONE), "set_current_dir", "get_current_dir");
2223-
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file", PROPERTY_HINT_FILE, "*", PROPERTY_USAGE_NONE), "set_current_file", "get_current_file");
2223+
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file", PROPERTY_HINT_FILE_PATH, "*", PROPERTY_USAGE_NONE), "set_current_file", "get_current_file");
22242224
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_current_path", "get_current_path");
22252225
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "filters"), "set_filters", "get_filters");
22262226
ADD_ARRAY_COUNT("Options", "option_count", "set_option_count", "get_option_count", "option_");

modules/gdscript/doc_classes/@GDScript.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@
423423
@export_file("*.txt") var notes_path: String
424424
@export_file var level_paths: Array[String]
425425
[/codeblock]
426+
[b]Note:[/b] The file will be stored and referenced as UID, if available. This ensures that the reference is valid even when the file is moved. You can use [ResourceUID] methods to convert it to path.
427+
</description>
428+
</annotation>
429+
<annotation name="@export_file_path" qualifiers="vararg">
430+
<return type="void" />
431+
<param index="0" name="filter" type="String" default="&quot;&quot;" />
432+
<description>
433+
Same as [annotation @export_file], except the file will be stored as a raw path. This means that it may become invalid when the file is moved. If you are exporting a [Resource] path, consider using [annotation @export_file] instead.
426434
</description>
427435
</annotation>
428436
<annotation name="@export_flags" qualifiers="vararg">

0 commit comments

Comments
 (0)