summaryrefslogtreecommitdiff
path: root/tools/editor/property_editor.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-12-15 23:39:36 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-12-15 23:39:36 -0300
commita1142225bf513e4afe0527ca604486d3988449cc (patch)
treed88f0e4bb1ca235f37640df6eae84e666b474ad4 /tools/editor/property_editor.cpp
parent035bb03331fba3fedbc5d968916fec33ea8b6aa4 (diff)
-split view of property editor and editor settings
Diffstat (limited to 'tools/editor/property_editor.cpp')
-rw-r--r--tools/editor/property_editor.cpp171
1 files changed, 171 insertions, 0 deletions
diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp
index c44cfa3d6e..1893c175a1 100644
--- a/tools/editor/property_editor.cpp
+++ b/tools/editor/property_editor.cpp
@@ -3638,3 +3638,174 @@ PropertyEditor::~PropertyEditor()
}
+/////////////////////////////
+
+
+
+
+
+class SectionedPropertyEditorFilter : public Object {
+
+ OBJ_TYPE( SectionedPropertyEditorFilter, Object );
+
+ Object *edited;
+ String section;
+
+ bool _set(const StringName& p_name, const Variant& p_value) {
+
+ if (!edited)
+ return false;
+
+ String name=p_name;
+ if (section!="") {
+ name=section+"/"+name;
+ }
+
+ bool valid;
+ edited->set(name,p_value,&valid);
+ return valid;
+ }
+
+ bool _get(const StringName& p_name,Variant &r_ret) const{
+
+ if (!edited)
+ return false;
+
+ String name=p_name;
+ if (section!="") {
+ name=section+"/"+name;
+ }
+
+ bool valid=false;
+
+ r_ret=edited->get(name,&valid);
+ return valid;
+
+
+ }
+ void _get_property_list(List<PropertyInfo> *p_list) const{
+
+ if (!edited)
+ return;
+
+ List<PropertyInfo> pinfo;
+ edited->get_property_list(&pinfo);
+ for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
+
+ PropertyInfo pi=E->get();
+ int sp = pi.name.find("/");
+ if (sp!=-1) {
+ String ss = pi.name.substr(0,sp);
+
+ if (ss==section) {
+ pi.name=pi.name.substr(sp+1,pi.name.length());
+ p_list->push_back(pi);
+ }
+ } else {
+ if (section=="")
+ p_list->push_back(pi);
+ }
+ }
+
+ }
+public:
+
+ void set_section(const String& p_section) {
+
+ section=p_section;
+ _change_notify();
+ }
+
+ void set_edited(Object* p_edited) {
+ edited=p_edited;
+ _change_notify();
+ }
+
+ SectionedPropertyEditorFilter() {
+ edited=NULL;
+ }
+
+};
+
+
+void SectionedPropertyEditor::_bind_methods() {
+
+ ObjectTypeDB::bind_method("_section_selected",&SectionedPropertyEditor::_section_selected);
+}
+
+void SectionedPropertyEditor::_section_selected(int p_which) {
+
+ filter->set_section( sections->get_item_metadata(p_which) );
+}
+
+void SectionedPropertyEditor::edit(Object* p_object) {
+
+ List<PropertyInfo> pinfo;
+ if (p_object)
+ p_object->get_property_list(&pinfo);
+ sections->clear();
+
+ 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;
+ if (pi.name.find(":")!=-1 || pi.name=="script/script")
+ continue;
+ int sp = pi.name.find("/");
+ if (sp!=-1) {
+ String sname=pi.name.substr(0,sp);
+ if (!existing_sections.has(sname)) {
+ existing_sections.insert(sname);
+ sections->add_item(sname.capitalize());
+ sections->set_item_metadata(sections->get_item_count()-1,sname);
+ }
+
+ } else {
+ if (!existing_sections.has("")) {
+ existing_sections.insert("");
+ sections->add_item("Global");
+ 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);
+
+}
+
+PropertyEditor *SectionedPropertyEditor::get_property_editor() {
+
+ return editor;
+}
+
+SectionedPropertyEditor::SectionedPropertyEditor() {
+
+ sections = memnew( ItemList );
+ add_child(sections);
+ sections->set_custom_minimum_size(Size2(160,0));
+ filter = memnew( SectionedPropertyEditorFilter );
+ editor = memnew( PropertyEditor );
+ editor->get_scene_tree()->set_column_titles_visible(false);
+ add_child(editor);
+ editor->set_h_size_flags(SIZE_EXPAND_FILL);
+ editor->hide_top_label();
+
+ sections->connect("item_selected",this,"_section_selected");
+
+}
+
+SectionedPropertyEditor::~SectionedPropertyEditor() {
+
+ memdelete(filter);
+}