diff --git a/doc/classes/EditorFeatureProfile.xml b/doc/classes/EditorFeatureProfile.xml index d652759dc7e..3aa1e63aac1 100644 --- a/doc/classes/EditorFeatureProfile.xml +++ b/doc/classes/EditorFeatureProfile.xml @@ -51,6 +51,7 @@ Loads an editor feature profile from a file. The file must follow the JSON format obtained by using the feature profile manager's [b]Export[/b] button or the [method save_to_file] method. + [b]Note:[/b] Feature profiles created via the user interface are loaded from the [code]feature_profiles[/code] directory, as a file with the [code].profile[/code] extension. The editor configuration folder can be found by using [method EditorPaths.get_config_dir]. @@ -58,6 +59,7 @@ Saves the editor feature profile to a file in JSON format. It can then be imported using the feature profile manager's [b]Import[/b] button or the [method load_from_file] method. + [b]Note:[/b] Feature profiles created via the user interface are saved in the [code]feature_profiles[/code] directory, as a file with the [code].profile[/code] extension. The editor configuration folder can be found by using [method EditorPaths.get_config_dir]. diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index f8002c260f3..c75e49e87fb 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -54,6 +54,14 @@ Returns the current directory being viewed in the [FileSystemDock]. If a file is selected, its base directory will be returned using [method String.get_base_dir] instead. + + + + Returns the name of the currently activated feature profile. If the default profile is currently active, an empty string is returned instead. + In order to get a reference to the [EditorFeatureProfile], you must load the feature profile using [method EditorFeatureProfile.load_from_file]. + [b]Note:[/b] Feature profiles created via the user interface are loaded from the [code]feature_profiles[/code] directory, as a file with the [code].profile[/code] extension. The editor configuration folder can be found by using [method EditorPaths.get_config_dir]. + + @@ -283,6 +291,15 @@ Selects the file, with the path provided by [param file], in the FileSystem dock. + + + + + Selects and activates the specified feature profile with the given [param profile_name]. Set [param profile_name] to an empty string to reset to the default feature profile. + A feature profile can be created programmatically using the [EditorFeatureProfile] class. + [b]Note:[/b] The feature profile that gets activated must be located in the [code]feature_profiles[/code] directory, as a file with the [code].profile[/code] extension. If a profile could not be found, an error occurs. The editor configuration folder can be found by using [method EditorPaths.get_config_dir]. + + diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index 7c77fec81ac..308bf33da51 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -419,13 +419,7 @@ void EditorFeatureProfileManager::_update_profile_list(const String &p_select_pr void EditorFeatureProfileManager::_profile_action(int p_action) { switch (p_action) { case PROFILE_CLEAR: { - EditorSettings::get_singleton()->set("_default_feature_profile", ""); - EditorSettings::get_singleton()->save(); - current_profile = ""; - current.unref(); - - _update_profile_list(); - _emit_current_profile_changed(); + set_current_profile("", false); } break; case PROFILE_SET: { String selected = _get_selected_profile(); @@ -433,13 +427,7 @@ void EditorFeatureProfileManager::_profile_action(int p_action) { if (selected == current_profile) { return; // Nothing to do here. } - EditorSettings::get_singleton()->set("_default_feature_profile", selected); - EditorSettings::get_singleton()->save(); - current_profile = selected; - current = edited; - - _update_profile_list(); - _emit_current_profile_changed(); + set_current_profile(selected, false); } break; case PROFILE_IMPORT: { import_profiles->popup_file_dialog(); @@ -878,11 +866,45 @@ Ref EditorFeatureProfileManager::get_current_profile() { return current; } +String EditorFeatureProfileManager::get_current_profile_name() const { + return current_profile; +} + +void EditorFeatureProfileManager::set_current_profile(const String &p_profile_name, bool p_validate_profile) { + if (p_validate_profile && !p_profile_name.is_empty()) { + // Profile may not exist. + Ref da = DirAccess::open(EditorPaths::get_singleton()->get_feature_profiles_dir()); + ERR_FAIL_COND_MSG(da.is_null(), "Cannot open directory '" + EditorPaths::get_singleton()->get_feature_profiles_dir() + "'."); + ERR_FAIL_COND_MSG(!da->file_exists(p_profile_name + ".profile"), "Feature profile '" + p_profile_name + "' does not exist."); + + // Change profile selection to emulate the UI interaction. Otherwise, the wrong profile would get activated. + // FIXME: Ideally, _update_selected_profile() should not rely on the user interface state to function properly. + for (int i = 0; i < profile_list->get_item_count(); i++) { + if (profile_list->get_item_metadata(i) == p_profile_name) { + profile_list->select(i); + break; + } + } + _update_selected_profile(); + } + + // Store in editor settings. + EditorSettings::get_singleton()->set("_default_feature_profile", p_profile_name); + EditorSettings::get_singleton()->save(); + + current_profile = p_profile_name; + if (p_profile_name.is_empty()) { + current.unref(); + } else { + current = edited; + } + _update_profile_list(); + _emit_current_profile_changed(); +} + EditorFeatureProfileManager *EditorFeatureProfileManager::singleton = nullptr; void EditorFeatureProfileManager::_bind_methods() { - ClassDB::bind_method("_update_selected_profile", &EditorFeatureProfileManager::_update_selected_profile); - ADD_SIGNAL(MethodInfo("current_feature_profile_changed")); } diff --git a/editor/editor_feature_profile.h b/editor/editor_feature_profile.h index 3f70e03ca88..25ee1c9ba4b 100644 --- a/editor/editor_feature_profile.h +++ b/editor/editor_feature_profile.h @@ -177,6 +177,8 @@ protected: public: Ref get_current_profile(); + String get_current_profile_name() const; + void set_current_profile(const String &p_profile_name, bool p_validate_profile); void notify_changed(); static EditorFeatureProfileManager *get_singleton() { return singleton; } diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp index d9d9dc01c0d..d0d695f2f8b 100644 --- a/editor/editor_interface.cpp +++ b/editor/editor_interface.cpp @@ -31,6 +31,7 @@ #include "editor_interface.h" #include "editor/editor_command_palette.h" +#include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_resource_preview.h" @@ -239,6 +240,14 @@ void EditorInterface::popup_dialog_centered_clamped(Window *p_dialog, const Size p_dialog->popup_exclusive_centered_clamped(EditorNode::get_singleton(), p_size, p_fallback_ratio); } +String EditorInterface::get_current_feature_profile() const { + return EditorFeatureProfileManager::get_singleton()->get_current_profile_name(); +} + +void EditorInterface::set_current_feature_profile(const String &p_profile_name) { + EditorFeatureProfileManager::get_singleton()->set_current_profile(p_profile_name, true); +} + // Editor docks. FileSystemDock *EditorInterface::get_file_system_dock() const { @@ -407,6 +416,9 @@ void EditorInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("popup_dialog_centered_ratio", "dialog", "ratio"), &EditorInterface::popup_dialog_centered_ratio, DEFVAL(0.8)); ClassDB::bind_method(D_METHOD("popup_dialog_centered_clamped", "dialog", "minsize", "fallback_ratio"), &EditorInterface::popup_dialog_centered_clamped, DEFVAL(Size2i()), DEFVAL(0.75)); + ClassDB::bind_method(D_METHOD("get_current_feature_profile"), &EditorInterface::get_current_feature_profile); + ClassDB::bind_method(D_METHOD("set_current_feature_profile", "profile_name"), &EditorInterface::set_current_feature_profile); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distraction_free_mode"), "set_distraction_free_mode", "is_distraction_free_mode_enabled"); // Editor docks. diff --git a/editor/editor_interface.h b/editor/editor_interface.h index f7e8cf8d4c6..ac31ce4dfbb 100644 --- a/editor/editor_interface.h +++ b/editor/editor_interface.h @@ -104,6 +104,9 @@ public: void popup_dialog_centered_ratio(Window *p_dialog, float p_ratio = 0.8); void popup_dialog_centered_clamped(Window *p_dialog, const Size2i &p_size = Size2i(), float p_fallback_ratio = 0.75); + String get_current_feature_profile() const; + void set_current_feature_profile(const String &p_profile_name); + // Editor docks. FileSystemDock *get_file_system_dock() const;