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
This commit is contained in:
Juan Linietsky 2016-05-15 20:25:51 -03:00
parent bed3efb17e
commit 8b47e26f59
5 changed files with 564 additions and 276 deletions

View File

@ -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) {
emit_signal("item_rmb_selected",i,Vector2(mb.x,mb.y));
} else {
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 (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);
}
}
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;
}

View File

@ -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();

View File

@ -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();

File diff suppressed because it is too large Load Diff

View File

@ -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);