Add ability to edit editor feature profiles
Allows enabling/disabling parts of the editor and storing/loading profiles for that.
This commit is contained in:
parent
9ab17b664d
commit
a20235aeb0
|
@ -312,6 +312,19 @@ void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringNa
|
|||
}
|
||||
}
|
||||
|
||||
void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
||||
const StringName *k = NULL;
|
||||
|
||||
while ((k = classes.next(k))) {
|
||||
|
||||
if (*k != p_class && get_parent_class(*k) == p_class)
|
||||
p_classes->push_back(*k);
|
||||
}
|
||||
}
|
||||
|
||||
StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
|
|
@ -214,6 +214,7 @@ public:
|
|||
|
||||
static void get_class_list(List<StringName> *p_classes);
|
||||
static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
|
||||
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
|
||||
static StringName get_parent_class_nocheck(const StringName &p_class);
|
||||
static StringName get_parent_class(const StringName &p_class);
|
||||
static bool class_exists(const StringName &p_class);
|
||||
|
|
|
@ -571,10 +571,16 @@ void FileAccess::store_buffer(const uint8_t *p_src, int p_length) {
|
|||
store_8(p_src[i]);
|
||||
}
|
||||
|
||||
Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) {
|
||||
Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) {
|
||||
|
||||
FileAccess *f = FileAccess::open(p_path, READ);
|
||||
ERR_FAIL_COND_V(!f, Vector<uint8_t>());
|
||||
FileAccess *f = FileAccess::open(p_path, READ, r_error);
|
||||
if (!f) {
|
||||
if (r_error) { // if error requested, do not throw error
|
||||
return Vector<uint8_t>();
|
||||
} else {
|
||||
ERR_FAIL_COND_V(!f, Vector<uint8_t>());
|
||||
}
|
||||
}
|
||||
Vector<uint8_t> data;
|
||||
data.resize(f->get_len());
|
||||
f->get_buffer(data.ptrw(), data.size());
|
||||
|
@ -582,6 +588,26 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) {
|
|||
return data;
|
||||
}
|
||||
|
||||
String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
|
||||
|
||||
Error err;
|
||||
Vector<uint8_t> array = get_file_as_array(p_path, &err);
|
||||
if (r_error) {
|
||||
*r_error = err;
|
||||
}
|
||||
if (err != OK) {
|
||||
if (r_error) {
|
||||
return String();
|
||||
} else {
|
||||
ERR_FAIL_COND_V(err != OK, String());
|
||||
}
|
||||
}
|
||||
|
||||
String ret;
|
||||
ret.parse_utf8((const char *)array.ptr(), array.size());
|
||||
return ret;
|
||||
}
|
||||
|
||||
String FileAccess::get_md5(const String &p_file) {
|
||||
|
||||
FileAccess *f = FileAccess::open(p_file, READ);
|
||||
|
|
|
@ -164,7 +164,8 @@ public:
|
|||
static String get_sha256(const String &p_file);
|
||||
static String get_multiple_md5(const Vector<String> &p_file);
|
||||
|
||||
static Vector<uint8_t> get_file_as_array(const String &p_path);
|
||||
static Vector<uint8_t> get_file_as_array(const String &p_path, Error *r_error = NULL);
|
||||
static String get_file_as_string(const String &p_path, Error *r_error = NULL);
|
||||
|
||||
template <class T>
|
||||
static void make_default(AccessType p_access) {
|
||||
|
|
|
@ -3748,6 +3748,24 @@ bool String::is_valid_html_color() const {
|
|||
return Color::html_is_valid(*this);
|
||||
}
|
||||
|
||||
bool String::is_valid_filename() const {
|
||||
|
||||
String stripped = strip_edges();
|
||||
if (*this != stripped) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stripped == String()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (find(":") != -1 || find("/") != -1 || find("\\") != -1 || find("?") != -1 || find("*") != -1 || find("\"") != -1 || find("|") != -1 || find("%") != -1 || find("<") != -1 || find(">") != -1) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool String::is_valid_ip_address() const {
|
||||
|
||||
if (find(":") >= 0) {
|
||||
|
|
|
@ -335,6 +335,7 @@ public:
|
|||
bool is_valid_hex_number(bool p_with_prefix) const;
|
||||
bool is_valid_html_color() const;
|
||||
bool is_valid_ip_address() const;
|
||||
bool is_valid_filename() const;
|
||||
|
||||
/**
|
||||
* The constructors must not depend on other overloads
|
||||
|
@ -406,11 +407,18 @@ _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
|
|||
//tool translate
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
//gets parsed
|
||||
String TTR(const String &);
|
||||
//use for c strings
|
||||
#define TTRC(m_value) m_value
|
||||
//use to avoid parsing (for use later with C strings)
|
||||
#define TTRGET(m_value) TTR(m_value)
|
||||
|
||||
#else
|
||||
|
||||
#define TTR(m_val) (String())
|
||||
#define TTRCDEF(m_value) (m_value)
|
||||
#define TTRC(m_value) (m_value)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -294,6 +294,7 @@ struct _VariantCall {
|
|||
VCALL_LOCALMEM1R(String, is_valid_hex_number);
|
||||
VCALL_LOCALMEM0R(String, is_valid_html_color);
|
||||
VCALL_LOCALMEM0R(String, is_valid_ip_address);
|
||||
VCALL_LOCALMEM0R(String, is_valid_filename);
|
||||
VCALL_LOCALMEM0R(String, to_int);
|
||||
VCALL_LOCALMEM0R(String, to_float);
|
||||
VCALL_LOCALMEM0R(String, hex_to_int);
|
||||
|
@ -1542,6 +1543,7 @@ void register_variant_methods() {
|
|||
ADDFUNC1R(STRING, BOOL, String, is_valid_hex_number, BOOL, "with_prefix", varray(false));
|
||||
ADDFUNC0R(STRING, BOOL, String, is_valid_html_color, varray());
|
||||
ADDFUNC0R(STRING, BOOL, String, is_valid_ip_address, varray());
|
||||
ADDFUNC0R(STRING, BOOL, String, is_valid_filename, varray());
|
||||
ADDFUNC0R(STRING, INT, String, to_int, varray());
|
||||
ADDFUNC0R(STRING, REAL, String, to_float, varray());
|
||||
ADDFUNC0R(STRING, INT, String, hex_to_int, varray());
|
||||
|
|
|
@ -238,6 +238,26 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
|
|||
p_types[p_type] = item;
|
||||
}
|
||||
|
||||
bool CreateDialog::_is_class_disabled_by_feature_profile(const StringName &p_class) {
|
||||
|
||||
Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
|
||||
if (profile.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringName class_name = p_class;
|
||||
|
||||
while (class_name != StringName()) {
|
||||
|
||||
if (profile->is_class_disabled(class_name)) {
|
||||
return true;
|
||||
}
|
||||
class_name = ClassDB::get_parent_class(class_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CreateDialog::_update_search() {
|
||||
|
||||
search_options->clear();
|
||||
|
@ -264,6 +284,10 @@ void CreateDialog::_update_search() {
|
|||
for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) {
|
||||
|
||||
String type = I->get();
|
||||
|
||||
if (_is_class_disabled_by_feature_profile(type)) {
|
||||
continue;
|
||||
}
|
||||
bool cpp_type = ClassDB::class_exists(type);
|
||||
|
||||
if (base_type == "Node" && type.begins_with("Editor"))
|
||||
|
|
|
@ -86,6 +86,8 @@ class CreateDialog : public ConfirmationDialog {
|
|||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||
|
||||
bool _is_class_disabled_by_feature_profile(const StringName &p_class);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
|
|
@ -0,0 +1,889 @@
|
|||
#include "editor_feature_profile.h"
|
||||
#include "core/io/json.h"
|
||||
#include "core/os/dir_access.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "editor_node.h"
|
||||
#include "editor_scale.h"
|
||||
|
||||
const char *EditorFeatureProfile::feature_names[FEATURE_MAX] = {
|
||||
TTRC("3D Editor"),
|
||||
TTRC("Script Editor"),
|
||||
TTRC("Asset Library"),
|
||||
TTRC("Scene Tree Editing"),
|
||||
TTRC("Import Dock"),
|
||||
TTRC("Node Dock"),
|
||||
TTRC("Filesystem Dock")
|
||||
};
|
||||
|
||||
const char *EditorFeatureProfile::feature_identifiers[FEATURE_MAX] = {
|
||||
"3d",
|
||||
"script",
|
||||
"asset_lib",
|
||||
"scene_tree",
|
||||
"import_dock",
|
||||
"node_dock",
|
||||
"filesystem_dock"
|
||||
};
|
||||
|
||||
void EditorFeatureProfile::set_disable_class(const StringName &p_class, bool p_disabled) {
|
||||
if (p_disabled) {
|
||||
disabled_classes.insert(p_class);
|
||||
} else {
|
||||
disabled_classes.erase(p_class);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorFeatureProfile::is_class_disabled(const StringName &p_class) const {
|
||||
return disabled_classes.has(p_class);
|
||||
}
|
||||
|
||||
void EditorFeatureProfile::set_disable_class_editor(const StringName &p_class, bool p_disabled) {
|
||||
if (p_disabled) {
|
||||
disabled_editors.insert(p_class);
|
||||
} else {
|
||||
disabled_editors.erase(p_class);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorFeatureProfile::is_class_editor_disabled(const StringName &p_class) const {
|
||||
return disabled_editors.has(p_class);
|
||||
}
|
||||
|
||||
void EditorFeatureProfile::set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled) {
|
||||
|
||||
if (p_disabled) {
|
||||
if (!disabled_properties.has(p_class)) {
|
||||
disabled_properties[p_class] = Set<StringName>();
|
||||
}
|
||||
|
||||
disabled_properties[p_class].insert(p_property);
|
||||
} else {
|
||||
ERR_FAIL_COND(!disabled_properties.has(p_class));
|
||||
disabled_properties[p_class].erase(p_property);
|
||||
if (disabled_properties[p_class].empty()) {
|
||||
disabled_properties.erase(p_class);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool EditorFeatureProfile::is_class_property_disabled(const StringName &p_class, const StringName &p_property) const {
|
||||
|
||||
if (!disabled_properties.has(p_class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!disabled_properties[p_class].has(p_property)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorFeatureProfile::has_class_properties_disabled(const StringName &p_class) const {
|
||||
return disabled_properties.has(p_class);
|
||||
}
|
||||
|
||||
void EditorFeatureProfile::set_disable_feature(Feature p_feature, bool p_disable) {
|
||||
|
||||
ERR_FAIL_INDEX(p_feature, FEATURE_MAX);
|
||||
features_disabled[p_feature] = p_disable;
|
||||
}
|
||||
bool EditorFeatureProfile::is_feature_disabled(Feature p_feature) const {
|
||||
ERR_FAIL_INDEX_V(p_feature, FEATURE_MAX, false);
|
||||
return features_disabled[p_feature];
|
||||
}
|
||||
|
||||
String EditorFeatureProfile::get_feature_name(Feature p_feature) {
|
||||
ERR_FAIL_INDEX_V(p_feature, FEATURE_MAX, String());
|
||||
return feature_names[p_feature];
|
||||
}
|
||||
|
||||
Error EditorFeatureProfile::save_to_file(const String &p_path) {
|
||||
|
||||
Dictionary json;
|
||||
json["type"] = "feature_profile";
|
||||
Array dis_classes;
|
||||
for (Set<StringName>::Element *E = disabled_classes.front(); E; E = E->next()) {
|
||||
dis_classes.push_back(String(E->get()));
|
||||
}
|
||||
dis_classes.sort();
|
||||
json["disabled_classes"] = dis_classes;
|
||||
|
||||
Array dis_editors;
|
||||
for (Set<StringName>::Element *E = disabled_editors.front(); E; E = E->next()) {
|
||||
dis_editors.push_back(String(E->get()));
|
||||
}
|
||||
dis_editors.sort();
|
||||
json["disabled_editors"] = dis_editors;
|
||||
|
||||
Array dis_props;
|
||||
|
||||
for (Map<StringName, Set<StringName> >::Element *E = disabled_properties.front(); E; E = E->next()) {
|
||||
for (Set<StringName>::Element *F = E->get().front(); F; F = F->next()) {
|
||||
dis_props.push_back(String(E->key()) + ":" + String(F->get()));
|
||||
}
|
||||
}
|
||||
|
||||
json["disabled_properties"] = dis_props;
|
||||
|
||||
Array dis_features;
|
||||
for (int i = 0; i < FEATURE_MAX; i++) {
|
||||
if (features_disabled[i]) {
|
||||
dis_features.push_back(feature_identifiers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
json["disabled_features"] = dis_features;
|
||||
|
||||
FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
|
||||
|
||||
String text = JSON::print(json, "\t");
|
||||
f->store_string(text);
|
||||
f->close();
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error EditorFeatureProfile::load_from_file(const String &p_path) {
|
||||
|
||||
Error err;
|
||||
String text = FileAccess::get_file_as_string(p_path, &err);
|
||||
if (err != OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
String err_str;
|
||||
int err_line;
|
||||
Variant v;
|
||||
err = JSON::parse(text, v, err_str, err_line);
|
||||
if (err != OK) {
|
||||
ERR_PRINTS("Error parsing '" + p_path + "' on line " + itos(err_line) + ": " + err_str);
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
Dictionary json = v;
|
||||
|
||||
if (!json.has("type") || String(json["type"]) != "feature_profile") {
|
||||
ERR_PRINTS("Error parsing '" + p_path + "', it's not a feature profile.");
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
disabled_classes.clear();
|
||||
|
||||
if (json.has("disabled_classes")) {
|
||||
Array disabled_classes_arr = json["disabled_classes"];
|
||||
for (int i = 0; i < disabled_classes_arr.size(); i++) {
|
||||
disabled_classes.insert(disabled_classes_arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
disabled_editors.clear();
|
||||
|
||||
if (json.has("disabled_editors")) {
|
||||
Array disabled_editors_arr = json["disabled_editors"];
|
||||
for (int i = 0; i < disabled_editors_arr.size(); i++) {
|
||||
disabled_editors.insert(disabled_editors_arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
disabled_properties.clear();
|
||||
|
||||
if (json.has("disabled_properties")) {
|
||||
Array disabled_properties_arr = json["disabled_properties"];
|
||||
for (int i = 0; i < disabled_properties_arr.size(); i++) {
|
||||
String s = disabled_properties_arr[i];
|
||||
set_disable_class_property(s.get_slice(":", 0), s.get_slice(":", 1), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (json.has("disabled_features")) {
|
||||
|
||||
Array disabled_features_arr = json["disabled_features"];
|
||||
for (int i = 0; i < FEATURE_MAX; i++) {
|
||||
bool found = false;
|
||||
String f = feature_identifiers[i];
|
||||
for (int j = 0; j < disabled_features_arr.size(); j++) {
|
||||
String fd = disabled_features_arr[j];
|
||||
if (fd == f) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
features_disabled[i] = found;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EditorFeatureProfile::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_disable_class", "class_name", "disable"), &EditorFeatureProfile::set_disable_class);
|
||||
ClassDB::bind_method(D_METHOD("is_class_disabled", "class_name"), &EditorFeatureProfile::is_class_disabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_disable_class_editor", "class_name", "disable"), &EditorFeatureProfile::set_disable_class_editor);
|
||||
ClassDB::bind_method(D_METHOD("is_class_editor_disabled", "class_name"), &EditorFeatureProfile::is_class_editor_disabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_disable_class_property", "class_name", "property"), &EditorFeatureProfile::set_disable_class_property);
|
||||
ClassDB::bind_method(D_METHOD("is_class_property_disabled", "class_name"), &EditorFeatureProfile::is_class_property_disabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_disable_feature", "feature", "disable"), &EditorFeatureProfile::set_disable_feature);
|
||||
ClassDB::bind_method(D_METHOD("is_feature_disabled", "feature"), &EditorFeatureProfile::is_feature_disabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_feature_name", "feature"), &EditorFeatureProfile::_get_feature_name);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("save_to_file", "path"), &EditorFeatureProfile::save_to_file);
|
||||
ClassDB::bind_method(D_METHOD("load_from_file", "path"), &EditorFeatureProfile::load_from_file);
|
||||
|
||||
BIND_ENUM_CONSTANT(FEATURE_3D);
|
||||
BIND_ENUM_CONSTANT(FEATURE_SCRIPT);
|
||||
BIND_ENUM_CONSTANT(FEATURE_ASSET_LIB);
|
||||
BIND_ENUM_CONSTANT(FEATURE_SCENE_TREE);
|
||||
BIND_ENUM_CONSTANT(FEATURE_IMPORT_DOCK);
|
||||
BIND_ENUM_CONSTANT(FEATURE_NODE_DOCK);
|
||||
BIND_ENUM_CONSTANT(FEATURE_FILESYSTEM_DOCK);
|
||||
BIND_ENUM_CONSTANT(FEATURE_MAX);
|
||||
}
|
||||
|
||||
EditorFeatureProfile::EditorFeatureProfile() {
|
||||
|
||||
for (int i = 0; i < FEATURE_MAX; i++) {
|
||||
features_disabled[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
|
||||
void EditorFeatureProfileManager::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_READY) {
|
||||
|
||||
current_profile = EDITOR_GET("_default_feature_profile");
|
||||
if (current_profile != String()) {
|
||||
current.instance();
|
||||
Error err = current->load_from_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(current_profile + ".profile"));
|
||||
if (err != OK) {
|
||||
ERR_PRINTS("Error loading default feature profile: " + current_profile);
|
||||
current_profile = String();
|
||||
current.unref();
|
||||
}
|
||||
}
|
||||
_update_profile_list(current_profile);
|
||||
}
|
||||
}
|
||||
|
||||
String EditorFeatureProfileManager::_get_selected_profile() {
|
||||
int idx = profile_list->get_selected();
|
||||
if (idx < 0) {
|
||||
return String();
|
||||
}
|
||||
|
||||
return profile_list->get_item_metadata(idx);
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_update_profile_list(const String &p_select_profile) {
|
||||
|
||||
String selected_profile;
|
||||
if (p_select_profile == String()) { //default, keep
|
||||
if (profile_list->get_selected() >= 0) {
|
||||
selected_profile = profile_list->get_item_metadata(profile_list->get_selected());
|
||||
if (!FileAccess::exists(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(selected_profile + ".profile"))) {
|
||||
selected_profile = String(); //does not exist
|
||||
}
|
||||
}
|
||||
} else {
|
||||
selected_profile = p_select_profile;
|
||||
}
|
||||
|
||||
Vector<String> profiles;
|
||||
DirAccessRef d = DirAccess::open(EditorSettings::get_singleton()->get_feature_profiles_dir());
|
||||
ERR_FAIL_COND(!d);
|
||||
d->list_dir_begin();
|
||||
while (true) {
|
||||
String f = d->get_next();
|
||||
if (f == String()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!d->current_is_dir()) {
|
||||
int last_pos = f.find_last(".profile");
|
||||
if (last_pos != -1) {
|
||||
profiles.push_back(f.substr(0, last_pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
profiles.sort();
|
||||
|
||||
profile_list->clear();
|
||||
|
||||
for (int i = 0; i < profiles.size(); i++) {
|
||||
String name = profiles[i];
|
||||
|
||||
if (i == 0 && selected_profile == String()) {
|
||||
selected_profile = name;
|
||||
}
|
||||
|
||||
if (name == current_profile) {
|
||||
name += " (current)";
|
||||
}
|
||||
profile_list->add_item(name);
|
||||
int index = profile_list->get_item_count() - 1;
|
||||
profile_list->set_item_metadata(index, profiles[i]);
|
||||
if (profiles[i] == selected_profile) {
|
||||
profile_list->select(index);
|
||||
}
|
||||
}
|
||||
|
||||
profile_actions[PROFILE_CLEAR]->set_disabled(current_profile == String());
|
||||
profile_actions[PROFILE_ERASE]->set_disabled(selected_profile == String());
|
||||
profile_actions[PROFILE_EXPORT]->set_disabled(selected_profile == String());
|
||||
profile_actions[PROFILE_SET]->set_disabled(selected_profile == String());
|
||||
|
||||
current_profile_name->set_text(current_profile);
|
||||
|
||||
_update_selected_profile();
|
||||
}
|
||||
|
||||
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();
|
||||
} break;
|
||||
case PROFILE_SET: {
|
||||
|
||||
String selected = _get_selected_profile();
|
||||
ERR_FAIL_COND(selected == String());
|
||||
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();
|
||||
|
||||
} break;
|
||||
case PROFILE_IMPORT: {
|
||||
|
||||
import_profiles->popup_centered_ratio();
|
||||
} break;
|
||||
case PROFILE_EXPORT: {
|
||||
|
||||
export_profile->popup_centered_ratio();
|
||||
export_profile->set_current_file(_get_selected_profile() + ".profile");
|
||||
} break;
|
||||
case PROFILE_NEW: {
|
||||
|
||||
new_profile_dialog->popup_centered_minsize();
|
||||
new_profile_name->clear();
|
||||
new_profile_name->grab_focus();
|
||||
} break;
|
||||
case PROFILE_ERASE: {
|
||||
String selected = _get_selected_profile();
|
||||
ERR_FAIL_COND(selected == String());
|
||||
|
||||
erase_profile_dialog->set_text(vformat(TTR("Erase profile '%s'? (no undo)"), selected));
|
||||
erase_profile_dialog->popup_centered_minsize();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_erase_selected_profile() {
|
||||
|
||||
String selected = _get_selected_profile();
|
||||
ERR_FAIL_COND(selected == String());
|
||||
DirAccessRef da = DirAccess::open(EditorSettings::get_singleton()->get_feature_profiles_dir());
|
||||
ERR_FAIL_COND(!da);
|
||||
da->remove(selected + ".profile");
|
||||
if (selected == current_profile) {
|
||||
_profile_action(PROFILE_CLEAR);
|
||||
} else {
|
||||
_update_profile_list();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_create_new_profile() {
|
||||
String name = new_profile_name->get_text().strip_edges();
|
||||
if (!name.is_valid_filename() || name.find(".") != -1) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Profile must be a valid filename and must not contain '.'"));
|
||||
return;
|
||||
}
|
||||
String file = EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(name + ".profile");
|
||||
if (FileAccess::exists(file)) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Profile with this name already exists."));
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<EditorFeatureProfile> new_profile;
|
||||
new_profile.instance();
|
||||
new_profile->save_to_file(file);
|
||||
|
||||
_update_profile_list(name);
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_profile_selected(int p_what) {
|
||||
|
||||
_update_selected_profile();
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected) {
|
||||
|
||||
TreeItem *class_item = class_list->create_item(p_parent);
|
||||
class_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
||||
class_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_class, "Node"));
|
||||
String text = p_class;
|
||||
|
||||
bool disabled = edited->is_class_disabled(p_class);
|
||||
bool disabled_editor = edited->is_class_editor_disabled(p_class);
|
||||
bool disabled_properties = edited->has_class_properties_disabled(p_class);
|
||||
if (disabled) {
|
||||
class_item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
|
||||
} else if (disabled_editor && disabled_properties) {
|
||||
text += " " + TTR("(Editor Disabled, Properties Disabled)");
|
||||
} else if (disabled_properties) {
|
||||
text += " " + TTR("(Properties Disabled)");
|
||||
} else if (disabled_editor) {
|
||||
text += " " + TTR("(Editor Disabled)");
|
||||
}
|
||||
class_item->set_text(0, text);
|
||||
class_item->set_editable(0, true);
|
||||
class_item->set_selectable(0, true);
|
||||
class_item->set_metadata(0, p_class);
|
||||
|
||||
if (p_class == p_selected) {
|
||||
class_item->select(0);
|
||||
}
|
||||
if (disabled) {
|
||||
//class disabled, do nothing else (do not show further)
|
||||
return;
|
||||
}
|
||||
|
||||
class_item->set_checked(0, true); // if its not disabled, its checked
|
||||
|
||||
List<StringName> child_classes;
|
||||
ClassDB::get_direct_inheriters_from_class(p_class, &child_classes);
|
||||
child_classes.sort_custom<StringName::AlphCompare>();
|
||||
|
||||
for (List<StringName>::Element *E = child_classes.front(); E; E = E->next()) {
|
||||
String name = E->get();
|
||||
if (name.begins_with("Editor") || ClassDB::get_api_type(name) != ClassDB::API_CORE) {
|
||||
continue;
|
||||
}
|
||||
_fill_classes_from(class_item, name, p_selected);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_class_list_item_selected() {
|
||||
|
||||
if (updating_features)
|
||||
return;
|
||||
|
||||
property_list->clear();
|
||||
|
||||
TreeItem *item = class_list->get_selected();
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
Variant md = item->get_metadata(0);
|
||||
if (md.get_type() != Variant::STRING) {
|
||||
return;
|
||||
}
|
||||
|
||||
String class_name = md;
|
||||
|
||||
if (edited->is_class_disabled(class_name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
updating_features = true;
|
||||
TreeItem *root = property_list->create_item();
|
||||
TreeItem *options = property_list->create_item(root);
|
||||
options->set_text(0, TTR("Class Options:"));
|
||||
|
||||
{
|
||||
TreeItem *option = property_list->create_item(options);
|
||||
option->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
||||
option->set_editable(0, true);
|
||||
option->set_selectable(0, true);
|
||||
option->set_checked(0, edited->is_class_editor_disabled(class_name));
|
||||
option->set_text(0, TTR("Disable Editor"));
|
||||
option->set_metadata(0, CLASS_OPTION_DISABLE_EDITOR);
|
||||
}
|
||||
|
||||
TreeItem *properties = property_list->create_item(root);
|
||||
properties->set_text(0, TTR("Enabled Properties:"));
|
||||
|
||||
List<PropertyInfo> props;
|
||||
|
||||
ClassDB::get_property_list(class_name, &props, true);
|
||||
|
||||
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
||||
|
||||
String name = E->get().name;
|
||||
if (!(E->get().usage & PROPERTY_USAGE_EDITOR))
|
||||
continue;
|
||||
TreeItem *property = property_list->create_item(properties);
|
||||
property->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
||||
property->set_editable(0, true);
|
||||
property->set_selectable(0, true);
|
||||
property->set_checked(0, !edited->is_class_property_disabled(class_name, name));
|
||||
property->set_text(0, name.capitalize());
|
||||
property->set_metadata(0, name);
|
||||
String icon_type = Variant::get_type_name(E->get().type);
|
||||
property->set_icon(0, EditorNode::get_singleton()->get_class_icon(icon_type));
|
||||
}
|
||||
|
||||
updating_features = false;
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_class_list_item_edited() {
|
||||
|
||||
if (updating_features)
|
||||
return;
|
||||
|
||||
TreeItem *item = class_list->get_edited();
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool checked = item->is_checked(0);
|
||||
|
||||
Variant md = item->get_metadata(0);
|
||||
if (md.get_type() == Variant::STRING) {
|
||||
String class_selected = md;
|
||||
edited->set_disable_class(class_selected, !checked);
|
||||
_save_and_update();
|
||||
_update_selected_profile();
|
||||
} else if (md.get_type() == Variant::INT) {
|
||||
int feature_selected = md;
|
||||
edited->set_disable_feature(EditorFeatureProfile::Feature(feature_selected), !checked);
|
||||
_save_and_update();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_property_item_edited() {
|
||||
if (updating_features)
|
||||
return;
|
||||
|
||||
TreeItem *class_item = class_list->get_selected();
|
||||
if (!class_item) {
|
||||
return;
|
||||
}
|
||||
|
||||
Variant md = class_item->get_metadata(0);
|
||||
if (md.get_type() != Variant::STRING) {
|
||||
return;
|
||||
}
|
||||
|
||||
String class_name = md;
|
||||
|
||||
TreeItem *item = property_list->get_edited();
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
bool checked = item->is_checked(0);
|
||||
|
||||
md = item->get_metadata(0);
|
||||
if (md.get_type() == Variant::STRING) {
|
||||
String property_selected = md;
|
||||
edited->set_disable_class_property(class_name, property_selected, !checked);
|
||||
_save_and_update();
|
||||
_update_selected_profile();
|
||||
} else if (md.get_type() == Variant::INT) {
|
||||
int feature_selected = md;
|
||||
switch (feature_selected) {
|
||||
case CLASS_OPTION_DISABLE_EDITOR: {
|
||||
edited->set_disable_class_editor(class_name, checked);
|
||||
_save_and_update();
|
||||
_update_selected_profile();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_update_selected_profile() {
|
||||
|
||||
String class_selected;
|
||||
int feature_selected = -1;
|
||||
|
||||
if (class_list->get_selected()) {
|
||||
Variant md = class_list->get_selected()->get_metadata(0);
|
||||
if (md.get_type() == Variant::STRING) {
|
||||
class_selected = md;
|
||||
} else if (md.get_type() == Variant::INT) {
|
||||
feature_selected = md;
|
||||
}
|
||||
}
|
||||
|
||||
class_list->clear();
|
||||
|
||||
String profile = _get_selected_profile();
|
||||
if (profile == String()) { //nothing selected, nothing edited
|
||||
property_list->clear();
|
||||
edited.unref();
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile == current_profile) {
|
||||
edited = current; //reuse current profile (which is what editor uses)
|
||||
ERR_FAIL_COND(current.is_null()); //nothing selected, current should never be null
|
||||
} else {
|
||||
//reload edited, if different from current
|
||||
edited.instance();
|
||||
Error err = edited->load_from_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(profile + ".profile"));
|
||||
ERR_FAIL_COND(err != OK);
|
||||
}
|
||||
|
||||
updating_features = true;
|
||||
|
||||
TreeItem *root = class_list->create_item();
|
||||
|
||||
TreeItem *features = class_list->create_item(root);
|
||||
features->set_text(0, TTR("Enabled Features:"));
|
||||
for (int i = 0; i < EditorFeatureProfile::FEATURE_MAX; i++) {
|
||||
|
||||
TreeItem *feature = class_list->create_item(features);
|
||||
feature->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
||||
feature->set_text(0, TTRGET(EditorFeatureProfile::get_feature_name(EditorFeatureProfile::Feature(i))));
|
||||
feature->set_selectable(0, true);
|
||||
feature->set_editable(0, true);
|
||||
feature->set_metadata(0, i);
|
||||
if (!edited->is_feature_disabled(EditorFeatureProfile::Feature(i))) {
|
||||
feature->set_checked(0, true);
|
||||
}
|
||||
|
||||
if (i == feature_selected) {
|
||||
feature->select(0);
|
||||
}
|
||||
}
|
||||
|
||||
TreeItem *classes = class_list->create_item(root);
|
||||
classes->set_text(0, TTR("Enabled Classes:"));
|
||||
|
||||
_fill_classes_from(classes, "Node", class_selected);
|
||||
_fill_classes_from(classes, "Resource", class_selected);
|
||||
|
||||
updating_features = false;
|
||||
|
||||
_class_list_item_selected();
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_import_profiles(const Vector<String> &p_paths) {
|
||||
|
||||
//test it first
|
||||
for (int i = 0; i < p_paths.size(); i++) {
|
||||
Ref<EditorFeatureProfile> profile;
|
||||
profile.instance();
|
||||
Error err = profile->load_from_file(p_paths[i]);
|
||||
String basefile = p_paths[i].get_file();
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(vformat(TTR("File '%s' format is invalid, import aborted."), basefile));
|
||||
return;
|
||||
}
|
||||
|
||||
String dst_file = EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(basefile);
|
||||
|
||||
if (FileAccess::exists(dst_file)) {
|
||||
EditorNode::get_singleton()->show_warning(vformat(TTR("Profile '%s' already exists. Remote it first before importing, import aborted."), basefile.get_basename()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//do it second
|
||||
for (int i = 0; i < p_paths.size(); i++) {
|
||||
Ref<EditorFeatureProfile> profile;
|
||||
profile.instance();
|
||||
Error err = profile->load_from_file(p_paths[i]);
|
||||
ERR_CONTINUE(err != OK);
|
||||
String basefile = p_paths[i].get_file();
|
||||
String dst_file = EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(basefile);
|
||||
profile->save_to_file(dst_file);
|
||||
}
|
||||
|
||||
_update_profile_list();
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_export_profile(const String &p_path) {
|
||||
|
||||
ERR_FAIL_COND(edited.is_null());
|
||||
Error err = edited->save_to_file(p_path);
|
||||
if (err != OK) {
|
||||
EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving profile to path: '%s'."), p_path));
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_save_and_update() {
|
||||
|
||||
String edited_path = _get_selected_profile();
|
||||
ERR_FAIL_COND(edited_path == String());
|
||||
ERR_FAIL_COND(edited.is_null());
|
||||
|
||||
edited->save_to_file(EditorSettings::get_singleton()->get_feature_profiles_dir().plus_file(edited_path + ".profile"));
|
||||
|
||||
if (edited == current) {
|
||||
update_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::_emit_current_profile_changed() {
|
||||
|
||||
emit_signal("current_feature_profile_changed");
|
||||
}
|
||||
|
||||
void EditorFeatureProfileManager::notify_changed() {
|
||||
_emit_current_profile_changed();
|
||||
}
|
||||
|
||||
Ref<EditorFeatureProfile> EditorFeatureProfileManager::get_current_profile() {
|
||||
return current;
|
||||
}
|
||||
|
||||
EditorFeatureProfileManager *EditorFeatureProfileManager::singleton = NULL;
|
||||
|
||||
void EditorFeatureProfileManager::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method("_update_selected_profile", &EditorFeatureProfileManager::_update_selected_profile);
|
||||
ClassDB::bind_method("_profile_action", &EditorFeatureProfileManager::_profile_action);
|
||||
ClassDB::bind_method("_create_new_profile", &EditorFeatureProfileManager::_create_new_profile);
|
||||
ClassDB::bind_method("_profile_selected", &EditorFeatureProfileManager::_profile_selected);
|
||||
ClassDB::bind_method("_erase_selected_profile", &EditorFeatureProfileManager::_erase_selected_profile);
|
||||
ClassDB::bind_method("_import_profiles", &EditorFeatureProfileManager::_import_profiles);
|
||||
ClassDB::bind_method("_export_profile", &EditorFeatureProfileManager::_export_profile);
|
||||
ClassDB::bind_method("_class_list_item_selected", &EditorFeatureProfileManager::_class_list_item_selected);
|
||||
ClassDB::bind_method("_class_list_item_edited", &EditorFeatureProfileManager::_class_list_item_edited);
|
||||
ClassDB::bind_method("_property_item_edited", &EditorFeatureProfileManager::_property_item_edited);
|
||||
ClassDB::bind_method("_emit_current_profile_changed", &EditorFeatureProfileManager::_emit_current_profile_changed);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("current_feature_profile_changed"));
|
||||
}
|
||||
|
||||
EditorFeatureProfileManager::EditorFeatureProfileManager() {
|
||||
|
||||
VBoxContainer *main_vbc = memnew(VBoxContainer);
|
||||
add_child(main_vbc);
|
||||
|
||||
HBoxContainer *name_hbc = memnew(HBoxContainer);
|
||||
current_profile_name = memnew(LineEdit);
|
||||
name_hbc->add_child(current_profile_name);
|
||||
current_profile_name->set_editable(false);
|
||||
current_profile_name->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
profile_actions[PROFILE_CLEAR] = memnew(Button(TTR("Unset")));
|
||||
name_hbc->add_child(profile_actions[PROFILE_CLEAR]);
|
||||
profile_actions[PROFILE_CLEAR]->set_disabled(true);
|
||||
profile_actions[PROFILE_CLEAR]->connect("pressed", this, "_profile_action", varray(PROFILE_CLEAR));
|
||||
|
||||
main_vbc->add_margin_child(TTR("Current Profile"), name_hbc);
|
||||
|
||||
HBoxContainer *profiles_hbc = memnew(HBoxContainer);
|
||||
profile_list = memnew(OptionButton);
|
||||
profile_list->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
profiles_hbc->add_child(profile_list);
|
||||
profile_list->connect("item_selected", this, "_profile_selected");
|
||||
|
||||
profile_actions[PROFILE_SET] = memnew(Button(TTR("Make Current")));
|
||||
profiles_hbc->add_child(profile_actions[PROFILE_SET]);
|
||||
profile_actions[PROFILE_SET]->set_disabled(true);
|
||||
profile_actions[PROFILE_SET]->connect("pressed", this, "_profile_action", varray(PROFILE_SET));
|
||||
|
||||
profile_actions[PROFILE_ERASE] = memnew(Button(TTR("Remove")));
|
||||
profiles_hbc->add_child(profile_actions[PROFILE_ERASE]);
|
||||
profile_actions[PROFILE_ERASE]->set_disabled(true);
|
||||
profile_actions[PROFILE_ERASE]->connect("pressed", this, "_profile_action", varray(PROFILE_ERASE));
|
||||
|
||||
profiles_hbc->add_child(memnew(VSeparator));
|
||||
|
||||
profile_actions[PROFILE_NEW] = memnew(Button(TTR("New")));
|
||||
profiles_hbc->add_child(profile_actions[PROFILE_NEW]);
|
||||
profile_actions[PROFILE_NEW]->connect("pressed", this, "_profile_action", varray(PROFILE_NEW));
|
||||
|
||||
profiles_hbc->add_child(memnew(VSeparator));
|
||||
|
||||
profile_actions[PROFILE_IMPORT] = memnew(Button(TTR("Import")));
|
||||
profiles_hbc->add_child(profile_actions[PROFILE_IMPORT]);
|
||||
profile_actions[PROFILE_IMPORT]->connect("pressed", this, "_profile_action", varray(PROFILE_IMPORT));
|
||||
|
||||
profile_actions[PROFILE_EXPORT] = memnew(Button(TTR("Export")));
|
||||
profiles_hbc->add_child(profile_actions[PROFILE_EXPORT]);
|
||||
profile_actions[PROFILE_EXPORT]->set_disabled(true);
|
||||
profile_actions[PROFILE_EXPORT]->connect("pressed", this, "_profile_action", varray(PROFILE_EXPORT));
|
||||
|
||||
main_vbc->add_margin_child(TTR("Available Profiles"), profiles_hbc);
|
||||
|
||||
h_split = memnew(HSplitContainer);
|
||||
h_split->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
main_vbc->add_child(h_split);
|
||||
|
||||
VBoxContainer *class_list_vbc = memnew(VBoxContainer);
|
||||
h_split->add_child(class_list_vbc);
|
||||
class_list_vbc->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
class_list = memnew(Tree);
|
||||
class_list_vbc->add_margin_child(TTR("Enabled Classes"), class_list, true);
|
||||
class_list->set_hide_root(true);
|
||||
class_list->set_hide_folding(true);
|
||||
class_list->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
|
||||
class_list->connect("cell_selected", this, "_class_list_item_selected");
|
||||
class_list->connect("item_edited", this, "_class_list_item_edited", varray(), CONNECT_DEFERRED);
|
||||
|
||||
VBoxContainer *property_list_vbc = memnew(VBoxContainer);
|
||||
h_split->add_child(property_list_vbc);
|
||||
property_list_vbc->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
property_list = memnew(Tree);
|
||||
property_list_vbc->add_margin_child(TTR("Class Options"), property_list, true);
|
||||
property_list->set_hide_root(true);
|
||||
property_list->set_hide_folding(true);
|
||||
property_list->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
|
||||
property_list->connect("item_edited", this, "_property_item_edited", varray(), CONNECT_DEFERRED);
|
||||
|
||||
new_profile_dialog = memnew(ConfirmationDialog);
|
||||
new_profile_dialog->set_title(TTR("New profile name:"));
|
||||
new_profile_name = memnew(LineEdit);
|
||||
new_profile_dialog->add_child(new_profile_name);
|
||||
new_profile_name->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
|
||||
add_child(new_profile_dialog);
|
||||
new_profile_dialog->connect("confirmed", this, "_create_new_profile");
|
||||
new_profile_dialog->register_text_enter(new_profile_name);
|
||||
new_profile_dialog->get_ok()->set_text(TTR("Create"));
|
||||
|
||||
erase_profile_dialog = memnew(ConfirmationDialog);
|
||||
add_child(erase_profile_dialog);
|
||||
erase_profile_dialog->set_title(TTR("Erase Profile"));
|
||||
erase_profile_dialog->connect("confirmed", this, "_erase_selected_profile");
|
||||
|
||||
import_profiles = memnew(EditorFileDialog);
|
||||
add_child(import_profiles);
|
||||
import_profiles->set_mode(EditorFileDialog::MODE_OPEN_FILES);
|
||||
import_profiles->add_filter("*.profile; Godot Feature Profile");
|
||||
import_profiles->connect("files_selected", this, "_import_profiles");
|
||||
import_profiles->set_title(TTR("Import Profile(s)"));
|
||||
import_profiles->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
||||
|
||||
export_profile = memnew(EditorFileDialog);
|
||||
add_child(export_profile);
|
||||
export_profile->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
||||
export_profile->add_filter("*.profile; Godot Feature Profile");
|
||||
export_profile->connect("file_selected", this, "_export_profile");
|
||||
export_profile->set_title(TTR("Export Profile"));
|
||||
export_profile->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
||||
|
||||
set_title(TTR("Manage Editor Feature Profiles"));
|
||||
EDITOR_DEF("_default_feature_profile", "");
|
||||
|
||||
update_timer = memnew(Timer);
|
||||
update_timer->set_wait_time(1); //wait a second before updating editor
|
||||
add_child(update_timer);
|
||||
update_timer->connect("timeout", this, "_emit_current_profile_changed");
|
||||
update_timer->set_one_shot(true);
|
||||
|
||||
updating_features = false;
|
||||
|
||||
singleton = this;
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
#ifndef EDITOR_FEATURE_PROFILE_H
|
||||
#define EDITOR_FEATURE_PROFILE_H
|
||||
|
||||
#include "core/os/file_access.h"
|
||||
#include "core/reference.h"
|
||||
#include "editor/editor_file_dialog.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/option_button.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/gui/split_container.h"
|
||||
#include "scene/gui/tree.h"
|
||||
|
||||
class EditorFeatureProfile : public Reference {
|
||||
GDCLASS(EditorFeatureProfile, Reference);
|
||||
|
||||
public:
|
||||
enum Feature {
|
||||
FEATURE_3D,
|
||||
FEATURE_SCRIPT,
|
||||
FEATURE_ASSET_LIB,
|
||||
FEATURE_SCENE_TREE,
|
||||
FEATURE_IMPORT_DOCK,
|
||||
FEATURE_NODE_DOCK,
|
||||
FEATURE_FILESYSTEM_DOCK,
|
||||
FEATURE_MAX
|
||||
};
|
||||
|
||||
private:
|
||||
Set<StringName> disabled_classes;
|
||||
Set<StringName> disabled_editors;
|
||||
Map<StringName, Set<StringName> > disabled_properties;
|
||||
|
||||
bool features_disabled[FEATURE_MAX];
|
||||
static const char *feature_names[FEATURE_MAX];
|
||||
static const char *feature_identifiers[FEATURE_MAX];
|
||||
|
||||
String _get_feature_name(Feature p_feature) { return get_feature_name(p_feature); }
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_disable_class(const StringName &p_class, bool p_disabled);
|
||||
bool is_class_disabled(const StringName &p_class) const;
|
||||
|
||||
void set_disable_class_editor(const StringName &p_class, bool p_disabled);
|
||||
bool is_class_editor_disabled(const StringName &p_class) const;
|
||||
|
||||
void set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled);
|
||||
bool is_class_property_disabled(const StringName &p_class, const StringName &p_property) const;
|
||||
bool has_class_properties_disabled(const StringName &p_class) const;
|
||||
|
||||
void set_disable_feature(Feature p_feature, bool p_disable);
|
||||
bool is_feature_disabled(Feature p_feature) const;
|
||||
|
||||
Error save_to_file(const String &p_path);
|
||||
Error load_from_file(const String &p_path);
|
||||
|
||||
static String get_feature_name(Feature p_feature);
|
||||
|
||||
EditorFeatureProfile();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(EditorFeatureProfile::Feature)
|
||||
|
||||
class EditorFeatureProfileManager : public AcceptDialog {
|
||||
|
||||
GDCLASS(EditorFeatureProfileManager, AcceptDialog);
|
||||
|
||||
enum Action {
|
||||
PROFILE_CLEAR,
|
||||
PROFILE_SET,
|
||||
PROFILE_IMPORT,
|
||||
PROFILE_EXPORT,
|
||||
PROFILE_NEW,
|
||||
PROFILE_ERASE,
|
||||
PROFILE_MAX
|
||||
};
|
||||
|
||||
enum ClassOptions {
|
||||
CLASS_OPTION_DISABLE_EDITOR
|
||||
};
|
||||
|
||||
ConfirmationDialog *erase_profile_dialog;
|
||||
ConfirmationDialog *new_profile_dialog;
|
||||
LineEdit *new_profile_name;
|
||||
|
||||
LineEdit *current_profile_name;
|
||||
OptionButton *profile_list;
|
||||
Button *profile_actions[PROFILE_MAX];
|
||||
|
||||
HSplitContainer *h_split;
|
||||
|
||||
Tree *class_list;
|
||||
Tree *property_list;
|
||||
|
||||
EditorFileDialog *import_profiles;
|
||||
EditorFileDialog *export_profile;
|
||||
|
||||
void _profile_action(int p_action);
|
||||
void _profile_selected(int p_what);
|
||||
|
||||
String current_profile;
|
||||
void _update_profile_list(const String &p_select_profile = String());
|
||||
void _update_selected_profile();
|
||||
void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected);
|
||||
|
||||
Ref<EditorFeatureProfile> current;
|
||||
Ref<EditorFeatureProfile> edited;
|
||||
|
||||
void _erase_selected_profile();
|
||||
void _create_new_profile();
|
||||
String _get_selected_profile();
|
||||
|
||||
void _import_profiles(const Vector<String> &p_paths);
|
||||
void _export_profile(const String &p_path);
|
||||
|
||||
bool updating_features;
|
||||
|
||||
void _class_list_item_selected();
|
||||
void _class_list_item_edited();
|
||||
void _property_item_edited();
|
||||
void _save_and_update();
|
||||
|
||||
Timer *update_timer;
|
||||
void _emit_current_profile_changed();
|
||||
|
||||
static EditorFeatureProfileManager *singleton;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
Ref<EditorFeatureProfile> get_current_profile();
|
||||
void notify_changed();
|
||||
|
||||
static EditorFeatureProfileManager *get_singleton() { return singleton; }
|
||||
EditorFeatureProfileManager();
|
||||
};
|
||||
|
||||
#endif // EDITOR_FEATURE_PROFILE_H
|
|
@ -1370,6 +1370,30 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit
|
|||
ped->added_editors.clear();
|
||||
}
|
||||
|
||||
bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName &p_property) {
|
||||
|
||||
Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
|
||||
if (profile.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringName class_name = object->get_class();
|
||||
|
||||
while (class_name != StringName()) {
|
||||
|
||||
if (profile->is_class_property_disabled(class_name, p_property)) {
|
||||
return true;
|
||||
}
|
||||
if (profile->is_class_disabled(class_name)) {
|
||||
//won't see properties of a disabled class
|
||||
return true;
|
||||
}
|
||||
class_name = ClassDB::get_parent_class(class_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorInspector::update_tree() {
|
||||
|
||||
//to update properly if all is refreshed
|
||||
|
@ -1513,7 +1537,7 @@ void EditorInspector::update_tree() {
|
|||
|
||||
continue;
|
||||
|
||||
} else if (!(p.usage & PROPERTY_USAGE_EDITOR))
|
||||
} else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name))
|
||||
continue;
|
||||
|
||||
if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && VS::get_singleton()->is_low_end())
|
||||
|
@ -2132,6 +2156,10 @@ void EditorInspector::_node_removed(Node *p_node) {
|
|||
|
||||
void EditorInspector::_notification(int p_what) {
|
||||
|
||||
if (p_what == NOTIFICATION_READY) {
|
||||
EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
|
||||
}
|
||||
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
if (sub_inspector) {
|
||||
|
@ -2238,6 +2266,11 @@ String EditorInspector::get_object_class() const {
|
|||
return object_class;
|
||||
}
|
||||
|
||||
void EditorInspector::_feature_profile_changed() {
|
||||
|
||||
update_tree();
|
||||
}
|
||||
|
||||
void EditorInspector::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(""), DEFVAL(false));
|
||||
|
@ -2254,6 +2287,7 @@ void EditorInspector::_bind_methods() {
|
|||
ClassDB::bind_method("_resource_selected", &EditorInspector::_resource_selected);
|
||||
ClassDB::bind_method("_object_id_selected", &EditorInspector::_object_id_selected);
|
||||
ClassDB::bind_method("_vscroll_changed", &EditorInspector::_vscroll_changed);
|
||||
ClassDB::bind_method("_feature_profile_changed", &EditorInspector::_feature_profile_changed);
|
||||
|
||||
ClassDB::bind_method("refresh", &EditorInspector::refresh);
|
||||
|
||||
|
|
|
@ -323,6 +323,10 @@ class EditorInspector : public ScrollContainer {
|
|||
|
||||
void _vscroll_changed(double);
|
||||
|
||||
void _feature_profile_changed();
|
||||
|
||||
bool _is_property_disabled_by_feature_profile(const StringName &p_property);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
|
|
@ -306,7 +306,14 @@ void EditorNode::_notification(int p_what) {
|
|||
VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport_rid(), true);
|
||||
VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(), true);
|
||||
|
||||
_editor_select(EDITOR_3D);
|
||||
feature_profile_manager->notify_changed();
|
||||
|
||||
if (!main_editor_buttons[EDITOR_3D]->is_visible()) { //may be hidden due to feature profile
|
||||
_editor_select(EDITOR_2D);
|
||||
} else {
|
||||
_editor_select(EDITOR_3D);
|
||||
}
|
||||
|
||||
_update_debug_options();
|
||||
|
||||
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
|
||||
|
@ -558,11 +565,14 @@ void EditorNode::_editor_select_next() {
|
|||
|
||||
int editor = _get_current_main_editor();
|
||||
|
||||
if (editor == editor_table.size() - 1) {
|
||||
editor = 0;
|
||||
} else {
|
||||
editor++;
|
||||
}
|
||||
do {
|
||||
if (editor == editor_table.size() - 1) {
|
||||
editor = 0;
|
||||
} else {
|
||||
editor++;
|
||||
}
|
||||
} while (main_editor_buttons[editor]->is_visible());
|
||||
|
||||
_editor_select(editor);
|
||||
}
|
||||
|
||||
|
@ -570,11 +580,14 @@ void EditorNode::_editor_select_prev() {
|
|||
|
||||
int editor = _get_current_main_editor();
|
||||
|
||||
if (editor == 0) {
|
||||
editor = editor_table.size() - 1;
|
||||
} else {
|
||||
editor--;
|
||||
}
|
||||
do {
|
||||
if (editor == 0) {
|
||||
editor = editor_table.size() - 1;
|
||||
} else {
|
||||
editor--;
|
||||
}
|
||||
} while (main_editor_buttons[editor]->is_visible());
|
||||
|
||||
_editor_select(editor);
|
||||
}
|
||||
|
||||
|
@ -1440,17 +1453,45 @@ void EditorNode::_dialog_action(String p_file) {
|
|||
|
||||
bool EditorNode::item_has_editor(Object *p_object) {
|
||||
|
||||
if (_is_class_editor_disabled_by_feature_profile(p_object->get_class())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return editor_data.get_subeditors(p_object).size() > 0;
|
||||
}
|
||||
|
||||
void EditorNode::edit_item_resource(RES p_resource) {
|
||||
edit_item(p_resource.ptr());
|
||||
}
|
||||
|
||||
bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName &p_class) {
|
||||
|
||||
Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
|
||||
if (profile.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringName class_name = p_class;
|
||||
|
||||
while (class_name != StringName()) {
|
||||
|
||||
if (profile->is_class_editor_disabled(class_name)) {
|
||||
return true;
|
||||
}
|
||||
class_name = ClassDB::get_parent_class(class_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorNode::edit_item(Object *p_object) {
|
||||
|
||||
Vector<EditorPlugin *> sub_plugins;
|
||||
|
||||
if (p_object) {
|
||||
if (_is_class_editor_disabled_by_feature_profile(p_object->get_class())) {
|
||||
return;
|
||||
}
|
||||
sub_plugins = editor_data.get_subeditors(p_object);
|
||||
}
|
||||
|
||||
|
@ -1640,6 +1681,12 @@ void EditorNode::_edit_current() {
|
|||
|
||||
EditorPlugin *main_plugin = editor_data.get_editor(current_obj);
|
||||
|
||||
for (int i = 0; i < editor_table.size(); i++) {
|
||||
if (editor_table[i] == main_plugin && !main_editor_buttons[i]->is_visible()) {
|
||||
main_plugin = NULL; //if button is not visible, then no plugin active
|
||||
}
|
||||
}
|
||||
|
||||
if (main_plugin) {
|
||||
|
||||
// special case if use of external editor is true
|
||||
|
@ -1677,7 +1724,11 @@ void EditorNode::_edit_current() {
|
|||
}
|
||||
}
|
||||
|
||||
Vector<EditorPlugin *> sub_plugins = editor_data.get_subeditors(current_obj);
|
||||
Vector<EditorPlugin *> sub_plugins;
|
||||
|
||||
if (!_is_class_editor_disabled_by_feature_profile(current_obj->get_class())) {
|
||||
sub_plugins = editor_data.get_subeditors(current_obj);
|
||||
}
|
||||
|
||||
if (!sub_plugins.empty()) {
|
||||
_display_top_editors(false);
|
||||
|
@ -1685,7 +1736,6 @@ void EditorNode::_edit_current() {
|
|||
_set_top_editors(sub_plugins);
|
||||
_set_editing_top_editors(current_obj);
|
||||
_display_top_editors(true);
|
||||
|
||||
} else if (!editor_plugins_over->get_plugins_list().empty()) {
|
||||
|
||||
hide_top_editors();
|
||||
|
@ -2358,6 +2408,11 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
|
|||
|
||||
export_template_manager->popup_manager();
|
||||
|
||||
} break;
|
||||
case SETTINGS_MANAGE_FEATURE_PROFILES: {
|
||||
|
||||
feature_profile_manager->popup_centered_ratio();
|
||||
|
||||
} break;
|
||||
case SETTINGS_TOGGLE_FULLSCREEN: {
|
||||
|
||||
|
@ -2541,10 +2596,13 @@ void EditorNode::_editor_select(int p_which) {
|
|||
if (selecting || changing_scene)
|
||||
return;
|
||||
|
||||
selecting = true;
|
||||
|
||||
ERR_FAIL_INDEX(p_which, editor_table.size());
|
||||
|
||||
if (!main_editor_buttons[p_which]->is_visible()) //button hidden, no editor
|
||||
return;
|
||||
|
||||
selecting = true;
|
||||
|
||||
for (int i = 0; i < main_editor_buttons.size(); i++) {
|
||||
main_editor_buttons[i]->set_pressed(i == p_which);
|
||||
}
|
||||
|
@ -3284,6 +3342,7 @@ void EditorNode::register_editor_types() {
|
|||
ClassDB::register_class<EditorProperty>();
|
||||
ClassDB::register_class<AnimationTrackEditPlugin>();
|
||||
ClassDB::register_class<ScriptCreateDialog>();
|
||||
ClassDB::register_class<EditorFeatureProfile>();
|
||||
|
||||
// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
|
||||
ClassDB::register_class<EditorScenePostImport>();
|
||||
|
@ -3821,7 +3880,13 @@ void EditorNode::_update_dock_slots_visibility() {
|
|||
} else {
|
||||
for (int i = 0; i < DOCK_SLOT_MAX; i++) {
|
||||
|
||||
if (dock_slot[i]->get_tab_count())
|
||||
int tabs_visible = 0;
|
||||
for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) {
|
||||
if (!dock_slot[i]->get_tab_hidden(j)) {
|
||||
tabs_visible++;
|
||||
}
|
||||
}
|
||||
if (tabs_visible)
|
||||
dock_slot[i]->show();
|
||||
else
|
||||
dock_slot[i]->hide();
|
||||
|
@ -4806,6 +4871,39 @@ void EditorNode::_resource_loaded(RES p_resource, const String &p_path) {
|
|||
singleton->editor_folding.load_resource_folding(p_resource, p_path);
|
||||
}
|
||||
|
||||
void EditorNode::_feature_profile_changed() {
|
||||
|
||||
Ref<EditorFeatureProfile> profile = feature_profile_manager->get_current_profile();
|
||||
TabContainer *import_tabs = cast_to<TabContainer>(import_dock->get_parent());
|
||||
TabContainer *node_tabs = cast_to<TabContainer>(node_dock->get_parent());
|
||||
TabContainer *fs_tabs = cast_to<TabContainer>(filesystem_dock->get_parent());
|
||||
if (profile.is_valid()) {
|
||||
|
||||
import_tabs->set_tab_hidden(import_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_IMPORT_DOCK));
|
||||
node_tabs->set_tab_hidden(node_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_NODE_DOCK));
|
||||
fs_tabs->set_tab_hidden(filesystem_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_FILESYSTEM_DOCK));
|
||||
|
||||
main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
|
||||
main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
|
||||
main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
|
||||
if (profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB)) {
|
||||
_editor_select(EDITOR_2D);
|
||||
}
|
||||
} else {
|
||||
|
||||
import_tabs->set_tab_hidden(import_dock->get_index(), false);
|
||||
node_tabs->set_tab_hidden(node_dock->get_index(), false);
|
||||
fs_tabs->set_tab_hidden(filesystem_dock->get_index(), false);
|
||||
import_dock->set_visible(true);
|
||||
node_dock->set_visible(true);
|
||||
filesystem_dock->set_visible(true);
|
||||
main_editor_buttons[EDITOR_3D]->set_visible(true);
|
||||
main_editor_buttons[EDITOR_ASSETLIB]->set_visible(true);
|
||||
}
|
||||
|
||||
_update_dock_slots_visibility();
|
||||
}
|
||||
|
||||
void EditorNode::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method("_menu_option", &EditorNode::_menu_option);
|
||||
|
@ -4884,6 +4982,7 @@ void EditorNode::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("_video_driver_selected"), &EditorNode::_video_driver_selected);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_resources_changed"), &EditorNode::_resources_changed);
|
||||
ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &EditorNode::_feature_profile_changed);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("play_pressed"));
|
||||
ADD_SIGNAL(MethodInfo("pause_pressed"));
|
||||
|
@ -5397,8 +5496,11 @@ EditorNode::EditorNode() {
|
|||
export_template_manager = memnew(ExportTemplateManager);
|
||||
gui_base->add_child(export_template_manager);
|
||||
|
||||
feature_profile_manager = memnew(EditorFeatureProfileManager);
|
||||
gui_base->add_child(feature_profile_manager);
|
||||
about = memnew(EditorAbout);
|
||||
gui_base->add_child(about);
|
||||
feature_profile_manager->connect("current_feature_profile_changed", this, "_feature_profile_changed");
|
||||
|
||||
warning = memnew(AcceptDialog);
|
||||
gui_base->add_child(warning);
|
||||
|
@ -5554,6 +5656,10 @@ EditorNode::EditorNode() {
|
|||
}
|
||||
p->add_separator();
|
||||
|
||||
p->add_item(TTR("Manage Editor Features"), SETTINGS_MANAGE_FEATURE_PROFILES);
|
||||
|
||||
p->add_separator();
|
||||
|
||||
p->add_item(TTR("Manage Export Templates"), SETTINGS_MANAGE_EXPORT_TEMPLATES);
|
||||
|
||||
// Help Menu
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "editor/editor_about.h"
|
||||
#include "editor/editor_data.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_feature_profile.h"
|
||||
#include "editor/editor_folding.h"
|
||||
#include "editor/editor_inspector.h"
|
||||
#include "editor/editor_log.h"
|
||||
|
@ -84,7 +85,6 @@
|
|||
#include "scene/gui/tool_button.h"
|
||||
#include "scene/gui/tree.h"
|
||||
#include "scene/gui/viewport_container.h"
|
||||
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
@ -175,6 +175,7 @@ private:
|
|||
SETTINGS_EDITOR_DATA_FOLDER,
|
||||
SETTINGS_EDITOR_CONFIG_FOLDER,
|
||||
SETTINGS_MANAGE_EXPORT_TEMPLATES,
|
||||
SETTINGS_MANAGE_FEATURE_PROFILES,
|
||||
SETTINGS_PICK_MAIN_SCENE,
|
||||
SETTINGS_TOGGLE_FULLSCREEN,
|
||||
SETTINGS_HELP,
|
||||
|
@ -294,6 +295,7 @@ private:
|
|||
ProjectSettingsEditor *project_settings;
|
||||
EditorFileDialog *file;
|
||||
ExportTemplateManager *export_template_manager;
|
||||
EditorFeatureProfileManager *feature_profile_manager;
|
||||
EditorFileDialog *file_templates;
|
||||
EditorFileDialog *file_export;
|
||||
EditorFileDialog *file_export_lib;
|
||||
|
@ -610,6 +612,9 @@ private:
|
|||
|
||||
void _resources_changed(const PoolVector<String> &p_resources);
|
||||
|
||||
void _feature_profile_changed();
|
||||
bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
|
|
@ -832,6 +832,13 @@ void EditorSettings::create() {
|
|||
} else {
|
||||
dir->change_dir("..");
|
||||
}
|
||||
|
||||
if (dir->change_dir("feature_profiles") != OK) {
|
||||
dir->make_dir("feature_profiles");
|
||||
} else {
|
||||
dir->change_dir("..");
|
||||
}
|
||||
|
||||
_create_script_templates(dir->get_current_dir().plus_file("script_templates"));
|
||||
|
||||
if (dir->change_dir("projects") != OK) {
|
||||
|
@ -1157,6 +1164,11 @@ String EditorSettings::get_cache_dir() const {
|
|||
return cache_dir;
|
||||
}
|
||||
|
||||
String EditorSettings::get_feature_profiles_dir() const {
|
||||
|
||||
return get_settings_dir().plus_file("feature_profiles");
|
||||
}
|
||||
|
||||
// Metadata
|
||||
|
||||
void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
|
||||
|
|
|
@ -169,6 +169,7 @@ public:
|
|||
String get_text_editor_themes_dir() const;
|
||||
String get_script_templates_dir() const;
|
||||
String get_cache_dir() const;
|
||||
String get_feature_profiles_dir() const;
|
||||
|
||||
void set_project_metadata(const String &p_section, const String &p_key, Variant p_data);
|
||||
Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const;
|
||||
|
|
|
@ -86,6 +86,13 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
|
|||
// Create all items for the files in the subdirectory
|
||||
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
|
||||
for (int i = 0; i < p_dir->get_file_count(); i++) {
|
||||
|
||||
String file_type = p_dir->get_file_type(i);
|
||||
|
||||
if (_is_file_type_disabled_by_feature_profile(file_type)) {
|
||||
//if type is disabled, file wont be displayed.
|
||||
continue;
|
||||
}
|
||||
String file_name = p_dir->get_file(i);
|
||||
|
||||
if (searched_string.length() > 0) {
|
||||
|
@ -276,6 +283,7 @@ void FileSystemDock::_notification(int p_what) {
|
|||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
|
||||
|
||||
EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_fs_changed");
|
||||
EditorResourcePreview::get_singleton()->connect("preview_invalidated", this, "_preview_invalidated");
|
||||
|
@ -520,6 +528,26 @@ void FileSystemDock::_set_file_display(bool p_active) {
|
|||
_update_file_list(true);
|
||||
}
|
||||
|
||||
bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName &p_class) {
|
||||
|
||||
Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
|
||||
if (profile.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringName class_name = p_class;
|
||||
|
||||
while (class_name != StringName()) {
|
||||
|
||||
if (profile->is_class_disabled(class_name)) {
|
||||
return true;
|
||||
}
|
||||
class_name = ClassDB::get_parent_class(class_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) {
|
||||
|
||||
if (matches->size() > p_max_items)
|
||||
|
@ -541,6 +569,11 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *
|
|||
fi.import_broken = !p_path->get_file_import_is_valid(i);
|
||||
fi.import_status = 0;
|
||||
|
||||
if (_is_file_type_disabled_by_feature_profile(fi.type)) {
|
||||
//this type is disabled, will not appear here
|
||||
continue;
|
||||
}
|
||||
|
||||
matches->push_back(fi);
|
||||
if (matches->size() > p_max_items)
|
||||
return;
|
||||
|
@ -2259,6 +2292,11 @@ void FileSystemDock::_update_import_dock() {
|
|||
import_dock_needs_update = false;
|
||||
}
|
||||
|
||||
void FileSystemDock::_feature_profile_changed() {
|
||||
|
||||
_update_display_mode(true);
|
||||
}
|
||||
|
||||
void FileSystemDock::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_file_list_gui_input"), &FileSystemDock::_file_list_gui_input);
|
||||
|
@ -2308,6 +2346,8 @@ void FileSystemDock::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("_file_multi_selected"), &FileSystemDock::_file_multi_selected);
|
||||
ClassDB::bind_method(D_METHOD("_update_import_dock"), &FileSystemDock::_update_import_dock);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &FileSystemDock::_feature_profile_changed);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::POOL_STRING_ARRAY, "files")));
|
||||
ADD_SIGNAL(MethodInfo("open"));
|
||||
|
||||
|
|
|
@ -268,6 +268,10 @@ private:
|
|||
|
||||
Vector<String> _tree_get_selected(bool remove_self_inclusion = true);
|
||||
|
||||
bool _is_file_type_disabled_by_feature_profile(const StringName &p_class);
|
||||
|
||||
void _feature_profile_changed();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
|
|
@ -290,12 +290,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
switch (p_tool) {
|
||||
|
||||
case TOOL_BATCH_RENAME: {
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
Tree *tree = scene_tree->get_scene_tree();
|
||||
if (tree->is_anything_selected()) {
|
||||
rename_dialog->popup_centered();
|
||||
}
|
||||
} break;
|
||||
case TOOL_RENAME: {
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
Tree *tree = scene_tree->get_scene_tree();
|
||||
if (tree->is_anything_selected()) {
|
||||
tree->grab_focus();
|
||||
|
@ -304,6 +310,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_NEW: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
String preferred = "";
|
||||
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
|
||||
|
||||
|
@ -319,6 +328,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_INSTANCE: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
Node *scene = edited_scene;
|
||||
|
||||
if (!scene) {
|
||||
|
@ -332,10 +344,17 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_REPLACE: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
create_dialog->popup_create(false, true);
|
||||
} break;
|
||||
case TOOL_ATTACH_SCRIPT: {
|
||||
|
||||
if (!profile_allow_script_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
if (selection.empty())
|
||||
break;
|
||||
|
@ -377,6 +396,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_CLEAR_SCRIPT: {
|
||||
|
||||
if (!profile_allow_script_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
Array selection = editor_selection->get_selected_nodes();
|
||||
|
||||
if (selection.empty())
|
||||
|
@ -404,6 +427,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
case TOOL_MOVE_UP:
|
||||
case TOOL_MOVE_DOWN: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!scene_tree->get_selected())
|
||||
break;
|
||||
|
||||
|
@ -464,6 +491,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_DUPLICATE: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!edited_scene)
|
||||
break;
|
||||
|
||||
|
@ -533,6 +564,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_REPARENT: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!scene_tree->get_selected())
|
||||
break;
|
||||
|
||||
|
@ -559,6 +594,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_MAKE_ROOT: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Node *> nodes = editor_selection->get_selected_node_list();
|
||||
ERR_FAIL_COND(nodes.size() != 1);
|
||||
|
||||
|
@ -616,6 +655,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_MULTI_EDIT: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
Node *root = EditorNode::get_singleton()->get_edited_scene();
|
||||
if (!root)
|
||||
break;
|
||||
|
@ -630,6 +673,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
|
||||
case TOOL_ERASE: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Node *> remove_list = editor_selection->get_selected_node_list();
|
||||
|
||||
if (remove_list.empty())
|
||||
|
@ -649,10 +696,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
case TOOL_MERGE_FROM_SCENE: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
EditorNode::get_singleton()->merge_from_scene();
|
||||
} break;
|
||||
case TOOL_NEW_SCENE_FROM: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
Node *scene = editor_data->get_edited_scene_root();
|
||||
|
||||
if (!scene) {
|
||||
|
@ -704,6 +759,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
new_scene_from_dialog->set_title(TTR("Save New Scene As..."));
|
||||
} break;
|
||||
case TOOL_COPY_NODE_PATH: {
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
List<Node *>::Element *e = selection.front();
|
||||
if (e) {
|
||||
|
@ -723,6 +779,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
|
||||
} break;
|
||||
case TOOL_SCENE_EDITABLE_CHILDREN: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
List<Node *>::Element *e = selection.front();
|
||||
if (e) {
|
||||
|
@ -740,6 +801,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
}
|
||||
} break;
|
||||
case TOOL_SCENE_USE_PLACEHOLDER: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
List<Node *>::Element *e = selection.front();
|
||||
if (e) {
|
||||
|
@ -760,6 +826,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
}
|
||||
} break;
|
||||
case TOOL_SCENE_MAKE_LOCAL: {
|
||||
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
List<Node *>::Element *e = selection.front();
|
||||
if (e) {
|
||||
|
@ -782,6 +853,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
}
|
||||
} break;
|
||||
case TOOL_SCENE_OPEN: {
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
List<Node *>::Element *e = selection.front();
|
||||
if (e) {
|
||||
|
@ -792,9 +864,17 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
}
|
||||
} break;
|
||||
case TOOL_SCENE_CLEAR_INHERITANCE: {
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
clear_inherit_confirm->popup_centered_minsize();
|
||||
} break;
|
||||
case TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM: {
|
||||
if (!profile_allow_editing) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
List<Node *>::Element *e = selection.front();
|
||||
if (e) {
|
||||
|
@ -807,6 +887,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
}
|
||||
} break;
|
||||
case TOOL_SCENE_OPEN_INHERITED: {
|
||||
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
List<Node *>::Element *e = selection.front();
|
||||
if (e) {
|
||||
|
@ -894,6 +975,8 @@ void SceneTreeDock::_notification(int p_what) {
|
|||
break;
|
||||
first_enter = false;
|
||||
|
||||
EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed");
|
||||
|
||||
CanvasItemEditorPlugin *canvas_item_plugin = Object::cast_to<CanvasItemEditorPlugin>(editor_data->get_editor("2D"));
|
||||
if (canvas_item_plugin) {
|
||||
canvas_item_plugin->get_canvas_item_editor()->connect("item_lock_status_changed", scene_tree, "_update_tree");
|
||||
|
@ -1640,7 +1723,12 @@ void SceneTreeDock::_delete_confirm() {
|
|||
}
|
||||
|
||||
void SceneTreeDock::_update_script_button() {
|
||||
if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 0) {
|
||||
|
||||
if (!profile_allow_script_editing) {
|
||||
|
||||
button_create_script->hide();
|
||||
button_clear_script->hide();
|
||||
} else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 0) {
|
||||
button_create_script->hide();
|
||||
button_clear_script->hide();
|
||||
} else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 1) {
|
||||
|
@ -2074,11 +2162,14 @@ void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) {
|
|||
}
|
||||
|
||||
void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
|
||||
|
||||
if (!EditorNode::get_singleton()->get_edited_scene()) {
|
||||
|
||||
menu->clear();
|
||||
menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
|
||||
menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
|
||||
if (profile_allow_editing) {
|
||||
menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
|
||||
menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
|
||||
}
|
||||
|
||||
menu->set_size(Size2(1, 1));
|
||||
menu->set_position(p_menu_pos);
|
||||
|
@ -2098,71 +2189,87 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
|
|||
|
||||
Node *selected = selection[0];
|
||||
|
||||
subresources.clear();
|
||||
menu_subresources->clear();
|
||||
menu_subresources->set_size(Size2(1, 1));
|
||||
_add_children_to_popup(selection.front()->get(), 0);
|
||||
if (menu->get_item_count() > 0)
|
||||
menu->add_separator();
|
||||
if (profile_allow_editing) {
|
||||
subresources.clear();
|
||||
menu_subresources->clear();
|
||||
menu_subresources->set_size(Size2(1, 1));
|
||||
_add_children_to_popup(selection.front()->get(), 0);
|
||||
if (menu->get_item_count() > 0)
|
||||
menu->add_separator();
|
||||
|
||||
menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
|
||||
menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
|
||||
menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
|
||||
menu->add_separator();
|
||||
}
|
||||
existing_script = selected->get_script();
|
||||
}
|
||||
|
||||
if (!existing_script.is_valid()) {
|
||||
menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT);
|
||||
}
|
||||
if (selection.size() > 1 || existing_script.is_valid()) {
|
||||
menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT);
|
||||
menu->add_icon_shortcut(get_icon("ScriptExtend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/extend_script"), TOOL_ATTACH_SCRIPT);
|
||||
if (profile_allow_script_editing) {
|
||||
|
||||
if (!existing_script.is_valid()) {
|
||||
menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT);
|
||||
}
|
||||
if (selection.size() > 1 || existing_script.is_valid()) {
|
||||
menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT);
|
||||
menu->add_icon_shortcut(get_icon("ScriptExtend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/extend_script"), TOOL_ATTACH_SCRIPT);
|
||||
}
|
||||
}
|
||||
|
||||
menu->add_separator();
|
||||
if (selection.size() == 1) {
|
||||
menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/rename"), TOOL_RENAME);
|
||||
}
|
||||
menu->add_icon_shortcut(get_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE);
|
||||
|
||||
if (scene_tree->get_selected() != edited_scene) {
|
||||
if (profile_allow_editing) {
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("MoveUp", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_up"), TOOL_MOVE_UP);
|
||||
menu->add_icon_shortcut(get_icon("MoveDown", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_down"), TOOL_MOVE_DOWN);
|
||||
menu->add_icon_shortcut(get_icon("Duplicate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/duplicate"), TOOL_DUPLICATE);
|
||||
menu->add_icon_shortcut(get_icon("Reparent", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/reparent"), TOOL_REPARENT);
|
||||
if (selection.size() == 1) {
|
||||
menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/rename"), TOOL_RENAME);
|
||||
}
|
||||
menu->add_icon_shortcut(get_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE);
|
||||
|
||||
if (scene_tree->get_selected() != edited_scene) {
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("MoveUp", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_up"), TOOL_MOVE_UP);
|
||||
menu->add_icon_shortcut(get_icon("MoveDown", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_down"), TOOL_MOVE_DOWN);
|
||||
menu->add_icon_shortcut(get_icon("Duplicate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/duplicate"), TOOL_DUPLICATE);
|
||||
menu->add_icon_shortcut(get_icon("Reparent", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/reparent"), TOOL_REPARENT);
|
||||
}
|
||||
}
|
||||
if (selection.size() == 1) {
|
||||
|
||||
menu->add_icon_shortcut(get_icon("NewRoot", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/make_root"), TOOL_MAKE_ROOT);
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("Blend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE);
|
||||
menu->add_icon_shortcut(get_icon("CreateNewSceneFrom", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM);
|
||||
menu->add_separator();
|
||||
if (profile_allow_editing) {
|
||||
menu->add_icon_shortcut(get_icon("NewRoot", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/make_root"), TOOL_MAKE_ROOT);
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("Blend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE);
|
||||
menu->add_icon_shortcut(get_icon("CreateNewSceneFrom", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM);
|
||||
menu->add_separator();
|
||||
}
|
||||
menu->add_icon_shortcut(get_icon("CopyNodePath", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/copy_node_path"), TOOL_COPY_NODE_PATH);
|
||||
|
||||
bool is_external = (selection[0]->get_filename() != "");
|
||||
if (is_external) {
|
||||
bool is_inherited = selection[0]->get_scene_inherited_state() != NULL;
|
||||
bool is_top_level = selection[0]->get_owner() == NULL;
|
||||
if (is_inherited && is_top_level) {
|
||||
menu->add_separator();
|
||||
menu->add_item(TTR("Clear Inheritance"), TOOL_SCENE_CLEAR_INHERITANCE);
|
||||
if (profile_allow_editing) {
|
||||
menu->add_item(TTR("Clear Inheritance"), TOOL_SCENE_CLEAR_INHERITANCE);
|
||||
}
|
||||
menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open in Editor"), TOOL_SCENE_OPEN_INHERITED);
|
||||
} else if (!is_top_level) {
|
||||
menu->add_separator();
|
||||
bool editable = EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(selection[0]);
|
||||
bool placeholder = selection[0]->get_scene_instance_load_placeholder();
|
||||
menu->add_check_item(TTR("Editable Children"), TOOL_SCENE_EDITABLE_CHILDREN);
|
||||
menu->add_check_item(TTR("Load As Placeholder"), TOOL_SCENE_USE_PLACEHOLDER);
|
||||
menu->add_item(TTR("Make Local"), TOOL_SCENE_MAKE_LOCAL);
|
||||
if (profile_allow_editing) {
|
||||
menu->add_check_item(TTR("Editable Children"), TOOL_SCENE_EDITABLE_CHILDREN);
|
||||
menu->add_check_item(TTR("Load As Placeholder"), TOOL_SCENE_USE_PLACEHOLDER);
|
||||
menu->add_item(TTR("Make Local"), TOOL_SCENE_MAKE_LOCAL);
|
||||
}
|
||||
menu->add_icon_item(get_icon("Load", "EditorIcons"), TTR("Open in Editor"), TOOL_SCENE_OPEN);
|
||||
menu->set_item_checked(menu->get_item_idx_from_text(TTR("Editable Children")), editable);
|
||||
menu->set_item_checked(menu->get_item_idx_from_text(TTR("Load As Placeholder")), placeholder);
|
||||
if (profile_allow_editing) {
|
||||
menu->set_item_checked(menu->get_item_idx_from_text(TTR("Editable Children")), editable);
|
||||
menu->set_item_checked(menu->get_item_idx_from_text(TTR("Load As Placeholder")), placeholder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selection.size() > 1) {
|
||||
if (profile_allow_editing && selection.size() > 1) {
|
||||
//this is not a commonly used action, it makes no sense for it to be where it was nor always present.
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/batch_rename"), TOOL_BATCH_RENAME);
|
||||
|
@ -2170,8 +2277,10 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
|
|||
menu->add_separator();
|
||||
menu->add_icon_item(get_icon("Help", "EditorIcons"), TTR("Open documentation"), TOOL_OPEN_DOCUMENTATION);
|
||||
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("Remove", "EditorIcons"), ED_SHORTCUT("scene_tree/delete", TTR("Delete Node(s)"), KEY_DELETE), TOOL_ERASE);
|
||||
if (profile_allow_editing) {
|
||||
menu->add_separator();
|
||||
menu->add_icon_shortcut(get_icon("Remove", "EditorIcons"), ED_SHORTCUT("scene_tree/delete", TTR("Delete Node(s)"), KEY_DELETE), TOOL_ERASE);
|
||||
}
|
||||
menu->set_size(Size2(1, 1));
|
||||
menu->set_position(p_menu_pos);
|
||||
menu->popup();
|
||||
|
@ -2321,6 +2430,30 @@ void SceneTreeDock::_favorite_root_selected(const String &p_class) {
|
|||
_tool_selected(TOOL_CREATE_FAVORITE, false);
|
||||
}
|
||||
|
||||
void SceneTreeDock::_feature_profile_changed() {
|
||||
|
||||
Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
|
||||
|
||||
if (profile.is_valid()) {
|
||||
|
||||
profile_allow_editing = !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCENE_TREE);
|
||||
profile_allow_script_editing = !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT);
|
||||
|
||||
button_add->set_visible(profile_allow_editing);
|
||||
button_instance->set_visible(profile_allow_editing);
|
||||
scene_tree->set_can_rename(profile_allow_editing);
|
||||
|
||||
} else {
|
||||
button_add->set_visible(true);
|
||||
button_instance->set_visible(true);
|
||||
scene_tree->set_can_rename(true);
|
||||
profile_allow_editing = true;
|
||||
profile_allow_script_editing = true;
|
||||
}
|
||||
|
||||
_update_script_button();
|
||||
}
|
||||
|
||||
void SceneTreeDock::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_tool_selected"), &SceneTreeDock::_tool_selected, DEFVAL(false));
|
||||
|
@ -2353,6 +2486,7 @@ void SceneTreeDock::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("_update_script_button"), &SceneTreeDock::_update_script_button);
|
||||
ClassDB::bind_method(D_METHOD("_favorite_root_selected"), &SceneTreeDock::_favorite_root_selected);
|
||||
ClassDB::bind_method(D_METHOD("_update_create_root_dialog"), &SceneTreeDock::_update_create_root_dialog);
|
||||
ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &SceneTreeDock::_feature_profile_changed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("instance"), &SceneTreeDock::instance);
|
||||
|
||||
|
@ -2537,6 +2671,9 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
|
|||
set_process_input(true);
|
||||
set_process(true);
|
||||
|
||||
profile_allow_editing = true;
|
||||
profile_allow_script_editing = true;
|
||||
|
||||
EDITOR_DEF("interface/editors/show_scene_tree_root_selection", true);
|
||||
EDITOR_DEF("_use_favorites_root_selection", false);
|
||||
}
|
||||
|
|
|
@ -212,6 +212,11 @@ class SceneTreeDock : public VBoxContainer {
|
|||
void _update_create_root_dialog();
|
||||
void _favorite_root_selected(const String &p_class);
|
||||
|
||||
void _feature_profile_changed();
|
||||
|
||||
bool profile_allow_editing;
|
||||
bool profile_allow_script_editing;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
|
|
@ -60,7 +60,7 @@ def process_file(f, fname):
|
|||
lc = 1
|
||||
while (l):
|
||||
|
||||
patterns = ['RTR(\"', 'TTR(\"']
|
||||
patterns = ['RTR(\"', 'TTR(\"','TTRC(\"']
|
||||
idx = 0
|
||||
pos = 0
|
||||
while (pos >= 0):
|
||||
|
|
|
@ -127,6 +127,9 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
|
|||
// Activate the clicked tab.
|
||||
pos.x -= tabs_ofs_cache;
|
||||
for (int i = first_tab_cache; i <= last_tab_cache; i++) {
|
||||
if (get_tab_hidden(i)) {
|
||||
continue;
|
||||
}
|
||||
int tab_width = _get_tab_width(i);
|
||||
if (pos.x < tab_width) {
|
||||
if (!get_tab_disabled(i)) {
|
||||
|
@ -216,6 +219,9 @@ void TabContainer::_notification(int p_what) {
|
|||
// Check if all tabs would fit into the header area.
|
||||
int all_tabs_width = 0;
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
if (get_tab_hidden(i)) {
|
||||
continue;
|
||||
}
|
||||
int tab_width = _get_tab_width(i);
|
||||
all_tabs_width += tab_width;
|
||||
|
||||
|
@ -241,6 +247,9 @@ void TabContainer::_notification(int p_what) {
|
|||
all_tabs_width = 0;
|
||||
Vector<int> tab_widths;
|
||||
for (int i = first_tab_cache; i < tabs.size(); i++) {
|
||||
if (get_tab_hidden(i)) {
|
||||
continue;
|
||||
}
|
||||
int tab_width = _get_tab_width(i);
|
||||
if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0)
|
||||
break;
|
||||
|
@ -267,6 +276,9 @@ void TabContainer::_notification(int p_what) {
|
|||
// Draw all visible tabs.
|
||||
int x = 0;
|
||||
for (int i = 0; i < tab_widths.size(); i++) {
|
||||
if (get_tab_hidden(i)) {
|
||||
continue;
|
||||
}
|
||||
Ref<StyleBox> tab_style;
|
||||
Color font_color;
|
||||
if (get_tab_disabled(i + first_tab_cache)) {
|
||||
|
@ -354,7 +366,7 @@ int TabContainer::_get_tab_width(int p_index) const {
|
|||
|
||||
ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
|
||||
Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
|
||||
if (!control || control->is_set_as_toplevel())
|
||||
if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index))
|
||||
return 0;
|
||||
|
||||
// Get the width of the text displayed on the tab.
|
||||
|
@ -765,6 +777,36 @@ bool TabContainer::get_tab_disabled(int p_tab) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
|
||||
|
||||
Control *child = _get_tab(p_tab);
|
||||
ERR_FAIL_COND(!child);
|
||||
child->set_meta("_tab_hidden", p_hidden);
|
||||
update();
|
||||
for (int i = 0; i < get_tab_count(); i++) {
|
||||
int try_tab = (p_tab + 1 + i) % get_tab_count();
|
||||
if (get_tab_disabled(try_tab) || get_tab_hidden(try_tab)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
set_current_tab(try_tab);
|
||||
return;
|
||||
}
|
||||
|
||||
//assumed no other tab can be switched to, just hide
|
||||
child->hide();
|
||||
}
|
||||
|
||||
bool TabContainer::get_tab_hidden(int p_tab) const {
|
||||
|
||||
Control *child = _get_tab(p_tab);
|
||||
ERR_FAIL_COND_V(!child, false);
|
||||
if (child->has_meta("_tab_hidden"))
|
||||
return child->get_meta("_tab_hidden");
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void TabContainer::get_translatable_strings(List<String> *p_strings) const {
|
||||
|
||||
Vector<Control *> tabs = _get_tabs();
|
||||
|
|
|
@ -96,6 +96,9 @@ public:
|
|||
void set_tab_disabled(int p_tab, bool p_disabled);
|
||||
bool get_tab_disabled(int p_tab) const;
|
||||
|
||||
void set_tab_hidden(int p_tab, bool p_hidden);
|
||||
bool get_tab_hidden(int p_tab) const;
|
||||
|
||||
int get_tab_count() const;
|
||||
void set_current_tab(int p_current);
|
||||
int get_current_tab() const;
|
||||
|
|
Loading…
Reference in New Issue