Merge pull request #3324 from TheHX/pr-property-editor

Better search for SectionedPropertyEditor, added "All" section
This commit is contained in:
Rémi Verschelde 2016-01-15 14:01:55 +01:00
commit bd968ce2f8
6 changed files with 88 additions and 124 deletions

View File

@ -60,9 +60,6 @@ void ProjectSettings::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) { if (p_what==NOTIFICATION_ENTER_TREE) {
search_button->set_icon(get_icon("Zoom","EditorIcons"));
clear_button->set_icon(get_icon("Close","EditorIcons"));
translation_list->connect("button_pressed",this,"_translation_delete"); translation_list->connect("button_pressed",this,"_translation_delete");
_update_actions(); _update_actions();
popup_add->add_icon_item(get_icon("Keyboard","EditorIcons"),"Key",InputEvent::KEY); popup_add->add_icon_item(get_icon("Keyboard","EditorIcons"),"Key",InputEvent::KEY);
@ -93,7 +90,9 @@ void ProjectSettings::_notification(int p_what) {
autoload_file_open->add_filter("*."+E->get()); autoload_file_open->add_filter("*."+E->get());
} }
} else if (p_what==NOTIFICATION_POST_POPUP) {
globals_editor->clear_search_box();
} }
} }
@ -1339,32 +1338,6 @@ void ProjectSettings::_update_autoload() {
} }
void ProjectSettings::_toggle_search_bar(bool p_pressed) {
globals_editor->get_property_editor()->set_use_filter(p_pressed);
if (p_pressed) {
search_bar->show();
add_prop_bar->hide();
search_box->grab_focus();
search_box->select_all();
} else {
search_bar->hide();
add_prop_bar->show();
}
}
void ProjectSettings::_clear_search_box() {
if (search_box->get_text()=="")
return;
search_box->clear();
globals_editor->get_property_editor()->update_tree();
}
void ProjectSettings::_bind_methods() { void ProjectSettings::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_item_selected"),&ProjectSettings::_item_selected); ObjectTypeDB::bind_method(_MD("_item_selected"),&ProjectSettings::_item_selected);
@ -1407,9 +1380,6 @@ void ProjectSettings::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_autoload_delete"),&ProjectSettings::_autoload_delete); ObjectTypeDB::bind_method(_MD("_autoload_delete"),&ProjectSettings::_autoload_delete);
ObjectTypeDB::bind_method(_MD("_autoload_edited"),&ProjectSettings::_autoload_edited); ObjectTypeDB::bind_method(_MD("_autoload_edited"),&ProjectSettings::_autoload_edited);
ObjectTypeDB::bind_method(_MD("_clear_search_box"),&ProjectSettings::_clear_search_box);
ObjectTypeDB::bind_method(_MD("_toggle_search_bar"),&ProjectSettings::_toggle_search_bar);
} }
ProjectSettings::ProjectSettings(EditorData *p_data) { ProjectSettings::ProjectSettings(EditorData *p_data) {
@ -1440,77 +1410,50 @@ ProjectSettings::ProjectSettings(EditorData *p_data) {
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
props_base->add_child(hbc); props_base->add_child(hbc);
search_button = memnew( ToolButton );
search_button->set_toggle_mode(true);
search_button->set_pressed(false);
search_button->set_text("Search");
hbc->add_child(search_button);
search_button->connect("toggled",this,"_toggle_search_bar");
hbc->add_child( memnew( VSeparator ) );
add_prop_bar = memnew( HBoxContainer );
add_prop_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
hbc->add_child(add_prop_bar);
Label *l = memnew( Label ); Label *l = memnew( Label );
add_prop_bar->add_child(l); hbc->add_child(l);
l->set_text("Category:"); l->set_text("Category:");
category = memnew( LineEdit ); category = memnew( LineEdit );
category->set_h_size_flags(Control::SIZE_EXPAND_FILL); category->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_prop_bar->add_child(category); hbc->add_child(category);
category->connect("text_entered",this,"_item_adds"); category->connect("text_entered",this,"_item_adds");
l = memnew( Label ); l = memnew( Label );
add_prop_bar->add_child(l); hbc->add_child(l);
l->set_text("Property:"); l->set_text("Property:");
property = memnew( LineEdit ); property = memnew( LineEdit );
property->set_h_size_flags(Control::SIZE_EXPAND_FILL); property->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_prop_bar->add_child(property); hbc->add_child(property);
property->connect("text_entered",this,"_item_adds"); property->connect("text_entered",this,"_item_adds");
l = memnew( Label ); l = memnew( Label );
add_prop_bar->add_child(l); hbc->add_child(l);
l->set_text("Type:"); l->set_text("Type:");
type = memnew( OptionButton ); type = memnew( OptionButton );
type->set_h_size_flags(Control::SIZE_EXPAND_FILL); type->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_prop_bar->add_child(type); hbc->add_child(type);
type->add_item("bool"); type->add_item("bool");
type->add_item("int"); type->add_item("int");
type->add_item("float"); type->add_item("float");
type->add_item("string"); type->add_item("string");
Button *add = memnew( Button ); Button *add = memnew( Button );
add_prop_bar->add_child(add); hbc->add_child(add);
add->set_text("Add"); add->set_text("Add");
add->connect("pressed",this,"_item_add"); add->connect("pressed",this,"_item_add");
Button *del = memnew( Button ); Button *del = memnew( Button );
add_prop_bar->add_child(del); hbc->add_child(del);
del->set_text("Del"); del->set_text("Del");
del->connect("pressed",this,"_item_del"); del->connect("pressed",this,"_item_del");
search_bar = memnew( HBoxContainer );
search_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
hbc->add_child(search_bar);
search_bar->hide();
search_box = memnew( LineEdit );
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
search_bar->add_child(search_box);
clear_button = memnew( ToolButton );
search_bar->add_child(clear_button);
clear_button->connect("pressed",this,"_clear_search_box");
globals_editor = memnew( SectionedPropertyEditor ); globals_editor = memnew( SectionedPropertyEditor );
props_base->add_child(globals_editor); props_base->add_child(globals_editor);
//globals_editor->hide_top_label(); //globals_editor->hide_top_label();
globals_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); globals_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
globals_editor->get_property_editor()->register_text_enter(search_box);
globals_editor->get_property_editor()->set_capitalize_paths(false); globals_editor->get_property_editor()->set_capitalize_paths(false);
globals_editor->get_property_editor()->get_scene_tree()->connect("cell_selected",this,"_item_selected"); globals_editor->get_property_editor()->get_scene_tree()->connect("cell_selected",this,"_item_selected");
globals_editor->get_property_editor()->connect("property_toggled",this,"_item_checked",varray(),CONNECT_DEFERRED); globals_editor->get_property_editor()->connect("property_toggled",this,"_item_checked",varray(),CONNECT_DEFERRED);

View File

@ -48,12 +48,6 @@ class ProjectSettings : public AcceptDialog {
UndoRedo *undo_redo; UndoRedo *undo_redo;
SectionedPropertyEditor *globals_editor; SectionedPropertyEditor *globals_editor;
HBoxContainer *search_bar;
ToolButton *search_button;
LineEdit *search_box;
ToolButton *clear_button;
HBoxContainer *add_prop_bar;
ConfirmationDialog *message; ConfirmationDialog *message;
LineEdit *category; LineEdit *category;
LineEdit *property; LineEdit *property;
@ -142,9 +136,6 @@ class ProjectSettings : public AcceptDialog {
void _translation_res_option_changed(); void _translation_res_option_changed();
void _translation_res_option_delete(Object *p_item,int p_column, int p_button); void _translation_res_option_delete(Object *p_item,int p_column, int p_button);
void _toggle_search_bar(bool p_pressed);
void _clear_search_box();
ProjectSettings(); ProjectSettings();

View File

@ -3777,6 +3777,10 @@ class SectionedPropertyEditorFilter : public Object {
for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
PropertyInfo pi=E->get(); PropertyInfo pi=E->get();
if (section=="")
p_list->push_back(pi);
int sp = pi.name.find("/"); int sp = pi.name.find("/");
if (sp!=-1) { if (sp!=-1) {
String ss = pi.name.substr(0,sp); String ss = pi.name.substr(0,sp);
@ -3786,7 +3790,7 @@ class SectionedPropertyEditorFilter : public Object {
p_list->push_back(pi); p_list->push_back(pi);
} }
} else { } else {
if (section=="") if (section=="global")
p_list->push_back(pi); p_list->push_back(pi);
} }
} }
@ -3811,10 +3815,18 @@ public:
}; };
void SectionedPropertyEditor::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
clear_button->set_icon(get_icon("Close", "EditorIcons"));
}
}
void SectionedPropertyEditor::_bind_methods() { void SectionedPropertyEditor::_bind_methods() {
ObjectTypeDB::bind_method("_section_selected",&SectionedPropertyEditor::_section_selected); ObjectTypeDB::bind_method("_section_selected",&SectionedPropertyEditor::_section_selected);
ObjectTypeDB::bind_method("_clear_search_box",&SectionedPropertyEditor::clear_search_box);
} }
void SectionedPropertyEditor::_section_selected(int p_which) { void SectionedPropertyEditor::_section_selected(int p_which) {
@ -3822,9 +3834,30 @@ void SectionedPropertyEditor::_section_selected(int p_which) {
filter->set_section( sections->get_item_metadata(p_which) ); filter->set_section( sections->get_item_metadata(p_which) );
} }
void SectionedPropertyEditor::clear_search_box() {
if (search_box->get_text().strip_edges()=="")
return;
search_box->clear();
editor->update_tree();
}
String SectionedPropertyEditor::get_current_section() const { String SectionedPropertyEditor::get_current_section() const {
return sections->get_item_metadata( sections->get_current() ); String section = sections->get_item_metadata( sections->get_current() );
if (section=="") {
String name = editor->get_selected_path();
int sp = name.find("/");
if (sp!=-1)
section = name.substr(0, sp);
}
return section;
} }
String SectionedPropertyEditor::get_full_item_path(const String& p_item) { String SectionedPropertyEditor::get_full_item_path(const String& p_item) {
@ -3844,11 +3877,20 @@ void SectionedPropertyEditor::edit(Object* p_object) {
sections->clear(); sections->clear();
Set<String> existing_sections; Set<String> existing_sections;
existing_sections.insert("");
sections->add_item("All");
sections->set_item_metadata(0, "");
for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
PropertyInfo pi=E->get(); PropertyInfo pi=E->get();
if (pi.usage&PROPERTY_USAGE_CATEGORY) if (pi.usage&PROPERTY_USAGE_CATEGORY)
continue; continue;
if ( !(pi.usage&PROPERTY_USAGE_EDITOR) )
continue;
if (pi.name.find(":")!=-1 || pi.name=="script/script") if (pi.name.find(":")!=-1 || pi.name=="script/script")
continue; continue;
int sp = pi.name.find("/"); int sp = pi.name.find("/");
@ -3861,10 +3903,10 @@ void SectionedPropertyEditor::edit(Object* p_object) {
} }
} else { } else {
if (!existing_sections.has("")) { if (!existing_sections.has("global")) {
existing_sections.insert(""); existing_sections.insert("global");
sections->add_item("Global"); sections->add_item("Global");
sections->set_item_metadata(sections->get_item_count()-1,""); sections->set_item_metadata(sections->get_item_count()-1,"global");
} }
} }
@ -3889,6 +3931,8 @@ PropertyEditor *SectionedPropertyEditor::get_property_editor() {
SectionedPropertyEditor::SectionedPropertyEditor() { SectionedPropertyEditor::SectionedPropertyEditor() {
add_constant_override("separation", 8);
VBoxContainer *left_vb = memnew( VBoxContainer); VBoxContainer *left_vb = memnew( VBoxContainer);
left_vb->set_custom_minimum_size(Size2(160,0)); left_vb->set_custom_minimum_size(Size2(160,0));
add_child(left_vb); add_child(left_vb);
@ -3903,7 +3947,21 @@ SectionedPropertyEditor::SectionedPropertyEditor() {
add_child(right_vb); add_child(right_vb);
filter = memnew( SectionedPropertyEditorFilter ); filter = memnew( SectionedPropertyEditorFilter );
HBoxContainer *hbc = memnew( HBoxContainer );
right_vb->add_margin_child("Search:",hbc);
search_box = memnew( LineEdit );
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(search_box);
clear_button = memnew( ToolButton );
hbc->add_child(clear_button);
clear_button->connect("pressed", this, "_clear_search_box");
editor = memnew( PropertyEditor ); editor = memnew( PropertyEditor );
editor->register_text_enter(search_box);
editor->set_use_filter(true);
editor->set_v_size_flags(SIZE_EXPAND_FILL); editor->set_v_size_flags(SIZE_EXPAND_FILL);
right_vb->add_margin_child("Properties:",editor,true); right_vb->add_margin_child("Properties:",editor,true);

View File

@ -259,12 +259,16 @@ class SectionedPropertyEditor : public HBoxContainer {
OBJ_TYPE(SectionedPropertyEditor,HBoxContainer); OBJ_TYPE(SectionedPropertyEditor,HBoxContainer);
ItemList *sections; ItemList *sections;
SectionedPropertyEditorFilter *filter; SectionedPropertyEditorFilter *filter;
LineEdit *search_box;
ToolButton *clear_button;
PropertyEditor *editor; PropertyEditor *editor;
static void _bind_methods();
void _section_selected(int p_which); void _section_selected(int p_which);
protected:
void _notification(int p_what);
static void _bind_methods();
public: public:
PropertyEditor *get_property_editor(); PropertyEditor *get_property_editor();
@ -272,6 +276,8 @@ public:
String get_full_item_path(const String& p_item); String get_full_item_path(const String& p_item);
String get_current_section() const; String get_current_section() const;
void clear_search_box();
SectionedPropertyEditor(); SectionedPropertyEditor();
~SectionedPropertyEditor(); ~SectionedPropertyEditor();
}; };

View File

@ -73,9 +73,6 @@ void EditorSettingsDialog::popup_edit_settings() {
property_editor->edit(EditorSettings::get_singleton()); property_editor->edit(EditorSettings::get_singleton());
property_editor->get_property_editor()->update_tree(); property_editor->get_property_editor()->update_tree();
search_box->select_all();
search_box->grab_focus();
popup_centered_ratio(0.7); popup_centered_ratio(0.7);
} }
@ -248,22 +245,15 @@ void EditorSettingsDialog::_update_plugins() {
} }
void EditorSettingsDialog::_clear_search_box() {
if (search_box->get_text()=="")
return;
search_box->clear();
property_editor->get_property_editor()->update_tree();
}
void EditorSettingsDialog::_notification(int p_what) { void EditorSettingsDialog::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) { if (p_what==NOTIFICATION_ENTER_TREE) {
rescan_plugins->set_icon(get_icon("Reload","EditorIcons")); rescan_plugins->set_icon(get_icon("Reload","EditorIcons"));
clear_button->set_icon(get_icon("Close","EditorIcons"));
_update_plugins(); _update_plugins();
} else if (p_what==NOTIFICATION_POST_POPUP) {
property_editor->clear_search_box();
} }
} }
@ -275,7 +265,6 @@ void EditorSettingsDialog::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_plugin_settings"),&EditorSettingsDialog::_plugin_settings); ObjectTypeDB::bind_method(_MD("_plugin_settings"),&EditorSettingsDialog::_plugin_settings);
ObjectTypeDB::bind_method(_MD("_plugin_edited"),&EditorSettingsDialog::_plugin_edited); ObjectTypeDB::bind_method(_MD("_plugin_edited"),&EditorSettingsDialog::_plugin_edited);
ObjectTypeDB::bind_method(_MD("_plugin_install"),&EditorSettingsDialog::_plugin_install); ObjectTypeDB::bind_method(_MD("_plugin_install"),&EditorSettingsDialog::_plugin_install);
ObjectTypeDB::bind_method(_MD("_clear_search_box"),&EditorSettingsDialog::_clear_search_box);
} }
EditorSettingsDialog::EditorSettingsDialog() { EditorSettingsDialog::EditorSettingsDialog() {
@ -286,38 +275,17 @@ EditorSettingsDialog::EditorSettingsDialog() {
add_child(tabs); add_child(tabs);
set_child_rect(tabs); set_child_rect(tabs);
VBoxContainer *vbc = memnew( VBoxContainer );
tabs->add_child(vbc);
vbc->set_name("General");
HBoxContainer *hbc = memnew( HBoxContainer );
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
vbc->add_child(hbc);
Label *l = memnew( Label );
l->set_text("Search: ");
hbc->add_child(l);
search_box = memnew( LineEdit );
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
hbc->add_child(search_box);
clear_button = memnew( ToolButton );
hbc->add_child(clear_button);
clear_button->connect("pressed",this,"_clear_search_box");
property_editor = memnew( SectionedPropertyEditor ); property_editor = memnew( SectionedPropertyEditor );
//property_editor->hide_top_label(); //property_editor->hide_top_label();
property_editor->get_property_editor()->set_use_filter(true); property_editor->set_name("General");
property_editor->get_property_editor()->register_text_enter(search_box);
property_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); property_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
vbc->add_child(property_editor); tabs->add_child(property_editor);
vbc = memnew( VBoxContainer ); VBoxContainer *vbc = memnew( VBoxContainer );
tabs->add_child(vbc); tabs->add_child(vbc);
vbc->set_name("Plugins"); vbc->set_name("Plugins");
hbc = memnew( HBoxContainer ); HBoxContainer *hbc = memnew( HBoxContainer );
vbc->add_child(hbc); vbc->add_child(hbc);
hbc->add_child( memnew( Label("Plugin List: "))); hbc->add_child( memnew( Label("Plugin List: ")));
hbc->add_spacer(); hbc->add_spacer();

View File

@ -51,8 +51,6 @@ class EditorSettingsDialog : public AcceptDialog {
Button *rescan_plugins; Button *rescan_plugins;
Tree *plugins; Tree *plugins;
LineEdit *search_box;
ToolButton *clear_button;
SectionedPropertyEditor *property_editor; SectionedPropertyEditor *property_editor;
Timer *timer; Timer *timer;