Fix Project Settings dialog add/delete global variable

This commit is contained in:
Franklin Sobrinho 2016-03-06 11:22:21 -03:00
parent f8c666085e
commit 48524384d6
3 changed files with 81 additions and 28 deletions

View File

@ -60,6 +60,8 @@ void ProjectSettings::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
globals_editor->edit(Globals::get_singleton());
search_button->set_icon(get_icon("Zoom","EditorIcons"));
clear_button->set_icon(get_icon("Close","EditorIcons"));
@ -566,8 +568,7 @@ void ProjectSettings::popup_project_settings() {
//popup_centered(Size2(500,400));
popup_centered_ratio();
globals_editor->edit(NULL);
globals_editor->edit(Globals::get_singleton());
globals_editor->update_category_list();
_update_translations();
_update_autoload();
plugin_settings->update_plugins();
@ -605,37 +606,45 @@ void ProjectSettings::_item_add() {
case 3: value=""; break;
}
String catname = category->get_text();
String catname = category->get_text().strip_edges();
/*if (!catname.is_valid_identifier()) {
message->set_text("Invalid Category.\nValid characters: a-z,A-Z,0-9 or _");
message->popup_centered(Size2(300,100));
return;
}*/
String propname = property->get_text();
String propname = property->get_text().strip_edges();
/*if (!propname.is_valid_identifier()) {
message->set_text("Invalid Property.\nValid characters: a-z,A-Z,0-9 or _");
message->popup_centered(Size2(300,100));
return;
}*/
String name = catname+"/"+propname;
String name = catname!="" ? catname+"/"+propname : propname;
Globals::get_singleton()->set(name,value);
globals_editor->edit(NULL);
globals_editor->edit(Globals::get_singleton());
globals_editor->set_current_section(catname);
globals_editor->update_category_list();
_settings_changed();
}
void ProjectSettings::_item_del() {
String catname = category->get_text();
String catname = category->get_text().strip_edges();
//ERR_FAIL_COND(!catname.is_valid_identifier());
String propname = property->get_text();
String propname = property->get_text().strip_edges();
//ERR_FAIL_COND(!propname.is_valid_identifier());
String name = catname+"/"+propname;
Globals::get_singleton()->set(name,Variant());
globals_editor->get_property_editor()->update_tree();
String name = catname!="" ? catname+"/"+propname : propname;
Globals::get_singleton()->set(name,Variant());
globals_editor->set_current_section(catname);
globals_editor->update_category_list();
_settings_changed();
}
void ProjectSettings::_action_adds(String) {

View File

@ -3840,14 +3840,34 @@ void SectionedPropertyEditor::_section_selected(int p_which) {
filter->set_section( sections->get_item_metadata(p_which) );
}
void SectionedPropertyEditor::set_current_section(const String& p_section) {
int section_idx = sections->find_metadata(p_section);
if (section_idx==sections->get_current())
return;
if (section_idx!=-1) {
sections->select(section_idx);
_section_selected(section_idx);
} else if (sections->get_item_count()) {
sections->select(0);
_section_selected(0);
}
}
String SectionedPropertyEditor::get_current_section() const {
return sections->get_item_metadata( sections->get_current() );
if (sections->get_current()!=-1)
return sections->get_item_metadata( sections->get_current() );
else
return "";
}
String SectionedPropertyEditor::get_full_item_path(const String& p_item) {
String base = sections->get_item_metadata( sections->get_current() );
String base = get_current_section();
if (base!="")
return base+"/"+p_item;
else
@ -3856,17 +3876,44 @@ String SectionedPropertyEditor::get_full_item_path(const String& p_item) {
void SectionedPropertyEditor::edit(Object* p_object) {
List<PropertyInfo> pinfo;
if (p_object)
p_object->get_property_list(&pinfo);
if (p_object) {
obj=p_object->get_instance_ID();
update_category_list();
} else {
sections->clear();
}
filter->set_edited(p_object);
editor->edit(filter);
sections->select(0);
_section_selected(0);
}
void SectionedPropertyEditor::update_category_list() {
String selected_category=get_current_section();
sections->clear();
Object *o = ObjectDB::get_instance(obj);
if (!o)
return;
List<PropertyInfo> pinfo;
o->get_property_list(&pinfo);
Set<String> existing_sections;
for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
PropertyInfo pi=E->get();
if (pi.usage&PROPERTY_USAGE_CATEGORY)
continue;
else if ( !(pi.usage&PROPERTY_USAGE_EDITOR) )
continue;
if (pi.name.find(":")!=-1 || pi.name=="script/script")
continue;
int sp = pi.name.find("/");
@ -3885,19 +3932,9 @@ void SectionedPropertyEditor::edit(Object* p_object) {
sections->set_item_metadata(sections->get_item_count()-1,"");
}
}
}
//sections->sort_items_by_text();
filter->set_edited(p_object);
editor->edit(filter);
sections->select(0);
_section_selected(0);
set_current_section(selected_category);
}
PropertyEditor *SectionedPropertyEditor::get_property_editor() {

View File

@ -257,6 +257,9 @@ class SectionedPropertyEditor : public HBoxContainer {
OBJ_TYPE(SectionedPropertyEditor,HBoxContainer);
ObjectID obj;
ItemList *sections;
SectionedPropertyEditorFilter *filter;
PropertyEditor *editor;
@ -270,8 +273,12 @@ public:
PropertyEditor *get_property_editor();
void edit(Object* p_object);
String get_full_item_path(const String& p_item);
void set_current_section(const String& p_section);
String get_current_section() const;
void update_category_list();
SectionedPropertyEditor();
~SectionedPropertyEditor();
};