summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarynate <mary.w.nate@gmail.com>2014-06-17 13:34:48 +0800
committermarynate <mary.w.nate@gmail.com>2014-06-17 13:35:14 +0800
commit9a75d3175e9deb83f35ca5bec367c94faeb94bdb (patch)
treedaae05b168fef762a75289363ae5fd90c706e2c4
parent703004f830f39adcde9b9565f1aa49d1b10e8d27 (diff)
Search filesystem by name or path; Remove extension filter; Use toolbutton for clear search term
-rw-r--r--tools/editor/scenes_dock.cpp59
-rw-r--r--tools/editor/scenes_dock.h23
2 files changed, 52 insertions, 30 deletions
diff --git a/tools/editor/scenes_dock.cpp b/tools/editor/scenes_dock.cpp
index bc0d48367a..a23c9cead7 100644
--- a/tools/editor/scenes_dock.cpp
+++ b/tools/editor/scenes_dock.cpp
@@ -38,7 +38,7 @@
bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) {
String search_term = tree_filter->get_search_term();
- String file_filter = tree_filter->get_file_filter();
+ ScenesDockFilter::FilterOption file_filter = tree_filter->get_file_filter();
TreeItem *item = tree->create_item(p_parent);
item->set_text(0,p_dir->get_name()+"/");
@@ -56,15 +56,19 @@ bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_di
for (int i=0;i<p_dir->get_file_count();i++) {
String file_name = p_dir->get_file(i);
- String extension = file_name.extension();
+ String file_path = p_dir->get_file_path(i);
- if (search_term!="" && file_name.findn(search_term)==-1)
- continue;
+ // ScenesDockFilter::FILTER_PATH
+ String search_from = file_path.right(6); // trim "res://"
+ if (file_filter == ScenesDockFilter::FILTER_NAME)
+ search_from = file_name;
+ else if (file_filter == ScenesDockFilter::FILTER_FOLDER)
+ search_from = file_path.right(6).get_base_dir();
- if (file_filter!="*" && extension != file_filter )
+ if (search_term!="" && search_from.findn(search_term)==-1)
continue;
- bool isfave = favorites.has(p_dir->get_file_path(i));
+ bool isfave = favorites.has(file_path);
if (button_favorite->is_pressed() && !isfave)
continue;
@@ -78,7 +82,7 @@ bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_di
fitem->set_icon(0, icon );
- fitem->set_metadata(0,p_dir->get_file_path(i));
+ fitem->set_metadata(0,file_path);
//if (p_dir->files[i]->icon.is_valid()) {
// fitem->set_icon(0,p_dir->files[i]->icon);
// }
@@ -289,7 +293,7 @@ ScenesDock::ScenesDock(EditorNode *p_editor) {
toolbar_hbc->add_child(button_instance);
tree = memnew( Tree );
- tree_filter=memnew( ScenesDockFilter(tree) );
+ tree_filter=memnew( ScenesDockFilter() );
tree_filter->connect("filter_changed", this, "_update_tree");
add_child(tree_filter);
add_child(tree);
@@ -314,8 +318,11 @@ ScenesDock::~ScenesDock() {
void ScenesDockFilter::_setup_filters() {
- file_filter->clear();
-
+ filter_option->clear();
+ filter_option->add_item("Path");
+ filter_option->add_item("Name");
+ filter_option->add_item("Folder");
+#if 0
List<String> extensions;
ResourceLoader::get_recognized_extensions_for_type("",&extensions);
@@ -336,6 +343,7 @@ void ScenesDockFilter::_setup_filters() {
else
file_filter->add_item("( "+flt+" )");
}
+#endif
}
void ScenesDockFilter::_command(int p_command) {
@@ -358,18 +366,26 @@ String ScenesDockFilter::get_search_term() {
return search_box->get_text().strip_edges();
}
-String ScenesDockFilter::get_file_filter() {
+ScenesDockFilter::FilterOption ScenesDockFilter::get_file_filter() {
return _current_filter;
}
void ScenesDockFilter::_file_filter_selected(int p_idx) {
- String selected = filters[file_filter->get_selected()];
+ FilterOption selected = (FilterOption)(filter_option->get_selected());
if (_current_filter != selected ) {
_current_filter = selected;
emit_signal("filter_changed");
}
}
+void ScenesDockFilter::_notification(int p_what) {
+ switch(p_what) {
+ case NOTIFICATION_ENTER_SCENE: {
+ clear_search_button->set_icon(get_icon("CloseHover","EditorIcons"));
+ } break;
+ }
+}
+
void ScenesDockFilter::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_command"),&ScenesDockFilter::_command);
@@ -379,17 +395,15 @@ void ScenesDockFilter::_bind_methods() {
ADD_SIGNAL( MethodInfo("filter_changed") );
}
-ScenesDockFilter::ScenesDockFilter(Tree *p_tree) {
-
- _current_filter = "*";
+ScenesDockFilter::ScenesDockFilter() {
- tree = p_tree;
+ _current_filter = FILTER_PATH;
- file_filter = memnew( OptionButton );
- file_filter->set_custom_minimum_size(Size2(90,10));
- file_filter->set_clip_text(true);
- file_filter->connect("item_selected", this, "_file_filter_selected");
- add_child(file_filter);
+ filter_option = memnew( OptionButton );
+ filter_option->set_custom_minimum_size(Size2(60,10));
+ filter_option->set_clip_text(true);
+ filter_option->connect("item_selected", this, "_file_filter_selected");
+ add_child(filter_option);
_setup_filters();
@@ -398,8 +412,7 @@ ScenesDockFilter::ScenesDockFilter(Tree *p_tree) {
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
add_child(search_box);
- clear_search_button = memnew( Button );
- clear_search_button->set_text("clear");
+ clear_search_button = memnew( ToolButton );
clear_search_button->connect("pressed",this,"_command",make_binds(CMD_CLEAR_FILTER));
add_child(clear_search_button);
diff --git a/tools/editor/scenes_dock.h b/tools/editor/scenes_dock.h
index cf48e2885f..9849f5ace0 100644
--- a/tools/editor/scenes_dock.h
+++ b/tools/editor/scenes_dock.h
@@ -33,7 +33,7 @@
#include "scene/gui/control.h"
#include "scene/gui/tree.h"
#include "scene/gui/label.h"
-#include "scene/gui/button.h"
+#include "scene/gui/tool_button.h"
#include "scene/gui/option_button.h"
#include "scene/gui/box_container.h"
#include "os/dir_access.h"
@@ -86,17 +86,25 @@ class ScenesDockFilter : public HBoxContainer {
OBJ_TYPE( ScenesDockFilter, HBoxContainer );
+private:
+ friend class ScenesDock;
+
enum Command {
CMD_CLEAR_FILTER,
};
Tree *tree;
- OptionButton *file_filter;
+ OptionButton *filter_option;
LineEdit *search_box;
- Button *clear_search_button;
+ ToolButton *clear_search_button;
- String _current_filter;
- Vector<String> filters;
+ enum FilterOption {
+ FILTER_PATH, // NAME or Folder
+ FILTER_NAME,
+ FILTER_FOLDER,
+ };
+ FilterOption _current_filter;
+ //Vector<String> filters;
void _command(int p_command);
void _search_text_changed(const String& p_newtext);
@@ -104,12 +112,13 @@ class ScenesDockFilter : public HBoxContainer {
void _file_filter_selected(int p_idx);
protected:
+ void _notification(int p_what);
static void _bind_methods();
public:
String get_search_term();
- String get_file_filter();
- ScenesDockFilter(Tree *p_tree);
+ FilterOption get_file_filter();
+ ScenesDockFilter();
};
#endif // SCENES_DOCK_H