Skip to content

Commit

Permalink
Add ability to edit editor feature profiles
Browse files Browse the repository at this point in the history
Allows enabling/disabling parts of the editor and storing/loading profiles for that.
  • Loading branch information
reduz committed Apr 8, 2019
1 parent 9ab17b6 commit a20235a
Show file tree
Hide file tree
Showing 24 changed files with 1,585 additions and 66 deletions.
13 changes: 13 additions & 0 deletions core/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions core/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class ClassDB {

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);
Expand Down
32 changes: 29 additions & 3 deletions core/os/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,17 +571,43 @@ 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());
memdelete(f);
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);
Expand Down
3 changes: 2 additions & 1 deletion core/os/file_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class FileAccess {
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) {
Expand Down
18 changes: 18 additions & 0 deletions core/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions core/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class String {
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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions core/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
24 changes: 24 additions & 0 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions editor/create_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit a20235a

Please sign in to comment.