diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-05-15 20:25:51 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-05-15 20:25:51 -0300 |
commit | 8b47e26f59ddca57f95dfae5ce807d382957a97e (patch) | |
tree | bd0ca96cd9c3bc86d6de9e65dd86f90259e91aff | |
parent | bed3efb17ede58a2bfc177b47cb3a49091aea30a (diff) |
Changes to FileSystem Dock
-Replaced buttons for file actions fo RMB menu
-Added a split mode, if the dock is not sharing vertical space with
anything else
-imroved drag and drop support
-rw-r--r-- | scene/gui/item_list.cpp | 60 | ||||
-rw-r--r-- | scene/gui/item_list.h | 6 | ||||
-rw-r--r-- | tools/editor/editor_node.cpp | 11 | ||||
-rw-r--r-- | tools/editor/scenes_dock.cpp | 698 | ||||
-rw-r--r-- | tools/editor/scenes_dock.h | 37 |
5 files changed, 550 insertions, 262 deletions
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 7041f86f16..c1a0e43e49 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -410,16 +410,18 @@ void ItemList::_input_event(const InputEvent& p_event) { defer_select_single=-1; return; } + if (defer_select_single>=0 && p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && !p_event.mouse_button.pressed) { select(defer_select_single,true); + emit_signal("multi_selected",defer_select_single,true); defer_select_single=-1; return; } - if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) { + if (p_event.type==InputEvent::MOUSE_BUTTON && (p_event.mouse_button.button_index==BUTTON_LEFT || (allow_rmb_select && p_event.mouse_button.button_index==BUTTON_RIGHT)) && p_event.mouse_button.pressed) { const InputEventMouseButton &mb = p_event.mouse_button; @@ -458,6 +460,7 @@ void ItemList::_input_event(const InputEvent& p_event) { if (select_mode==SELECT_MULTI && items[i].selected && mb.mod.command) { unselect(i); emit_signal("multi_selected",i,false); + } else if (select_mode==SELECT_MULTI && mb.mod.shift && current>=0 && current<items.size() && current!=i) { int from = current; @@ -471,29 +474,45 @@ void ItemList::_input_event(const InputEvent& p_event) { if (selected) emit_signal("multi_selected",i,true); } + + if (p_event.mouse_button.button_index==BUTTON_RIGHT) { + + emit_signal("item_rmb_selected",i,Vector2(mb.x,mb.y)); + } } else { - if (!mb.doubleclick && !mb.mod.command && select_mode==SELECT_MULTI && items[i].selectable && items[i].selected) { + if (!mb.doubleclick && !mb.mod.command && select_mode==SELECT_MULTI && items[i].selectable && items[i].selected && p_event.mouse_button.button_index==BUTTON_LEFT) { defer_select_single=i; return; } - bool selected = !items[i].selected; - select(i,select_mode==SELECT_SINGLE || !mb.mod.command); - if (selected) { - if (select_mode==SELECT_SINGLE) { - emit_signal("item_selected",i); - } else - emit_signal("multi_selected",i,true); - } + if (items[i].selected && p_event.mouse_button.button_index==BUTTON_RIGHT) { - if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) { + emit_signal("item_rmb_selected",i,Vector2(mb.x,mb.y)); + } else { + bool selected = !items[i].selected; - emit_signal("item_activated",i); - } + select(i,select_mode==SELECT_SINGLE || !mb.mod.command); + + if (selected) { + if (select_mode==SELECT_SINGLE) { + emit_signal("item_selected",i); + } else + emit_signal("multi_selected",i,true); + } + + if (p_event.mouse_button.button_index==BUTTON_RIGHT) { + + emit_signal("item_rmb_selected",i,Vector2(mb.x,mb.y)); + } else if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) { + + emit_signal("item_activated",i); + + } + } } @@ -1172,6 +1191,16 @@ int ItemList::find_metadata(const Variant& p_metadata) const { } + +void ItemList::set_allow_rmb_select(bool p_allow) { + allow_rmb_select=p_allow; +} + +bool ItemList::get_allow_rmb_select() const { + + return allow_rmb_select; +} + void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("add_item","text","icon:Texture","selectable"),&ItemList::add_item,DEFVAL(Variant()),DEFVAL(true)); @@ -1232,6 +1261,9 @@ void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_max_icon_size","size"),&ItemList::set_max_icon_size); ObjectTypeDB::bind_method(_MD("get_max_icon_size"),&ItemList::get_max_icon_size); + ObjectTypeDB::bind_method(_MD("set_allow_rmb_select","allow"),&ItemList::set_allow_rmb_select); + ObjectTypeDB::bind_method(_MD("get_allow_rmb_select"),&ItemList::get_allow_rmb_select); + ObjectTypeDB::bind_method(_MD("get_item_at_pos","pos","exact"),&ItemList::get_item_at_pos,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("ensure_current_is_visible"),&ItemList::ensure_current_is_visible); @@ -1245,6 +1277,7 @@ void ItemList::_bind_methods(){ BIND_CONSTANT( SELECT_MULTI ); ADD_SIGNAL( MethodInfo("item_selected",PropertyInfo(Variant::INT,"index"))); + ADD_SIGNAL( MethodInfo("item_rmb_selected",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::VECTOR2,"atpos"))); ADD_SIGNAL( MethodInfo("multi_selected",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::BOOL,"selected"))); ADD_SIGNAL( MethodInfo("item_activated",PropertyInfo(Variant::INT,"index"))); } @@ -1273,6 +1306,7 @@ ItemList::ItemList() { search_time_msec=0; ensure_selected_visible=false; defer_select_single=-1; + allow_rmb_select=false; } diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index ba70ed3530..59fa1d8270 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -61,9 +61,10 @@ private: int max_columns; Size2 min_icon_size; Size2 max_icon_size; - int defer_select_single; + bool allow_rmb_select; + void _scroll_changed(double); void _input_event(const InputEvent& p_event); protected: @@ -138,6 +139,9 @@ public: void set_max_icon_size(const Size2& p_size); Size2 get_max_icon_size() const; + void set_allow_rmb_select(bool p_allow); + bool get_allow_rmb_select() const; + void ensure_current_is_visible(); void sort_items_by_text(); diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index c9cec3b7f4..bbd2464992 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -2057,8 +2057,9 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { case FILE_QUICK_OPEN_FILE: { - quick_open->popup("Resource", false, true); - quick_open->set_title(TTR("Quick Search File..")); + //quick_open->popup("Resource", false, true); + //quick_open->set_title(TTR("Quick Search File..")); + scenes_dock->focus_on_filter(); } break; case FILE_RUN_SCRIPT: { @@ -3942,12 +3943,6 @@ void EditorNode::_update_recent_scenes() { void EditorNode::_quick_opened() { - if (current_option==FILE_QUICK_OPEN_FILE) { - String res_path = quick_open->get_selected(); - - scenes_dock->open(res_path); - return; - } Vector<String> files = quick_open->get_selected_files(); diff --git a/tools/editor/scenes_dock.cpp b/tools/editor/scenes_dock.cpp index c03142a3e7..e00f470bc4 100644 --- a/tools/editor/scenes_dock.cpp +++ b/tools/editor/scenes_dock.cpp @@ -36,7 +36,7 @@ #include "editor_node.h" #include "editor_settings.h" - +#include "scene/main/viewport.h" bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) { @@ -151,6 +151,35 @@ void ScenesDock::_notification(int p_what) { switch(p_what) { + case NOTIFICATION_RESIZED: { + + + bool new_mode = get_size().height < get_viewport_rect().size.height*3/4; + + if (new_mode != split_mode ) { + + split_mode=new_mode; + + //print_line("SPLIT MODE? "+itos(split_mode)); + if (split_mode) { + + file_list_vb->hide(); + tree->set_v_size_flags(SIZE_EXPAND_FILL); + button_back->show(); + } else { + + tree->show(); + file_list_vb->show(); + tree->set_v_size_flags(SIZE_FILL); + button_back->hide(); + if (!EditorFileSystem::get_singleton()->is_scanning()) { + _fs_changed(); + } + } + } + + + } break; case NOTIFICATION_ENTER_TREE: { if (initialized) @@ -163,19 +192,20 @@ void ScenesDock::_notification(int p_what) { button_favorite->set_icon( get_icon("Favorites","EditorIcons")); button_fav_up->set_icon( get_icon("MoveUp","EditorIcons")); button_fav_down->set_icon( get_icon("MoveDown","EditorIcons")); - button_instance->set_icon( get_icon("Add","EditorIcons")); - button_open->set_icon( get_icon("Folder","EditorIcons")); + //button_instance->set_icon( get_icon("Add","EditorIcons")); + //button_open->set_icon( get_icon("Folder","EditorIcons")); button_back->set_icon( get_icon("Filesystem","EditorIcons")); display_mode->set_icon( get_icon("FileList","EditorIcons")); display_mode->connect("pressed",this,"_change_file_display"); - file_options->set_icon( get_icon("Tools","EditorIcons")); + //file_options->set_icon( get_icon("Tools","EditorIcons")); files->connect("item_activated",this,"_select_file"); button_hist_next->connect("pressed",this,"_fw_history"); button_hist_prev->connect("pressed",this,"_bw_history"); + search_button->set_icon( get_icon("Zoom","EditorIcons")); button_hist_next->set_icon( get_icon("Forward","EditorIcons")); button_hist_prev->set_icon( get_icon("Back","EditorIcons")); - file_options->get_popup()->connect("item_pressed",this,"_file_option"); + file_options->connect("item_pressed",this,"_file_option"); button_back->connect("pressed",this,"_go_to_tree",varray(),CONNECT_DEFERRED); @@ -195,6 +225,19 @@ void ScenesDock::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { } break; + case NOTIFICATION_DRAG_BEGIN: { + + Dictionary dd = get_viewport()->gui_get_drag_data(); + if (tree->is_visible() && dd.has("type") && ( + (String(dd["type"])=="files") || (String(dd["type"])=="files_and_dirs") || (String(dd["type"])=="resource"))) { + tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); + } + } break; + case NOTIFICATION_DRAG_END: { + + tree->set_drop_mode_flags(0); + + } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { display_mode->set_pressed(int(EditorSettings::get_singleton()->get("file_dialog/display_mode"))==EditorFileDialog::DISPLAY_LIST); @@ -235,6 +278,11 @@ void ScenesDock::_dir_selected() { button_fav_up->set_disabled(true); button_fav_down->set_disabled(true); + + } + + if (!split_mode) { + _open_pressed(); //go directly to dir } } @@ -355,42 +403,26 @@ String ScenesDock::get_selected_path() const { return "res://"+path; } -void ScenesDock::_instance_pressed() { - if (tree_mode) - { - TreeItem *sel = tree->get_selected(); - if (!sel) - return; - String path = sel->get_metadata(0); - } - else - { - int idx = -1; - for (int i = 0; i<files->get_item_count(); i++) { - if (files->is_selected(i)) - { - idx = i; - break; - } - } +void ScenesDock::_thumbnail_done(const String& p_path,const Ref<Texture>& p_preview, const Variant& p_udata) { - if (idx<0) - return; + bool valid=false; - path = files->get_item_metadata(idx); + if (!search_box->is_hidden()) { + valid=true; + } else { + valid=(path==p_path.get_base_dir()); } - emit_signal("instance",path); -} - -void ScenesDock::_thumbnail_done(const String& p_path,const Ref<Texture>& p_preview, const Variant& p_udata) { - - if (p_preview.is_valid() && path==p_path.get_base_dir()) { + if (p_preview.is_valid() && valid) { - int idx=p_udata; + Array uarr=p_udata; + int idx=uarr[0]; + String file=uarr[1]; if (idx>=files->get_item_count()) return; + if (files->get_item_text(idx)!=file) + return; String fpath = files->get_item_metadata(idx); if (fpath!=p_path) return; @@ -412,6 +444,34 @@ void ScenesDock::_change_file_display() { _update_files(true); } +void ScenesDock::_search(EditorFileSystemDirectory *p_path,List<FileInfo>* matches,int p_max_items) { + + if (matches->size()>p_max_items) + return; + + for(int i=0;i<p_path->get_subdir_count();i++) { + _search(p_path->get_subdir(i),matches,p_max_items); + + } + + String match = search_box->get_text(); + + for(int i=0;i<p_path->get_file_count();i++) { + String file = p_path->get_file(i); + + if (file.find(match)!=-1) { + + FileInfo fi; + fi.name=file; + fi.type=p_path->get_file_type(i); + fi.path=p_path->get_file_path(i); + matches->push_back(fi); + if (matches->size()>p_max_items) + return; + } + } +} + void ScenesDock::_update_files(bool p_keep_selection) { Set<String> cselection; @@ -427,6 +487,9 @@ void ScenesDock::_update_files(bool p_keep_selection) { files->clear(); + current_path->set_text(path); + + EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path); if (!efd) return; @@ -436,6 +499,7 @@ void ScenesDock::_update_files(bool p_keep_selection) { Ref<Texture> file_thumbnail; bool use_thumbnails=!display_mode->is_pressed(); + bool use_folders = !search_box->is_visible() && split_mode; if (use_thumbnails) { //thumbnails @@ -477,59 +541,90 @@ void ScenesDock::_update_files(bool p_keep_selection) { } + if (use_folders) { - if (path!="res://") { + if (path!="res://") { - if (use_thumbnails) { - files->add_item("..",folder_thumbnail,true); - } else { - files->add_item("..",get_icon("folder","FileDialog"),true); + if (use_thumbnails) { + files->add_item("..",folder_thumbnail,true); + } else { + files->add_item("..",get_icon("folder","FileDialog"),true); + } + + String bd = path.get_base_dir(); + if (bd!="res://" && !bd.ends_with("/")) + bd+="/"; + + files->set_item_metadata(files->get_item_count()-1,bd); } - String bd = path.get_base_dir(); - if (bd!="res://" && !bd.ends_with("/")) - bd+="/"; + for(int i=0;i<efd->get_subdir_count();i++) { + + String dname=efd->get_subdir(i)->get_name(); + + + if (use_thumbnails) { + files->add_item(dname,folder_thumbnail,true); + } else { + files->add_item(dname,get_icon("folder","FileDialog"),true); + } - files->set_item_metadata(files->get_item_count()-1,bd); + files->set_item_metadata(files->get_item_count()-1,path.plus_file(dname)+"/"); + + if (cselection.has(dname)) + files->select(files->get_item_count()-1,false); + } } - for(int i=0;i<efd->get_subdir_count();i++) { - String dname=efd->get_subdir(i)->get_name(); + List<FileInfo> filelist; + if (search_box->is_visible()) { - if (use_thumbnails) { - files->add_item(dname,folder_thumbnail,true); - } else { - files->add_item(dname,get_icon("folder","FileDialog"),true); + if (search_box->get_text().length()>1) { + _search(EditorFileSystem::get_singleton()->get_filesystem(),&filelist,128); } - files->set_item_metadata(files->get_item_count()-1,path.plus_file(dname)+"/"); + filelist.sort(); + } else { - if (cselection.has(dname)) - files->select(files->get_item_count()-1,false); + for(int i=0;i<efd->get_file_count();i++) { + + FileInfo fi; + fi.name=efd->get_file(i); + fi.path=path.plus_file(fi.name); + fi.type=efd->get_file_type(i); + + filelist.push_back(fi); + } } - for(int i=0;i<efd->get_file_count();i++) { + StringName ei="EditorIcons"; //make it faster.. + StringName oi="Object"; - String fname=efd->get_file(i); - String fp = path.plus_file(fname); + for(List<FileInfo>::Element *E=filelist.front();E;E=E->next()) { + String fname=E->get().name; + String fp = E->get().path; + StringName type = E->get().type; - String type = efd->get_file_type(i); Ref<Texture> type_icon; - if (has_icon(type,"EditorIcons")) { - type_icon=get_icon(type,"EditorIcons"); + if (has_icon(type,ei)) { + type_icon=get_icon(type,ei); } else { - type_icon=get_icon("Object","EditorIcons"); + type_icon=get_icon(oi,ei); } if (use_thumbnails) { files->add_item(fname,file_thumbnail,true); files->set_item_metadata(files->get_item_count()-1,fp); files->set_item_tag_icon(files->get_item_count()-1,type_icon); - EditorResourcePreview::get_singleton()->queue_resource_preview(fp,this,"_thumbnail_done",files->get_item_count()-1); + Array udata; + udata.resize(2); + udata[0]=files->get_item_count()-1; + udata[1]=fname; + EditorResourcePreview::get_singleton()->queue_resource_preview(fp,this,"_thumbnail_done",udata); } else { files->add_item(fname,type_icon,true); files->set_item_metadata(files->get_item_count()-1,fp); @@ -547,25 +642,21 @@ void ScenesDock::_update_files(bool p_keep_selection) { void ScenesDock::_select_file(int p_idx) { files->select(p_idx,true); - _open_pressed(); + _file_option(FILE_OPEN); } void ScenesDock::_go_to_tree() { tree->show(); - files->hide(); - path_hb->hide(); + file_list_vb->hide(); _update_tree(); tree->grab_focus(); tree->ensure_cursor_is_visible(); button_favorite->show(); button_fav_up->show(); button_fav_down->show(); - button_open->hide(); - button_instance->hide(); - button_open->hide(); - file_options->hide(); - tree_mode=true; + //button_open->hide(); + //file_options->hide(); } void ScenesDock::_go_to_dir(const String& p_dir){ @@ -585,20 +676,18 @@ void ScenesDock::_fs_changed() { button_hist_prev->set_disabled(history_pos==0); button_hist_next->set_disabled(history_pos+1==history.size()); scanning_vb->hide(); + split_box->show(); - if (tree_mode) { - - tree->show(); + if (!tree->is_hidden()) { button_favorite->show(); button_fav_up->show(); button_fav_down->show(); _update_tree(); - } else { - files->show(); - path_hb->show(); - button_instance->show(); - button_open->show(); - file_options->show(); + + } + + if (!file_list_vb->is_hidden()) { + _update_files(true); } @@ -607,18 +696,10 @@ void ScenesDock::_fs_changed() { void ScenesDock::_set_scannig_mode() { - tree->hide(); - button_favorite->hide(); - button_fav_up->hide(); - button_fav_down->hide(); - button_instance->hide(); - button_open->hide(); - file_options->hide(); + split_box->hide(); button_hist_prev->set_disabled(true); button_hist_next->set_disabled(true); scanning_vb->show(); - path_hb->hide(); - files->hide(); set_process(true); if (EditorFileSystem::get_singleton()->is_scanning()) { scanning_progress->set_val(EditorFileSystem::get_singleton()->get_scanning_progress()*100); @@ -635,11 +716,14 @@ void ScenesDock::_fw_history() { path=history[history_pos]; - if (tree_mode) { + if (!tree->is_hidden()) { _update_tree(); tree->grab_focus(); tree->ensure_cursor_is_visible(); - } else { + + } + + if (!file_list_vb->is_hidden()) { _update_files(false); current_path->set_text(path); } @@ -656,11 +740,14 @@ void ScenesDock::_bw_history() { path=history[history_pos]; - if (tree_mode) { + + if (!tree->is_hidden()) { _update_tree(); tree->grab_focus(); tree->ensure_cursor_is_visible(); - } else { + } + + if (!file_list_vb->is_hidden()) { _update_files(false); current_path->set_text(path); } @@ -829,9 +916,17 @@ void ScenesDock::_move_operation(const String& p_to_path) { for(int i=0;i<move_dirs.size();i++) { - String to = p_to_path.plus_file(move_dirs[i].get_file()); - Error err = da->rename(move_dirs[i],to); - print_line("moving dir "+move_dirs[i]+" to "+to); + String mdir = move_dirs[i]; + if (mdir=="res://") + continue; + + if (mdir.ends_with("/")) { + mdir=mdir.substr(0,mdir.length()-1); + } + + String to = p_to_path.plus_file(mdir.get_file()); + Error err = da->rename(mdir,to); + print_line("moving dir "+mdir+" to "+to); if (err!=OK) { EditorNode::get_singleton()->add_io_error("Error moving dir:\n"+move_dirs[i]+"\n"); } @@ -848,6 +943,52 @@ void ScenesDock::_file_option(int p_option) { switch(p_option) { + + case FILE_OPEN: { + int idx=-1; + for(int i=0;i<files->get_item_count();i++) { + if (files->is_selected(i)) { + idx=i; + break; + } + } + + if (idx<0) + return; + + + + String path = files->get_item_metadata(idx); + + if (path.ends_with("/")) { + if (path!="res://") { + path=path.substr(0,path.length()-1); + } + this->path=path; + _update_files(false); + current_path->set_text(path); + _push_to_history(); + } else { + + if (ResourceLoader::get_resource_type(path)=="PackedScene") { + + editor->open_request(path); + } else { + + editor->load_resource(path); + } + } + } break; + case FILE_INSTANCE: { + + for (int i = 0; i<files->get_item_count(); i++) { + + String path =files->get_item_metadata(i); + if (EditorFileSystem::get_singleton()->get_file_type(path)=="PackedScene") { + emit_signal("instance",path); + } + } + } break; case FILE_DEPENDENCIES: { int idx = files->get_current(); @@ -937,77 +1078,63 @@ void ScenesDock::_file_option(int p_option) { void ScenesDock::_open_pressed(){ - if (tree_mode) { - - TreeItem *sel = tree->get_selected(); - if (!sel) { - return; - } - path = sel->get_metadata(0); - /*if (path!="res://" && path.ends_with("/")) { - path=path.substr(0,path.length()-1); - }*/ + TreeItem *sel = tree->get_selected(); + if (!sel) { + return; + } + path = sel->get_metadata(0); + /*if (path!="res://" && path.ends_with("/")) { + path=path.substr(0,path.length()-1); + }*/ - tree_mode=false; + //tree_mode=false; + if (split_mode) { tree->hide(); - files->show(); - path_hb->show(); + file_list_vb->show(); button_favorite->hide(); button_fav_up->hide(); button_fav_down->hide(); - button_instance->show(); - button_open->show(); - file_options->show(); - - _update_files(false); - - current_path->set_text(path); - - _push_to_history(); + } + //file_options->show(); - } else { - - int idx=-1; - for(int i=0;i<files->get_item_count();i++) { - if (files->is_selected(i)) { - idx=i; - break; - } - } + _update_files(false); + current_path->set_text(path); + _push_to_history(); - if (idx<0) - return; +// emit_signal("open",path); +} +void ScenesDock::_search_toggled(){ - String path = files->get_item_metadata(idx); + if (search_button->is_pressed()) { + //search_box->clear(); + search_box->select_all(); + search_box->show(); + current_path->hide(); + search_box->grab_focus(); - if (path.ends_with("/")) { - if (path!="res://") { - path=path.substr(0,path.length()-1); - } - this->path=path; - _update_files(false); - current_path->set_text(path); - _push_to_history(); - } else { + _update_files(false); + } else { - if (ResourceLoader::get_resource_type(path)=="PackedScene") { + //search_box->clear(); + search_box->hide(); + current_path->show(); - editor->open_request(path); - } else { + _update_files(false); - editor->load_resource(path); - } - } } +} -// emit_signal("open",path); +void ScenesDock::_search_changed(const String& p_text) { -} + if (!search_box->is_visible()) + return; //wtf + _update_files(false); +} void ScenesDock::_rescan() { @@ -1020,51 +1147,8 @@ void ScenesDock::fix_dependencies(const String& p_for_file) { deps_editor->edit(p_for_file); } -void ScenesDock::open(const String& p_path) { - - String npath; - String nfile; - - if (p_path.ends_with("/")) { - - if (p_path!="res://") - npath=p_path.substr(0,p_path.length()-1); - else - npath="res://"; - } else { - nfile=p_path.get_file(); - npath=p_path.get_base_dir(); - } - - path=npath; - - if (tree_mode && nfile=="") { - _update_tree(); - tree->grab_focus(); - tree->call_deferred("ensure_cursor_is_visible"); - _push_to_history(); - return; - } else if (tree_mode){ - _update_tree(); - tree->grab_focus(); - tree->ensure_cursor_is_visible(); - _open_pressed(); - current_path->set_text(path); - } else { - _update_files(false); - _push_to_history(); - } - - for(int i=0;i<files->get_item_count();i++) { - - String md = files->get_item_metadata(i); - if (md==p_path) { - files->select(i,true); - files->ensure_current_is_visible(); - break; - } - } +void ScenesDock::focus_on_filter() { } @@ -1076,6 +1160,23 @@ void ScenesDock::set_use_thumbnails(bool p_use) { Variant ScenesDock::get_drag_data_fw(const Point2& p_point,Control* p_from) { + if (p_from==tree) { + + TreeItem *selected = tree->get_selected(); + if (!selected) + return Variant(); + + String path = selected->get_metadata(0); + if (path==String()) + return Variant(); + if (!path.ends_with("/")) + path=path+"/"; + Vector<String> paths; + paths.push_back(path); + return EditorNode::get_singleton()->drag_files(paths,p_from); + + } + if (p_from==files) { List<int> seldirs; @@ -1150,6 +1251,20 @@ bool ScenesDock::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Co return true; } } + + if (p_from==tree) { + + TreeItem *ti = tree->get_item_at_pos(p_point); + if (!ti) + return false; + String path = ti->get_metadata(0); + + if (path==String()) + return false; + + return true; + } + } return false; @@ -1168,53 +1283,150 @@ void ScenesDock::drop_data_fw(const Point2& p_point,const Variant& p_data,Contro return; } - String save_path=path; - int at_pos = files->get_item_at_pos(p_point); - if (at_pos!=-1) { - String to_dir = files->get_item_metadata(at_pos); - if (to_dir.ends_with("/")) { - save_path=to_dir; - if (save_path!="res://") - save_path=save_path.substr(0,save_path.length()-1); - } + if (p_from==tree) { + + TreeItem *ti = tree->get_item_at_pos(p_point); + if (!ti) + return; + String path = ti->get_metadata(0); + + if (path==String()) + return; + + EditorNode::get_singleton()->save_resource_as(res,path); + return; } - EditorNode::get_singleton()->save_resource_as(res,save_path); - return; + if (p_from==files) { + String save_path=path; + + int at_pos = files->get_item_at_pos(p_point); + if (at_pos!=-1) { + String to_dir = files->get_item_metadata(at_pos); + if (to_dir.ends_with("/")) { + save_path=to_dir; + if (save_path!="res://") + save_path=save_path.substr(0,save_path.length()-1); + } + + } + + EditorNode::get_singleton()->save_resource_as(res,save_path); + return; + } } if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) { - int at_pos = files->get_item_at_pos(p_point); - ERR_FAIL_COND(at_pos==-1); - String to_dir = files->get_item_metadata(at_pos); - ERR_FAIL_COND(!to_dir.ends_with("/")); + if (p_from==files || p_from==tree) { - Vector<String> fnames = drag_data["files"]; - move_files.clear(); - move_dirs.clear(); - - for(int i=0;i<fnames.size();i++) { - if (fnames[i].ends_with("/")) - move_dirs.push_back(fnames[i]); - else - move_files.push_back(fnames[i]); - } + String to_dir; + + if (p_from==files) { - _move_operation(to_dir); + int at_pos = files->get_item_at_pos(p_point); + ERR_FAIL_COND(at_pos==-1); + String to_dir = files->get_item_metadata(at_pos); + } else { + TreeItem *ti = tree->get_item_at_pos(p_point); + if (!ti) + return; + to_dir = ti->get_metadata(0); + ERR_FAIL_COND(to_dir==String()); + + } + + if (to_dir!="res://" && to_dir.ends_with("/")) { + to_dir=to_dir.substr(0,to_dir.length()-1); + } + + Vector<String> fnames = drag_data["files"]; + move_files.clear(); + move_dirs.clear(); + + for(int i=0;i<fnames.size();i++) { + if (fnames[i].ends_with("/")) + move_dirs.push_back(fnames[i]); + else + move_files.push_back(fnames[i]); + } + + _move_operation(to_dir); + } } } +void ScenesDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { + + Vector<String> filenames; + + bool all_scenes=true; + + for(int i=0;i<files->get_item_count();i++) { + + if (!files->is_selected(i)) + continue; + + String path = files->get_item_metadata(i); + + if (files->get_item_text(i)=="..") { + // no operate on .. + return; + } + + if (path.ends_with("/")) { + //no operate on dirs + return; + } + + + filenames.push_back(path); + if (EditorFileSystem::get_singleton()->get_file_type(path)!="PackedScene") + all_scenes=false; + } + + + if (filenames.size()==0) + return; + + file_options->clear(); + file_options->set_size(Size2(1,1)); + + file_options->add_item(TTR("Open"),FILE_OPEN); + if (all_scenes) { + file_options->add_item(TTR("Instance"),FILE_INSTANCE); + } + + file_options->add_separator(); + + if (filenames.size()==1) { + file_options->add_item(TTR("Edit Dependencies.."),FILE_DEPENDENCIES); + file_options->add_item(TTR("View Owners.."),FILE_OWNERS); + file_options->add_separator(); + } + + if (filenames.size()==1) { + file_options->add_item(TTR("Rename or Move.."),FILE_MOVE); + } else { + file_options->add_item(TTR("Move To.."),FILE_MOVE); + } + + file_options->add_item(TTR("Delete"),FILE_REMOVE); + //file_options->add_item(TTR("Info"),FILE_INFO); + file_options->set_pos(files->get_global_pos() + p_pos); + file_options->popup(); + +} void ScenesDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_update_tree"),&ScenesDock::_update_tree); ObjectTypeDB::bind_method(_MD("_rescan"),&ScenesDock::_rescan); ObjectTypeDB::bind_method(_MD("_favorites_pressed"),&ScenesDock::_favorites_pressed); - ObjectTypeDB::bind_method(_MD("_instance_pressed"),&ScenesDock::_instance_pressed); +// ObjectTypeDB::bind_method(_MD("_instance_pressed"),&ScenesDock::_instance_pressed); ObjectTypeDB::bind_method(_MD("_open_pressed"),&ScenesDock::_open_pressed); ObjectTypeDB::bind_method(_MD("_thumbnail_done"),&ScenesDock::_thumbnail_done); @@ -1231,10 +1443,13 @@ void ScenesDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_file_option"), &ScenesDock::_file_option); ObjectTypeDB::bind_method(_MD("_move_operation"), &ScenesDock::_move_operation); ObjectTypeDB::bind_method(_MD("_rename_operation"), &ScenesDock::_rename_operation); + ObjectTypeDB::bind_method(_MD("_search_toggled"), &ScenesDock::_search_toggled); + ObjectTypeDB::bind_method(_MD("_search_changed"), &ScenesDock::_search_changed); ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &ScenesDock::get_drag_data_fw); ObjectTypeDB::bind_method(_MD("can_drop_data_fw"), &ScenesDock::can_drop_data_fw); ObjectTypeDB::bind_method(_MD("drop_data_fw"), &ScenesDock::drop_data_fw); + ObjectTypeDB::bind_method(_MD("_files_list_rmb_select"),&ScenesDock::_files_list_rmb_select); ADD_SIGNAL(MethodInfo("instance")); ADD_SIGNAL(MethodInfo("open")); @@ -1245,6 +1460,7 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { editor=p_editor; + HBoxContainer *toolbar_hbc = memnew( HBoxContainer ); add_child(toolbar_hbc); @@ -1294,7 +1510,7 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { button_fav_up->set_focus_mode(FOCUS_NONE); button_fav_down->set_focus_mode(FOCUS_NONE); - +/* button_open = memnew( Button ); button_open->set_flat(true); button_open->connect("pressed",this,"_open_pressed"); @@ -1312,26 +1528,23 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { button_instance->set_focus_mode(FOCUS_NONE); button_instance->set_tooltip(TTR("Instance the selected scene(s) as child of the selected node.")); +*/ + file_options = memnew( PopupMenu ); + add_child(file_options); - file_options = memnew( MenuButton ); - toolbar_hbc->add_child(file_options); - file_options->get_popup()->add_item(TTR("Rename or Move"),FILE_MOVE); - file_options->get_popup()->add_item(TTR("Delete"),FILE_REMOVE); - file_options->get_popup()->add_separator(); - file_options->get_popup()->add_item(TTR("Edit Dependencies"),FILE_DEPENDENCIES); - file_options->get_popup()->add_item(TTR("View Owners"),FILE_OWNERS); - //file_options->get_popup()->add_item(TTR("Info"),FILE_INFO); - file_options->hide(); - file_options->set_focus_mode(FOCUS_NONE); - file_options->set_tooltip(TTR("Miscenaneous options related to resources on disk.")); + split_box = memnew( VSplitContainer ); + add_child(split_box); + split_box->set_v_size_flags(SIZE_EXPAND_FILL); tree = memnew( Tree ); tree->set_hide_root(true); - add_child(tree); + split_box->add_child(tree); + tree->set_custom_minimum_size(Size2(0,200)); + tree->set_drag_forwarding(this); - tree->set_v_size_flags(SIZE_EXPAND_FILL); + //tree->set_v_size_flags(SIZE_EXPAND_FILL); tree->connect("item_edited",this,"_favorite_toggled"); tree->connect("item_activated",this,"_open_pressed"); tree->connect("cell_selected",this,"_dir_selected"); @@ -1340,22 +1553,40 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { files->set_v_size_flags(SIZE_EXPAND_FILL); files->set_select_mode(ItemList::SELECT_MULTI); files->set_drag_forwarding(this); + files->connect("item_rmb_selected",this,"_files_list_rmb_select"); + files->set_allow_rmb_select(true); + + file_list_vb = memnew( VBoxContainer ); + split_box->add_child(file_list_vb); + file_list_vb->set_v_size_flags(SIZE_EXPAND_FILL); path_hb = memnew( HBoxContainer ); + file_list_vb->add_child(path_hb); + button_back = memnew( ToolButton ); path_hb->add_child(button_back); + button_back->hide(); current_path=memnew( LineEdit ); current_path->set_h_size_flags(SIZE_EXPAND_FILL); path_hb->add_child(current_path); + + search_box = memnew( LineEdit ); + search_box->set_h_size_flags(SIZE_EXPAND_FILL); + path_hb->add_child(search_box); + search_box->hide(); + search_box->connect("text_changed",this,"_search_changed"); + + search_button = memnew( ToolButton ); + path_hb->add_child(search_button); + search_button->set_toggle_mode(true ); + search_button->connect("pressed",this,"_search_toggled"); + display_mode = memnew( ToolButton ); path_hb->add_child(display_mode); display_mode->set_toggle_mode(true); - add_child(path_hb); - path_hb->hide(); + file_list_vb->add_child(files); - add_child(files); - files->hide(); scanning_vb = memnew( VBoxContainer ); Label *slabel = memnew( Label ); @@ -1393,7 +1624,8 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { history.push_back("res://"); history_pos=0; - tree_mode=true; + + split_mode=false; path="res://"; diff --git a/tools/editor/scenes_dock.h b/tools/editor/scenes_dock.h index 86196b7ccd..327e5a25f0 100644 --- a/tools/editor/scenes_dock.h +++ b/tools/editor/scenes_dock.h @@ -39,6 +39,7 @@ #include "scene/gui/menu_button.h" #include "scene/gui/item_list.h" #include "scene/gui/progress_bar.h" +#include "scene/gui/split_container.h" #include "os/dir_access.h" #include "os/thread.h" @@ -54,6 +55,8 @@ class ScenesDock : public VBoxContainer { OBJ_TYPE( ScenesDock, VBoxContainer ); enum FileMenu { + FILE_OPEN, + FILE_INSTANCE, FILE_DEPENDENCIES, FILE_OWNERS, FILE_MOVE, @@ -65,25 +68,28 @@ class ScenesDock : public VBoxContainer { VBoxContainer *scanning_vb; ProgressBar *scanning_progress; + VSplitContainer *split_box; + VBoxContainer *file_list_vb; EditorNode *editor; Set<String> favorites; Button *button_reload; - Button *button_instance; Button *button_favorite; Button *button_fav_up; Button *button_fav_down; - Button *button_open; Button *button_back; Button *display_mode; Button *button_hist_next; Button *button_hist_prev; LineEdit *current_path; + LineEdit *search_box; + Button *search_button; HBoxContainer *path_hb; - MenuButton *file_options; + bool split_mode; + PopupMenu *file_options; DependencyEditor *deps_editor; DependencyEditorOwners *owners_editor; @@ -107,8 +113,6 @@ class ScenesDock : public VBoxContainer { Tree * tree; //directories ItemList *files; - bool tree_mode; - void _go_to_tree(); void _go_to_dir(const String& p_dir); void _select_file(int p_idx); @@ -131,6 +135,7 @@ class ScenesDock : public VBoxContainer { void _bw_history(); void _push_to_history(); + void _fav_up_pressed(); void _fav_down_pressed(); void _dir_selected(); @@ -138,9 +143,27 @@ class ScenesDock : public VBoxContainer { void _rescan(); void _set_scannig_mode(); + void _favorites_pressed(); - void _instance_pressed(); void _open_pressed(); + void _search_toggled(); + void _search_changed(const String& p_text); + + + void _files_list_rmb_select(int p_item,const Vector2& p_pos); + + + struct FileInfo { + String name; + String path; + StringName type; + + bool operator<(const FileInfo& fi) const { + return name < fi.name; + } + }; + + void _search(EditorFileSystemDirectory *p_path, List<FileInfo>* matches, int p_max_items); Variant get_drag_data_fw(const Point2& p_point,Control* p_from); bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; @@ -152,7 +175,7 @@ protected: public: String get_selected_path() const; - void open(const String& p_path); + void focus_on_filter(); void fix_dependencies(const String& p_for_file); |