FileSystemDock: Collapse folders by default, add context menu with "Expand all" / "Collapse all" option.

This commit is contained in:
lonesurvivor 2017-01-10 13:19:59 +01:00
parent 48097f6df3
commit 8fbd47c377
2 changed files with 55 additions and 2 deletions

View file

@ -38,14 +38,16 @@
#include "editor_settings.h" #include "editor_settings.h"
#include "scene/main/viewport.h" #include "scene/main/viewport.h"
bool FileSystemDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) { bool FileSystemDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) {
TreeItem *item = tree->create_item(p_parent); TreeItem *item = tree->create_item(p_parent);
String dname=p_dir->get_name(); String dname=p_dir->get_name();
if (dname=="") if (dname=="")
dname="res://"; dname="res://";
else {
// collapse every tree item but the root folder
item->set_collapsed(true);
}
item->set_text(0,dname); item->set_text(0,dname);
item->set_icon(0,get_icon("Folder","EditorIcons")); item->set_icon(0,get_icon("Folder","EditorIcons"));
@ -161,6 +163,7 @@ void FileSystemDock::_notification(int p_what) {
button_hist_next->set_icon( get_icon("Forward","EditorIcons")); button_hist_next->set_icon( get_icon("Forward","EditorIcons"));
button_hist_prev->set_icon( get_icon("Back","EditorIcons")); button_hist_prev->set_icon( get_icon("Back","EditorIcons"));
file_options->connect("id_pressed",this,"_file_option"); file_options->connect("id_pressed",this,"_file_option");
folder_options->connect("id_pressed",this,"_folder_option");
button_back->connect("pressed",this,"_go_to_tree",varray(),CONNECT_DEFERRED); button_back->connect("pressed",this,"_go_to_tree",varray(),CONNECT_DEFERRED);
@ -1096,6 +1099,30 @@ void FileSystemDock::_file_option(int p_option) {
} }
} }
void FileSystemDock::_folder_option(int p_option) {
TreeItem *item = tree->get_selected();
TreeItem *child = item->get_children();
switch(p_option) {
case FOLDER_EXPAND_ALL:
item->set_collapsed(false);
while(child) {
child->set_collapsed(false);
child = child->get_next();
}
break;
case FOLDER_COLLAPSE_ALL:
while(child) {
child->set_collapsed(true);
child = child->get_next();
}
break;
}
}
void FileSystemDock::_open_pressed(){ void FileSystemDock::_open_pressed(){
@ -1126,6 +1153,17 @@ void FileSystemDock::_open_pressed(){
} }
void FileSystemDock::_dir_rmb_pressed(const Vector2& p_pos) {
folder_options->clear();
folder_options->set_size(Size2(1,1));
folder_options->add_item(TTR("Expand all"),FOLDER_EXPAND_ALL);
folder_options->add_item(TTR("Collapse all"),FOLDER_COLLAPSE_ALL);
folder_options->set_pos(files->get_global_pos() + p_pos);
folder_options->popup();
}
void FileSystemDock::_search_changed(const String& p_text) { void FileSystemDock::_search_changed(const String& p_text) {
@ -1586,6 +1624,7 @@ void FileSystemDock::_bind_methods() {
ClassDB::bind_method(_MD("_favorites_pressed"),&FileSystemDock::_favorites_pressed); ClassDB::bind_method(_MD("_favorites_pressed"),&FileSystemDock::_favorites_pressed);
// ClassDB::bind_method(_MD("_instance_pressed"),&ScenesDock::_instance_pressed); // ClassDB::bind_method(_MD("_instance_pressed"),&ScenesDock::_instance_pressed);
ClassDB::bind_method(_MD("_open_pressed"),&FileSystemDock::_open_pressed); ClassDB::bind_method(_MD("_open_pressed"),&FileSystemDock::_open_pressed);
ClassDB::bind_method(_MD("_dir_rmb_pressed"),&FileSystemDock::_dir_rmb_pressed);
ClassDB::bind_method(_MD("_thumbnail_done"),&FileSystemDock::_thumbnail_done); ClassDB::bind_method(_MD("_thumbnail_done"),&FileSystemDock::_thumbnail_done);
ClassDB::bind_method(_MD("_select_file"), &FileSystemDock::_select_file); ClassDB::bind_method(_MD("_select_file"), &FileSystemDock::_select_file);
@ -1597,6 +1636,7 @@ void FileSystemDock::_bind_methods() {
ClassDB::bind_method(_MD("_fs_changed"), &FileSystemDock::_fs_changed); ClassDB::bind_method(_MD("_fs_changed"), &FileSystemDock::_fs_changed);
ClassDB::bind_method(_MD("_dir_selected"), &FileSystemDock::_dir_selected); ClassDB::bind_method(_MD("_dir_selected"), &FileSystemDock::_dir_selected);
ClassDB::bind_method(_MD("_file_option"), &FileSystemDock::_file_option); ClassDB::bind_method(_MD("_file_option"), &FileSystemDock::_file_option);
ClassDB::bind_method(_MD("_folder_option"), &FileSystemDock::_folder_option);
ClassDB::bind_method(_MD("_move_operation"), &FileSystemDock::_move_operation); ClassDB::bind_method(_MD("_move_operation"), &FileSystemDock::_move_operation);
ClassDB::bind_method(_MD("_rename_operation"), &FileSystemDock::_rename_operation); ClassDB::bind_method(_MD("_rename_operation"), &FileSystemDock::_rename_operation);
@ -1686,6 +1726,9 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
file_options = memnew( PopupMenu ); file_options = memnew( PopupMenu );
add_child(file_options); add_child(file_options);
folder_options = memnew ( PopupMenu );
add_child(folder_options);
split_box = memnew( VSplitContainer ); split_box = memnew( VSplitContainer );
add_child(split_box); add_child(split_box);
split_box->set_v_size_flags(SIZE_EXPAND_FILL); split_box->set_v_size_flags(SIZE_EXPAND_FILL);
@ -1695,12 +1738,14 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
tree->set_hide_root(true); tree->set_hide_root(true);
split_box->add_child(tree); split_box->add_child(tree);
tree->set_drag_forwarding(this); tree->set_drag_forwarding(this);
tree->set_allow_rmb_select(true);
//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_edited",this,"_favorite_toggled");
tree->connect("item_activated",this,"_open_pressed"); tree->connect("item_activated",this,"_open_pressed");
tree->connect("cell_selected",this,"_dir_selected"); tree->connect("cell_selected",this,"_dir_selected");
tree->connect("item_rmb_selected",this,"_dir_rmb_pressed");
files = memnew( ItemList ); files = memnew( ItemList );
files->set_v_size_flags(SIZE_EXPAND_FILL); files->set_v_size_flags(SIZE_EXPAND_FILL);

View file

@ -73,6 +73,11 @@ private:
FILE_COPY_PATH FILE_COPY_PATH
}; };
enum FolderMenu {
FOLDER_EXPAND_ALL,
FOLDER_COLLAPSE_ALL
};
VBoxContainer *scanning_vb; VBoxContainer *scanning_vb;
ProgressBar *scanning_progress; ProgressBar *scanning_progress;
@ -97,6 +102,7 @@ private:
DisplayMode display_mode; DisplayMode display_mode;
PopupMenu *file_options; PopupMenu *file_options;
PopupMenu *folder_options;
DependencyEditor *deps_editor; DependencyEditor *deps_editor;
DependencyEditorOwners *owners_editor; DependencyEditorOwners *owners_editor;
@ -134,6 +140,7 @@ private:
void _file_option(int p_option); void _file_option(int p_option);
void _folder_option(int p_option);
void _update_files(bool p_keep_selection); void _update_files(bool p_keep_selection);
void _change_file_display(); void _change_file_display();
@ -151,6 +158,7 @@ private:
void _favorites_pressed(); void _favorites_pressed();
void _open_pressed(); void _open_pressed();
void _dir_rmb_pressed(const Vector2& local_mouse_pos);
void _search_changed(const String& p_text); void _search_changed(const String& p_text);