Skip to content

Commit 2270224

Browse files
committed
Merge pull request godotengine#105414 from KoBeWi/disable_uid_here
Add `@export_file_path` to export raw paths (no UID)
2 parents fae0998 + 42249bb commit 2270224

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. Optional "feature" hint string force hides anything inside when unchecked.
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
@@ -2815,7 +2815,7 @@
28152815
Hints that an integer property is a bitmask using the optionally named avoidance layers.
28162816
</constant>
28172817
<constant name="PROPERTY_HINT_FILE" value="13" enum="PropertyHint">
2818-
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].
2818+
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].
28192819
</constant>
28202820
<constant name="PROPERTY_HINT_DIR" value="14" enum="PropertyHint">
28212821
Hints that a [String] property is a path to a directory. Editing it will show a file dialog for picking the path.
@@ -2964,7 +2964,10 @@
29642964
- If it contains [code]"show_builtin"[/code], built-in input actions are included in the selection.
29652965
- 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.
29662966
</constant>
2967-
<constant name="PROPERTY_HINT_MAX" value="44" enum="PropertyHint">
2967+
<constant name="PROPERTY_HINT_FILE_PATH" value="44" enum="PropertyHint">
2968+
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.
2969+
</constant>
2970+
<constant name="PROPERTY_HINT_MAX" value="45" enum="PropertyHint">
29682971
Represents the size of the [enum PropertyHint] enum.
29692972
</constant>
29702973
<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
@@ -161,6 +161,7 @@ class EditorPropertyPath : public EditorProperty {
161161
bool folder = false;
162162
bool global = false;
163163
bool save_mode = false;
164+
bool enable_uid = false;
164165
EditorFileDialog *dialog = nullptr;
165166
LineEdit *path = nullptr;
166167
Button *path_edit = nullptr;
@@ -178,7 +179,7 @@ class EditorPropertyPath : public EditorProperty {
178179
void _notification(int p_what);
179180

180181
public:
181-
void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global);
182+
void setup(const Vector<String> &p_extensions, bool p_folder, bool p_global, bool p_enable_uid);
182183
void set_save_mode();
183184
virtual void update_property() override;
184185
EditorPropertyPath();

editor/export/editor_export_platform_apple_embedded.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,19 @@ void EditorExportPlatformAppleEmbedded::get_export_options(List<ExportOption> *r
351351
}
352352
}
353353

354-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
355-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_dark", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
356-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
354+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
355+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_dark", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
356+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), ""));
357357

358358
HashSet<String> used_names;
359359

360360
Vector<IconInfo> icon_infos = get_icon_infos();
361361
for (int i = 0; i < icon_infos.size(); ++i) {
362362
if (!used_names.has(icon_infos[i].preset_key)) {
363363
used_names.insert(icon_infos[i].preset_key);
364-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
365-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_dark", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
366-
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_tinted", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
364+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), ""));
365+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_dark", PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), ""));
366+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_tinted", PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), ""));
367367
}
368368
}
369369
}

editor/export/project_export.cpp

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

283-
export_path->setup(extension_vector, false, true);
283+
export_path->setup(extension_vector, false, true, false);
284284
export_path->update_property();
285285
advanced_options->set_disabled(false);
286286
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
@@ -1635,7 +1635,7 @@ void FileSystemDock::_update_project_settings_after_move(const HashMap<String, S
16351635
// Find all project settings of type FILE and replace them if needed.
16361636
const HashMap<StringName, PropertyInfo> prop_info = ProjectSettings::get_singleton()->get_custom_property_info();
16371637
for (const KeyValue<StringName, PropertyInfo> &E : prop_info) {
1638-
if (E.value.hint == PROPERTY_HINT_FILE) {
1638+
if (E.value.hint == PROPERTY_HINT_FILE_PATH) {
16391639
String old_path = GLOBAL_GET(E.key);
16401640
if (p_renames.has(old_path)) {
16411641
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
@@ -2191,7 +2191,7 @@ void EditorFileDialog::_bind_methods() {
21912191
ADD_PROPERTY(PropertyInfo(Variant::INT, "display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"), "set_display_mode", "get_display_mode");
21922192
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");
21932193
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_dir", PROPERTY_HINT_DIR, "", PROPERTY_USAGE_NONE), "set_current_dir", "get_current_dir");
2194-
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file", PROPERTY_HINT_FILE, "*", PROPERTY_USAGE_NONE), "set_current_file", "get_current_file");
2194+
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file", PROPERTY_HINT_FILE_PATH, "*", PROPERTY_USAGE_NONE), "set_current_file", "get_current_file");
21952195
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_current_path", "get_current_path");
21962196
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "filters"), "set_filters", "get_filters");
21972197
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
@@ -435,6 +435,14 @@
435435
@export_file("*.txt") var notes_path: String
436436
@export_file var level_paths: Array[String]
437437
[/codeblock]
438+
[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.
439+
</description>
440+
</annotation>
441+
<annotation name="@export_file_path" qualifiers="vararg">
442+
<return type="void" />
443+
<param index="0" name="filter" type="String" default="&quot;&quot;" />
444+
<description>
445+
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.
438446
</description>
439447
</annotation>
440448
<annotation name="@export_flags" qualifiers="vararg">

0 commit comments

Comments
 (0)