2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* scenes_dock.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-01 14:50:53 +01:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "scenes_dock.h"
|
|
|
|
#include "os/dir_access.h"
|
|
|
|
#include "os/file_access.h"
|
|
|
|
#include "globals.h"
|
2014-10-07 06:31:49 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "io/resource_loader.h"
|
|
|
|
#include "os/os.h"
|
|
|
|
#include "editor_node.h"
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
#include "editor_settings.h"
|
2016-05-16 01:25:51 +02:00
|
|
|
#include "scene/main/viewport.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) {
|
|
|
|
|
2014-05-16 13:48:23 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *item = tree->create_item(p_parent);
|
2015-08-24 01:15:56 +02:00
|
|
|
String dname=p_dir->get_name();
|
|
|
|
if (dname=="")
|
|
|
|
dname="res://";
|
|
|
|
|
|
|
|
item->set_text(0,dname);
|
2014-02-10 02:10:30 +01:00
|
|
|
item->set_icon(0,get_icon("Folder","EditorIcons"));
|
2015-08-24 01:15:56 +02:00
|
|
|
item->set_selectable(0,true);
|
|
|
|
String lpath = p_dir->get_path();
|
|
|
|
if (lpath!="res://" && lpath.ends_with("/")) {
|
|
|
|
lpath=lpath.substr(0,lpath.length()-1);
|
|
|
|
}
|
|
|
|
item->set_metadata(0,lpath);
|
|
|
|
if (lpath==path) {
|
|
|
|
item->select(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//item->set_custom_bg_color(0,get_color("prop_subsection","Editor"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
bool has_items=false;
|
|
|
|
|
|
|
|
for(int i=0;i<p_dir->get_subdir_count();i++) {
|
|
|
|
|
|
|
|
if (_create_tree(item,p_dir->get_subdir(i)))
|
|
|
|
has_items=true;
|
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
#if 0
|
2014-02-10 02:10:30 +01:00
|
|
|
for (int i=0;i<p_dir->get_file_count();i++) {
|
|
|
|
|
2014-05-16 13:48:23 +02:00
|
|
|
String file_name = p_dir->get_file(i);
|
2014-06-17 07:34:48 +02:00
|
|
|
String file_path = p_dir->get_file_path(i);
|
2014-05-16 13:48:23 +02:00
|
|
|
|
2014-06-17 07:34:48 +02:00
|
|
|
// 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();
|
2014-05-16 13:48:23 +02:00
|
|
|
|
2014-06-17 07:34:48 +02:00
|
|
|
if (search_term!="" && search_from.findn(search_term)==-1)
|
2014-05-16 13:48:23 +02:00
|
|
|
continue;
|
|
|
|
|
2014-06-17 07:34:48 +02:00
|
|
|
bool isfave = favorites.has(file_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (button_favorite->is_pressed() && !isfave)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TreeItem *fitem = tree->create_item(item);
|
|
|
|
fitem->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
|
|
|
|
fitem->set_editable(0,true);
|
|
|
|
fitem->set_checked(0,isfave);
|
2014-05-16 13:48:23 +02:00
|
|
|
fitem->set_text(0,file_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Ref<Texture> icon = get_icon( (has_icon(p_dir->get_file_type(i),"EditorIcons")?p_dir->get_file_type(i):String("Object")),"EditorIcons");
|
|
|
|
fitem->set_icon(0, icon );
|
|
|
|
|
|
|
|
|
2014-06-17 07:34:48 +02:00
|
|
|
fitem->set_metadata(0,file_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
//if (p_dir->files[i]->icon.is_valid()) {
|
|
|
|
// fitem->set_icon(0,p_dir->files[i]->icon);
|
|
|
|
// }
|
|
|
|
has_items=true;
|
|
|
|
|
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
#endif
|
|
|
|
/*if (!has_items) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
memdelete(item);
|
|
|
|
return false;
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
}*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScenesDock::_update_tree() {
|
|
|
|
|
|
|
|
tree->clear();
|
|
|
|
updating_tree=true;
|
2015-08-24 01:15:56 +02:00
|
|
|
TreeItem *root = tree->create_item();
|
|
|
|
TreeItem *favorites = tree->create_item(root);
|
|
|
|
favorites->set_icon(0, get_icon("Favorites","EditorIcons") );
|
2016-05-04 03:25:37 +02:00
|
|
|
favorites->set_text(0,TTR("Favorites:"));
|
2015-08-24 01:15:56 +02:00
|
|
|
favorites->set_selectable(0,false);
|
|
|
|
Vector<String> faves = EditorSettings::get_singleton()->get_favorite_dirs();
|
|
|
|
for(int i=0;i<faves.size();i++) {
|
|
|
|
if (!faves[i].begins_with("res://"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TreeItem *ti = tree->create_item(favorites);
|
|
|
|
String fv = faves[i];
|
|
|
|
if (fv=="res://")
|
|
|
|
ti->set_text(0,"/");
|
|
|
|
else
|
|
|
|
ti->set_text(0,faves[i].get_file());
|
|
|
|
ti->set_icon(0,get_icon("Folder","EditorIcons"));
|
|
|
|
ti->set_selectable(0,true);
|
|
|
|
ti->set_metadata(0,faves[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
_create_tree(root,EditorFileSystem::get_singleton()->get_filesystem());
|
2014-02-10 02:10:30 +01:00
|
|
|
updating_tree=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScenesDock::_notification(int p_what) {
|
|
|
|
|
|
|
|
switch(p_what) {
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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;
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
if (initialized)
|
|
|
|
return;
|
2015-11-19 23:59:33 +01:00
|
|
|
initialized=true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"_fs_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
button_reload->set_icon( get_icon("Reload","EditorIcons"));
|
|
|
|
button_favorite->set_icon( get_icon("Favorites","EditorIcons"));
|
2016-05-16 01:25:51 +02:00
|
|
|
//button_instance->set_icon( get_icon("Add","EditorIcons"));
|
|
|
|
//button_open->set_icon( get_icon("Folder","EditorIcons"));
|
2015-08-24 01:15:56 +02:00
|
|
|
button_back->set_icon( get_icon("Filesystem","EditorIcons"));
|
|
|
|
display_mode->set_icon( get_icon("FileList","EditorIcons"));
|
|
|
|
display_mode->connect("pressed",this,"_change_file_display");
|
2016-05-16 01:25:51 +02:00
|
|
|
//file_options->set_icon( get_icon("Tools","EditorIcons"));
|
2015-08-24 01:15:56 +02:00
|
|
|
files->connect("item_activated",this,"_select_file");
|
|
|
|
button_hist_next->connect("pressed",this,"_fw_history");
|
|
|
|
button_hist_prev->connect("pressed",this,"_bw_history");
|
2016-05-24 04:24:17 +02:00
|
|
|
search_icon->set_texture( get_icon("Zoom","EditorIcons"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
button_hist_next->set_icon( get_icon("Forward","EditorIcons"));
|
|
|
|
button_hist_prev->set_icon( get_icon("Back","EditorIcons"));
|
2016-05-16 01:25:51 +02:00
|
|
|
file_options->connect("item_pressed",this,"_file_option");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
button_back->connect("pressed",this,"_go_to_tree",varray(),CONNECT_DEFERRED);
|
|
|
|
current_path->connect("text_entered",this,"_go_to_dir");
|
|
|
|
_update_tree(); //maybe it finished already
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
if (EditorFileSystem::get_singleton()->is_scanning()) {
|
|
|
|
_set_scannig_mode();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
if (EditorFileSystem::get_singleton()->is_scanning()) {
|
|
|
|
scanning_progress->set_val(EditorFileSystem::get_singleton()->get_scanning_progress()*100);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_DRAG_BEGIN: {
|
|
|
|
|
|
|
|
Dictionary dd = get_viewport()->gui_get_drag_data();
|
2016-05-24 04:24:17 +02:00
|
|
|
if (tree->is_visible() && dd.has("type") ) {
|
|
|
|
if ( (String(dd["type"])=="files") || (String(dd["type"])=="files_and_dirs") || (String(dd["type"])=="resource")) {
|
|
|
|
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
|
|
|
|
}
|
|
|
|
if ( (String(dd["type"])=="favorite") ) {
|
|
|
|
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
|
|
|
|
}
|
2016-05-16 01:25:51 +02:00
|
|
|
}
|
2016-05-24 04:24:17 +02:00
|
|
|
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_DRAG_END: {
|
|
|
|
|
|
|
|
tree->set_drop_mode_flags(0);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2015-12-15 17:39:13 +01:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-15 17:39:13 +01:00
|
|
|
display_mode->set_pressed(int(EditorSettings::get_singleton()->get("file_dialog/display_mode"))==EditorFileDialog::DISPLAY_LIST);
|
|
|
|
|
|
|
|
_change_file_display();
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
void ScenesDock::_dir_selected() {
|
|
|
|
|
|
|
|
TreeItem *ti = tree->get_selected();
|
|
|
|
if (!ti)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2015-08-24 01:15:56 +02:00
|
|
|
String dir = ti->get_metadata(0);
|
|
|
|
bool found=false;
|
|
|
|
Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
|
|
|
|
for(int i=0;i<favorites.size();i++) {
|
|
|
|
|
|
|
|
if (favorites[i]==dir) {
|
|
|
|
found=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
button_favorite->set_pressed(found);
|
|
|
|
if (ti->get_parent() && ti->get_parent()->get_parent()==tree->get_root() && !ti->get_parent()->get_prev()) {
|
|
|
|
|
|
|
|
//a favorite!!!
|
|
|
|
} else {
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!split_mode) {
|
|
|
|
_open_pressed(); //go directly to dir
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScenesDock::_favorites_pressed() {
|
|
|
|
|
|
|
|
TreeItem *sel = tree->get_selected();
|
|
|
|
if (!sel)
|
|
|
|
return ;
|
|
|
|
String dir = sel->get_metadata(0);
|
|
|
|
|
|
|
|
int idx = -1;
|
|
|
|
Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
|
|
|
|
for(int i=0;i<favorites.size();i++) {
|
|
|
|
|
|
|
|
if (favorites[i]==dir) {
|
|
|
|
idx=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (button_favorite->is_pressed() && idx==-1) {
|
|
|
|
favorites.push_back(dir);
|
|
|
|
EditorSettings::get_singleton()->set_favorite_dirs(favorites);
|
|
|
|
_update_tree();
|
|
|
|
} else if (!button_favorite->is_pressed() && idx!=-1) {
|
|
|
|
favorites.remove(idx);
|
|
|
|
EditorSettings::get_singleton()->set_favorite_dirs(favorites);
|
|
|
|
_update_tree();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String ScenesDock::get_selected_path() const {
|
|
|
|
|
|
|
|
TreeItem *sel = tree->get_selected();
|
|
|
|
if (!sel)
|
|
|
|
return "";
|
|
|
|
String path = sel->get_metadata(0);
|
|
|
|
return "res://"+path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
void ScenesDock::_thumbnail_done(const String& p_path,const Ref<Texture>& p_preview, const Variant& p_udata) {
|
2015-09-08 03:55:47 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
bool valid=false;
|
2015-09-08 03:55:47 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (!search_box->is_hidden()) {
|
|
|
|
valid=true;
|
|
|
|
} else {
|
|
|
|
valid=(path==p_path.get_base_dir());
|
2015-09-08 03:55:47 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (p_preview.is_valid() && valid) {
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
Array uarr=p_udata;
|
|
|
|
int idx=uarr[0];
|
|
|
|
String file=uarr[1];
|
2015-08-24 01:15:56 +02:00
|
|
|
if (idx>=files->get_item_count())
|
|
|
|
return;
|
2016-05-16 01:25:51 +02:00
|
|
|
if (files->get_item_text(idx)!=file)
|
|
|
|
return;
|
2015-08-24 01:15:56 +02:00
|
|
|
String fpath = files->get_item_metadata(idx);
|
|
|
|
if (fpath!=p_path)
|
|
|
|
return;
|
|
|
|
files->set_item_icon(idx,p_preview);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_change_file_display() {
|
|
|
|
|
|
|
|
if (display_mode->is_pressed()) {
|
|
|
|
display_mode->set_icon( get_icon("FileThumbnail","EditorIcons"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
display_mode->set_icon( get_icon("FileList","EditorIcons"));
|
|
|
|
}
|
|
|
|
|
|
|
|
_update_files(true);
|
|
|
|
}
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
void ScenesDock::_update_files(bool p_keep_selection) {
|
|
|
|
|
|
|
|
Set<String> cselection;
|
|
|
|
|
|
|
|
if (p_keep_selection) {
|
|
|
|
|
|
|
|
for(int i=0;i<files->get_item_count();i++) {
|
|
|
|
|
|
|
|
if (files->is_selected(i))
|
|
|
|
cselection.insert(files->get_item_text(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
files->clear();
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
current_path->set_text(path);
|
|
|
|
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
|
|
|
|
if (!efd)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
|
|
|
|
Ref<Texture> folder_thumbnail;
|
|
|
|
Ref<Texture> file_thumbnail;
|
|
|
|
|
|
|
|
bool use_thumbnails=!display_mode->is_pressed();
|
2016-05-24 04:24:17 +02:00
|
|
|
bool use_folders = search_box->get_text().length()==0 && split_mode;
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
if (use_thumbnails) { //thumbnails
|
|
|
|
|
|
|
|
files->set_max_columns(0);
|
|
|
|
files->set_icon_mode(ItemList::ICON_MODE_TOP);
|
|
|
|
files->set_fixed_column_width(thumbnail_size*3/2);
|
|
|
|
files->set_max_text_lines(2);
|
|
|
|
files->set_min_icon_size(Size2(thumbnail_size,thumbnail_size));
|
|
|
|
|
|
|
|
if (!has_icon("ResizedFolder","EditorIcons")) {
|
|
|
|
Ref<ImageTexture> folder = get_icon("FolderBig","EditorIcons");
|
|
|
|
Image img = folder->get_data();
|
|
|
|
img.resize(thumbnail_size,thumbnail_size);
|
|
|
|
Ref<ImageTexture> resized_folder = Ref<ImageTexture>( memnew( ImageTexture));
|
|
|
|
resized_folder->create_from_image(img,0);
|
2016-05-11 16:46:08 +02:00
|
|
|
Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
folder_thumbnail = get_icon("ResizedFolder","EditorIcons");
|
|
|
|
|
|
|
|
if (!has_icon("ResizedFile","EditorIcons")) {
|
|
|
|
Ref<ImageTexture> file = get_icon("FileBig","EditorIcons");
|
|
|
|
Image img = file->get_data();
|
|
|
|
img.resize(thumbnail_size,thumbnail_size);
|
|
|
|
Ref<ImageTexture> resized_file = Ref<ImageTexture>( memnew( ImageTexture));
|
|
|
|
resized_file->create_from_image(img,0);
|
2016-05-11 16:46:08 +02:00
|
|
|
Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
file_thumbnail = get_icon("ResizedFile","EditorIcons");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
files->set_icon_mode(ItemList::ICON_MODE_LEFT);
|
|
|
|
files->set_max_columns(1);
|
|
|
|
files->set_max_text_lines(1);
|
|
|
|
files->set_fixed_column_width(0);
|
|
|
|
files->set_min_icon_size(Size2());
|
|
|
|
|
2014-10-15 00:44:41 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (use_folders) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (path!="res://") {
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
List<FileInfo> filelist;
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-24 04:24:17 +02:00
|
|
|
if (search_box->get_text().length()) {
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (search_box->get_text().length()>1) {
|
|
|
|
_search(EditorFileSystem::get_singleton()->get_filesystem(),&filelist,128);
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
filelist.sort();
|
|
|
|
} else {
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
StringName ei="EditorIcons"; //make it faster..
|
|
|
|
StringName oi="Object";
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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;
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
Ref<Texture> type_icon;
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (has_icon(type,ei)) {
|
|
|
|
type_icon=get_icon(type,ei);
|
2015-08-24 01:15:56 +02:00
|
|
|
} else {
|
2016-05-16 01:25:51 +02:00
|
|
|
type_icon=get_icon(oi,ei);
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
2015-08-24 01:15:56 +02:00
|
|
|
} else {
|
|
|
|
files->add_item(fname,type_icon,true);
|
|
|
|
files->set_item_metadata(files->get_item_count()-1,fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cselection.has(fname))
|
|
|
|
files->select(files->get_item_count()-1,false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_select_file(int p_idx) {
|
|
|
|
|
|
|
|
files->select(p_idx,true);
|
2016-05-16 01:25:51 +02:00
|
|
|
_file_option(FILE_OPEN);
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_go_to_tree() {
|
|
|
|
|
|
|
|
tree->show();
|
2016-05-16 01:25:51 +02:00
|
|
|
file_list_vb->hide();
|
2015-08-24 01:15:56 +02:00
|
|
|
_update_tree();
|
|
|
|
tree->grab_focus();
|
|
|
|
tree->ensure_cursor_is_visible();
|
|
|
|
button_favorite->show();
|
2016-05-16 01:25:51 +02:00
|
|
|
//button_open->hide();
|
|
|
|
//file_options->hide();
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_go_to_dir(const String& p_dir){
|
|
|
|
|
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
if (da->change_dir(p_dir)==OK) {
|
|
|
|
path=da->get_current_dir();
|
|
|
|
_update_files(false);
|
|
|
|
}
|
|
|
|
current_path->set_text(path);
|
|
|
|
memdelete(da);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
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();
|
2016-05-16 01:25:51 +02:00
|
|
|
split_box->show();
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (!tree->is_hidden()) {
|
2015-08-24 01:15:56 +02:00
|
|
|
button_favorite->show();
|
|
|
|
_update_tree();
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file_list_vb->is_hidden()) {
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
_update_files(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_process(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_set_scannig_mode() {
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
split_box->hide();
|
2015-08-24 01:15:56 +02:00
|
|
|
button_hist_prev->set_disabled(true);
|
|
|
|
button_hist_next->set_disabled(true);
|
|
|
|
scanning_vb->show();
|
|
|
|
set_process(true);
|
|
|
|
if (EditorFileSystem::get_singleton()->is_scanning()) {
|
|
|
|
scanning_progress->set_val(EditorFileSystem::get_singleton()->get_scanning_progress()*100);
|
|
|
|
} else {
|
|
|
|
scanning_progress->set_val(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_fw_history() {
|
|
|
|
|
|
|
|
if (history_pos<history.size()-1)
|
|
|
|
history_pos++;
|
|
|
|
|
|
|
|
path=history[history_pos];
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (!tree->is_hidden()) {
|
2015-08-24 01:15:56 +02:00
|
|
|
_update_tree();
|
|
|
|
tree->grab_focus();
|
|
|
|
tree->ensure_cursor_is_visible();
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file_list_vb->is_hidden()) {
|
2015-08-24 01:15:56 +02:00
|
|
|
_update_files(false);
|
|
|
|
current_path->set_text(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
button_hist_prev->set_disabled(history_pos==0);
|
|
|
|
button_hist_next->set_disabled(history_pos+1==history.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_bw_history() {
|
|
|
|
|
|
|
|
if (history_pos>0)
|
|
|
|
history_pos--;
|
|
|
|
|
|
|
|
path=history[history_pos];
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
if (!tree->is_hidden()) {
|
2015-08-24 01:15:56 +02:00
|
|
|
_update_tree();
|
|
|
|
tree->grab_focus();
|
|
|
|
tree->ensure_cursor_is_visible();
|
2016-05-16 01:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!file_list_vb->is_hidden()) {
|
2015-08-24 01:15:56 +02:00
|
|
|
_update_files(false);
|
|
|
|
current_path->set_text(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
button_hist_prev->set_disabled(history_pos==0);
|
|
|
|
button_hist_next->set_disabled(history_pos+1==history.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_push_to_history() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
history.resize(history_pos+1);
|
|
|
|
if (history[history_pos]!=path) {
|
|
|
|
history.push_back(path);
|
|
|
|
history_pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
button_hist_prev->set_disabled(history_pos==0);
|
|
|
|
button_hist_next->set_disabled(history_pos+1==history.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScenesDock::_find_inside_move_files(EditorFileSystemDirectory *efsd,Vector<String>& files) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
for(int i=0;i<efsd->get_subdir_count();i++) {
|
|
|
|
_find_inside_move_files(efsd->get_subdir(i),files);
|
|
|
|
}
|
|
|
|
for(int i=0;i<efsd->get_file_count();i++) {
|
|
|
|
files.push_back(efsd->get_file_path(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
void ScenesDock::_find_remaps(EditorFileSystemDirectory *efsd,Map<String,String> &renames,List<String>& to_remaps) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
for(int i=0;i<efsd->get_subdir_count();i++) {
|
|
|
|
_find_remaps(efsd->get_subdir(i),renames,to_remaps);
|
|
|
|
}
|
|
|
|
for(int i=0;i<efsd->get_file_count();i++) {
|
|
|
|
Vector<String> deps=efsd->get_file_deps(i);
|
|
|
|
for(int j=0;j<deps.size();j++) {
|
|
|
|
if (renames.has(deps[j])) {
|
|
|
|
to_remaps.push_back(efsd->get_file_path(i));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScenesDock::_rename_operation(const String& p_to_path) {
|
|
|
|
|
|
|
|
if (move_files[0]==p_to_path) {
|
2016-05-04 03:25:37 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Same source and destination files, doing nothing."));
|
2015-08-24 01:15:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (FileAccess::exists(p_to_path)) {
|
|
|
|
EditorNode::get_singleton()->show_warning("Target file exists, can't overwrite. Delete first.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String,String> renames;
|
|
|
|
renames[move_files[0]]=p_to_path;
|
|
|
|
|
|
|
|
List<String> remap;
|
|
|
|
|
|
|
|
_find_remaps(EditorFileSystem::get_singleton()->get_filesystem(),renames,remap);
|
|
|
|
print_line("found files to remap: "+itos(remap.size()));
|
|
|
|
|
|
|
|
//perform remaps
|
|
|
|
for(List<String>::Element *E=remap.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
Error err = ResourceLoader::rename_dependencies(E->get(),renames);
|
|
|
|
print_line("remapping: "+E->get());
|
|
|
|
|
|
|
|
if (err!=OK) {
|
|
|
|
EditorNode::get_singleton()->add_io_error("Can't rename deps for:\n"+E->get()+"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//finally, perform moves
|
|
|
|
|
|
|
|
DirAccess *da=DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
|
|
|
|
Error err = da->rename(move_files[0],p_to_path);
|
|
|
|
print_line("moving file "+move_files[0]+" to "+p_to_path);
|
|
|
|
if (err!=OK) {
|
|
|
|
EditorNode::get_singleton()->add_io_error("Error moving file:\n"+move_files[0]+"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//rescan everything
|
|
|
|
memdelete(da);
|
|
|
|
print_line("call rescan!");
|
|
|
|
_rescan();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScenesDock::_move_operation(const String& p_to_path) {
|
|
|
|
|
|
|
|
if (p_to_path==path) {
|
2016-05-04 03:25:37 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Same source and destination paths, doing nothing."));
|
2015-08-24 01:15:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//find files inside dirs to be moved
|
|
|
|
|
|
|
|
Vector<String> inside_files;
|
|
|
|
|
|
|
|
for(int i=0;i<move_dirs.size();i++) {
|
|
|
|
if (p_to_path.begins_with(move_dirs[i])) {
|
2016-05-19 00:08:12 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Can't move directories to within themselves."));
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2015-08-24 01:15:56 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
EditorFileSystemDirectory *efsd=EditorFileSystem::get_singleton()->get_path(move_dirs[i]);
|
|
|
|
if (!efsd)
|
|
|
|
continue;
|
|
|
|
_find_inside_move_files(efsd,inside_files);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
//make list of remaps
|
|
|
|
Map<String,String> renames;
|
|
|
|
String repfrom=path=="res://"?path:String(path+"/");
|
|
|
|
String repto=p_to_path=="res://"?p_to_path:String(p_to_path+"/");
|
|
|
|
|
|
|
|
for(int i=0;i<move_files.size();i++) {
|
|
|
|
renames[move_files[i]]=move_files[i].replace_first(repfrom,repto);
|
|
|
|
print_line("move file "+move_files[i]+" -> "+renames[move_files[i]]);
|
|
|
|
}
|
|
|
|
for(int i=0;i<inside_files.size();i++) {
|
|
|
|
renames[inside_files[i]]=inside_files[i].replace_first(repfrom,repto);
|
|
|
|
print_line("inside file "+inside_files[i]+" -> "+renames[inside_files[i]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//make list of files that will be run the remapping
|
|
|
|
List<String> remap;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
_find_remaps(EditorFileSystem::get_singleton()->get_filesystem(),renames,remap);
|
|
|
|
print_line("found files to remap: "+itos(remap.size()));
|
|
|
|
|
|
|
|
//perform remaps
|
|
|
|
for(List<String>::Element *E=remap.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
Error err = ResourceLoader::rename_dependencies(E->get(),renames);
|
|
|
|
print_line("remapping: "+E->get());
|
|
|
|
|
|
|
|
if (err!=OK) {
|
|
|
|
EditorNode::get_singleton()->add_io_error("Can't rename deps for:\n"+E->get()+"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//finally, perform moves
|
|
|
|
|
|
|
|
DirAccess *da=DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
|
|
|
|
for(int i=0;i<move_files.size();i++) {
|
|
|
|
|
|
|
|
String to = move_files[i].replace_first(repfrom,repto);
|
|
|
|
Error err = da->rename(move_files[i],to);
|
|
|
|
print_line("moving file "+move_files[i]+" to "+to);
|
|
|
|
if (err!=OK) {
|
|
|
|
EditorNode::get_singleton()->add_io_error("Error moving file:\n"+move_files[i]+"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0;i<move_dirs.size();i++) {
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
2015-08-24 01:15:56 +02:00
|
|
|
if (err!=OK) {
|
|
|
|
EditorNode::get_singleton()->add_io_error("Error moving dir:\n"+move_dirs[i]+"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memdelete(da);
|
|
|
|
//rescan everything
|
|
|
|
print_line("call rescan!");
|
|
|
|
_rescan();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::_file_option(int p_option) {
|
|
|
|
|
|
|
|
switch(p_option) {
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
|
2016-05-18 09:37:59 +02:00
|
|
|
case FILE_SHOW_IN_EXPLORER:
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
2016-05-18 09:37:59 +02:00
|
|
|
if (p_option == FILE_SHOW_IN_EXPLORER) {
|
2016-05-21 14:08:35 +02:00
|
|
|
String dir = Globals::get_singleton()->globalize_path(path);
|
|
|
|
dir = dir.substr(0, dir.find_last("/"));
|
2016-05-18 09:37:59 +02:00
|
|
|
OS::get_singleton()->shell_open(String("file://")+dir);
|
|
|
|
return;
|
|
|
|
}
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
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;
|
2015-08-24 01:15:56 +02:00
|
|
|
case FILE_DEPENDENCIES: {
|
|
|
|
|
|
|
|
int idx = files->get_current();
|
|
|
|
if (idx<0 || idx>=files->get_item_count())
|
|
|
|
break;
|
|
|
|
String path = files->get_item_metadata(idx);
|
|
|
|
deps_editor->edit(path);
|
|
|
|
} break;
|
|
|
|
case FILE_OWNERS: {
|
|
|
|
|
|
|
|
int idx = files->get_current();
|
|
|
|
if (idx<0 || idx>=files->get_item_count())
|
|
|
|
break;
|
|
|
|
String path = files->get_item_metadata(idx);
|
|
|
|
owners_editor->show(path);
|
|
|
|
} break;
|
|
|
|
case FILE_MOVE: {
|
|
|
|
|
|
|
|
move_dirs.clear();;
|
|
|
|
move_files.clear();
|
|
|
|
|
|
|
|
for(int i=0;i<files->get_item_count();i++) {
|
|
|
|
|
|
|
|
String path = files->get_item_metadata(i);
|
|
|
|
if (!files->is_selected(i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (files->get_item_text(i)=="..") {
|
2016-05-04 03:25:37 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Can't operate on '..'"));
|
2015-08-24 01:15:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.ends_with("/")) {
|
|
|
|
move_dirs.push_back(path.substr(0,path.length()-1));
|
|
|
|
} else {
|
|
|
|
move_files.push_back(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (move_dirs.empty() && move_files.size()==1) {
|
|
|
|
|
|
|
|
rename_dialog->clear_filters();
|
|
|
|
rename_dialog->add_filter("*."+move_files[0].extension());
|
|
|
|
rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
|
|
|
rename_dialog->set_current_path(move_files[0]);
|
|
|
|
rename_dialog->popup_centered_ratio();
|
2016-05-19 00:08:12 +02:00
|
|
|
rename_dialog->set_title(TTR("Pick New Name and Location For:")+" "+move_files[0].get_file());
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//just move
|
|
|
|
move_dialog->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case FILE_REMOVE: {
|
|
|
|
|
|
|
|
Vector<String> torem;
|
|
|
|
|
|
|
|
for(int i=0;i<files->get_item_count();i++) {
|
|
|
|
|
|
|
|
String path = files->get_item_metadata(i);
|
|
|
|
if (path.ends_with("/") || !files->is_selected(i))
|
|
|
|
continue;
|
|
|
|
torem.push_back(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (torem.empty()) {
|
2016-05-04 03:25:37 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("No files selected!"));
|
2015-08-24 01:15:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_dialog->show(torem);
|
|
|
|
//1) find if used
|
|
|
|
//2) warn
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case FILE_INFO: {
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
void ScenesDock::_open_pressed(){
|
|
|
|
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
|
|
|
}*/
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
//tree_mode=false;
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (split_mode) {
|
2015-08-24 01:15:56 +02:00
|
|
|
tree->hide();
|
2016-05-16 01:25:51 +02:00
|
|
|
file_list_vb->show();
|
2015-08-24 01:15:56 +02:00
|
|
|
button_favorite->hide();
|
2016-05-16 01:25:51 +02:00
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
//file_options->show();
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
_update_files(false);
|
|
|
|
current_path->set_text(path);
|
|
|
|
_push_to_history();
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
// emit_signal("open",path);
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
void ScenesDock::_search_changed(const String& p_text) {
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (!search_box->is_visible())
|
|
|
|
return; //wtf
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
_update_files(false);
|
|
|
|
}
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ScenesDock::_rescan() {
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
_set_scannig_mode();
|
2014-02-10 02:10:30 +01:00
|
|
|
EditorFileSystem::get_singleton()->scan();
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::fix_dependencies(const String& p_for_file) {
|
|
|
|
deps_editor->edit(p_for_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
void ScenesDock::focus_on_filter() {
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-15 17:39:13 +01:00
|
|
|
void ScenesDock::set_use_thumbnails(bool p_use) {
|
|
|
|
|
|
|
|
display_mode->set_pressed(!p_use);
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:46:08 +02:00
|
|
|
|
|
|
|
Variant ScenesDock::get_drag_data_fw(const Point2& p_point,Control* p_from) {
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
2016-05-24 04:24:17 +02:00
|
|
|
Dictionary d = EditorNode::get_singleton()->drag_files(paths,p_from);
|
|
|
|
|
|
|
|
if (selected->get_parent() && tree->get_root()->get_children()==selected->get_parent()) {
|
|
|
|
//a favorite.. treat as such
|
|
|
|
d["type"]="favorite";
|
|
|
|
}
|
|
|
|
|
|
|
|
return d;
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:46:08 +02:00
|
|
|
if (p_from==files) {
|
|
|
|
|
|
|
|
List<int> seldirs;
|
|
|
|
List<int> selfiles;
|
|
|
|
|
|
|
|
for (int i = 0; i<files->get_item_count(); i++) {
|
|
|
|
if (files->is_selected(i)) {
|
|
|
|
String path = files->get_item_metadata(i);
|
|
|
|
if (path.ends_with("/"))
|
|
|
|
seldirs.push_back(i);
|
|
|
|
else
|
|
|
|
selfiles.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seldirs.empty() && selfiles.empty())
|
|
|
|
return Variant();
|
|
|
|
//if (seldirs.size() && selfiles.size())
|
|
|
|
// return Variant(); //can't really mix files and dirs (i think?) - yes you can, commenting
|
|
|
|
|
|
|
|
/*if (selfiles.size()==1) {
|
|
|
|
Ref<Resource> resource = ResourceLoader::load(files->get_item_metadata(selfiles.front()->get()));
|
|
|
|
if (resource.is_valid()) {
|
|
|
|
return EditorNode::get_singleton()->drag_resource(resource,p_from);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if (selfiles.size()>0 && seldirs.size()==0) {
|
|
|
|
Vector<String> fnames;
|
|
|
|
for(List<int>::Element *E=selfiles.front();E;E=E->next()) {
|
|
|
|
fnames.push_back(files->get_item_metadata(E->get()));
|
|
|
|
}
|
|
|
|
return EditorNode::get_singleton()->drag_files(fnames,p_from);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selfiles.size()>0 || seldirs.size()>0) {
|
|
|
|
Vector<String> fnames;
|
|
|
|
for(List<int>::Element *E=selfiles.front();E;E=E->next()) {
|
|
|
|
fnames.push_back(files->get_item_metadata(E->get()));
|
|
|
|
}
|
|
|
|
for(List<int>::Element *E=seldirs.front();E;E=E->next()) {
|
|
|
|
fnames.push_back(files->get_item_metadata(E->get()));
|
|
|
|
}
|
|
|
|
return EditorNode::get_singleton()->drag_files_and_dirs(fnames,p_from);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScenesDock::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{
|
|
|
|
|
|
|
|
Dictionary drag_data = p_data;
|
|
|
|
|
2016-05-24 04:24:17 +02:00
|
|
|
if (drag_data.has("type") && String(drag_data["type"])=="favorite") {
|
|
|
|
|
|
|
|
//moving favorite around
|
|
|
|
TreeItem *ti = tree->get_item_at_pos(p_point);
|
|
|
|
if (!ti)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int what = tree->get_drop_section_at_pos(p_point);
|
|
|
|
|
|
|
|
if (ti==tree->get_root()->get_children()) {
|
|
|
|
return (what==1); //the parent, first fav
|
|
|
|
}
|
|
|
|
if (ti->get_parent() && tree->get_root()->get_children()==ti->get_parent()) {
|
|
|
|
return true; // a favorite
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ti==tree->get_root()->get_children()->get_next()) {
|
|
|
|
return (what==-1); //the tree, last fav
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-12 01:57:52 +02:00
|
|
|
|
2016-05-11 16:46:08 +02:00
|
|
|
if (drag_data.has("type") && String(drag_data["type"])=="resource") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) {
|
|
|
|
|
|
|
|
Vector<String> fnames = drag_data["files"];
|
|
|
|
|
|
|
|
if (p_from==files) {
|
|
|
|
|
|
|
|
int at_pos = files->get_item_at_pos(p_point);
|
|
|
|
if (at_pos!=-1) {
|
|
|
|
|
|
|
|
String dir = files->get_item_metadata(at_pos);
|
|
|
|
if (dir.ends_with("/"))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScenesDock::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){
|
|
|
|
|
|
|
|
if (!can_drop_data_fw(p_point,p_data,p_from))
|
|
|
|
return;
|
|
|
|
Dictionary drag_data = p_data;
|
|
|
|
|
2016-05-24 04:24:17 +02:00
|
|
|
if (drag_data.has("type") && String(drag_data["type"])=="favorite") {
|
|
|
|
|
|
|
|
//moving favorite around
|
|
|
|
TreeItem *ti = tree->get_item_at_pos(p_point);
|
|
|
|
if (!ti)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vector<String> files = drag_data["files"];
|
|
|
|
|
|
|
|
ERR_FAIL_COND(files.size()!=1);
|
|
|
|
|
|
|
|
String swap = files[0];
|
|
|
|
if (swap!="res://" && swap.ends_with("/")) {
|
|
|
|
swap=swap.substr(0,swap.length()-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int what = tree->get_drop_section_at_pos(p_point);
|
|
|
|
|
|
|
|
TreeItem *swap_item=NULL;
|
|
|
|
|
|
|
|
if (ti==tree->get_root()->get_children()) {
|
|
|
|
swap_item=tree->get_root()->get_children()->get_children();
|
|
|
|
|
|
|
|
} else if (ti->get_parent() && tree->get_root()->get_children()==ti->get_parent()) {
|
|
|
|
if (what==-1) {
|
|
|
|
swap_item=ti;
|
|
|
|
} else {
|
|
|
|
swap_item=ti->get_next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String swap_with;
|
|
|
|
|
|
|
|
if (swap_item) {
|
|
|
|
swap_with=swap_item->get_metadata(0);
|
|
|
|
if (swap_with!="res://" && swap_with.ends_with("/")) {
|
|
|
|
swap_with=swap_with.substr(0,swap_with.length()-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swap==swap_with)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vector<String> dirs = EditorSettings::get_singleton()->get_favorite_dirs();
|
|
|
|
|
|
|
|
ERR_FAIL_COND(dirs.find(swap)==-1);
|
|
|
|
ERR_FAIL_COND(swap_with!=String() && dirs.find(swap_with)==-1);
|
|
|
|
|
|
|
|
dirs.erase(swap);
|
|
|
|
|
|
|
|
if (swap_with==String()) {
|
|
|
|
dirs.push_back(swap);
|
|
|
|
} else {
|
|
|
|
int idx = dirs.find(swap_with);
|
|
|
|
dirs.insert(idx,swap);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorSettings::get_singleton()->set_favorite_dirs(dirs);
|
|
|
|
_update_tree();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:46:08 +02:00
|
|
|
if (drag_data.has("type") && String(drag_data["type"])=="resource") {
|
|
|
|
Ref<Resource> res = drag_data["resource"];
|
|
|
|
|
|
|
|
if (!res.is_valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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;
|
2016-05-11 16:46:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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;
|
|
|
|
}
|
2016-05-11 16:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) {
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
if (p_from==files || p_from==tree) {
|
2016-05-11 16:46:08 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
String to_dir;
|
|
|
|
|
|
|
|
if (p_from==files) {
|
2016-05-11 16:46:08 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
int at_pos = files->get_item_at_pos(p_point);
|
|
|
|
ERR_FAIL_COND(at_pos==-1);
|
2016-05-23 23:14:47 +02:00
|
|
|
to_dir = files->get_item_metadata(at_pos);
|
2016-05-16 01:25:51 +02:00
|
|
|
} 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);
|
|
|
|
}
|
2016-05-11 16:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
2016-05-18 09:37:59 +02:00
|
|
|
|
|
|
|
file_options->add_separator();
|
2016-05-21 14:08:35 +02:00
|
|
|
file_options->add_item(TTR("Show In File Manager"),FILE_SHOW_IN_EXPLORER);
|
2016-05-18 09:37:59 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
file_options->set_pos(files->get_global_pos() + p_pos);
|
|
|
|
file_options->popup();
|
|
|
|
|
|
|
|
}
|
2016-05-11 16:46:08 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ScenesDock::_bind_methods() {
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("_update_tree"),&ScenesDock::_update_tree);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_rescan"),&ScenesDock::_rescan);
|
2015-08-24 01:15:56 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_favorites_pressed"),&ScenesDock::_favorites_pressed);
|
2016-05-16 01:25:51 +02:00
|
|
|
// ObjectTypeDB::bind_method(_MD("_instance_pressed"),&ScenesDock::_instance_pressed);
|
2014-02-10 02:10:30 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("_open_pressed"),&ScenesDock::_open_pressed);
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("_thumbnail_done"),&ScenesDock::_thumbnail_done);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_select_file"), &ScenesDock::_select_file);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_go_to_tree"), &ScenesDock::_go_to_tree);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_go_to_dir"), &ScenesDock::_go_to_dir);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_change_file_display"), &ScenesDock::_change_file_display);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_fw_history"), &ScenesDock::_fw_history);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_bw_history"), &ScenesDock::_bw_history);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_fs_changed"), &ScenesDock::_fs_changed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_dir_selected"), &ScenesDock::_dir_selected);
|
|
|
|
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);
|
2016-05-24 04:24:17 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_search_changed"), &ScenesDock::_search_changed);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-11 16:46:08 +02:00
|
|
|
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);
|
2016-05-16 01:25:51 +02:00
|
|
|
ObjectTypeDB::bind_method(_MD("_files_list_rmb_select"),&ScenesDock::_files_list_rmb_select);
|
2016-05-11 16:46:08 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("instance"));
|
|
|
|
ADD_SIGNAL(MethodInfo("open"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ScenesDock::ScenesDock(EditorNode *p_editor) {
|
|
|
|
|
|
|
|
editor=p_editor;
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
|
2014-05-16 13:48:23 +02:00
|
|
|
HBoxContainer *toolbar_hbc = memnew( HBoxContainer );
|
|
|
|
add_child(toolbar_hbc);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
button_hist_prev = memnew( ToolButton );
|
|
|
|
toolbar_hbc->add_child(button_hist_prev);
|
|
|
|
button_hist_prev->set_disabled(true);
|
2016-05-04 03:25:37 +02:00
|
|
|
button_hist_prev->set_tooltip(TTR("Previous Directory"));
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
button_hist_next = memnew( ToolButton );
|
|
|
|
toolbar_hbc->add_child(button_hist_next);
|
|
|
|
button_hist_next->set_disabled(true);
|
|
|
|
button_hist_prev->set_focus_mode(FOCUS_NONE);
|
|
|
|
button_hist_next->set_focus_mode(FOCUS_NONE);
|
2016-05-04 03:25:37 +02:00
|
|
|
button_hist_next->set_tooltip(TTR("Next Directory"));
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-24 04:24:17 +02:00
|
|
|
current_path=memnew( LineEdit );
|
|
|
|
current_path->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
toolbar_hbc->add_child(current_path);
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
button_reload = memnew( Button );
|
|
|
|
button_reload->set_flat(true);
|
2016-03-09 00:00:52 +01:00
|
|
|
button_reload->connect("pressed",this,"_rescan");
|
2014-05-16 13:48:23 +02:00
|
|
|
toolbar_hbc->add_child(button_reload);
|
2015-08-24 01:15:56 +02:00
|
|
|
button_reload->set_focus_mode(FOCUS_NONE);
|
2016-05-04 03:25:37 +02:00
|
|
|
button_reload->set_tooltip(TTR("Re-Scan Filesystem"));
|
2016-05-24 04:24:17 +02:00
|
|
|
button_reload->hide();
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-24 04:24:17 +02:00
|
|
|
//toolbar_hbc->add_spacer();
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
button_favorite = memnew( Button );
|
|
|
|
button_favorite->set_flat(true);
|
|
|
|
button_favorite->set_toggle_mode(true);
|
2015-08-24 01:15:56 +02:00
|
|
|
button_favorite->connect("pressed",this,"_favorites_pressed");
|
2014-05-16 13:48:23 +02:00
|
|
|
toolbar_hbc->add_child(button_favorite);
|
2016-05-04 03:25:37 +02:00
|
|
|
button_favorite->set_tooltip(TTR("Toggle folder status as Favorite"));
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
button_favorite->set_focus_mode(FOCUS_NONE);
|
2016-05-24 04:24:17 +02:00
|
|
|
|
|
|
|
Control *spacer = memnew( Control);
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
/*
|
2014-02-10 02:10:30 +01:00
|
|
|
button_open = memnew( Button );
|
|
|
|
button_open->set_flat(true);
|
|
|
|
button_open->connect("pressed",this,"_open_pressed");
|
2014-05-16 13:48:23 +02:00
|
|
|
toolbar_hbc->add_child(button_open);
|
2015-08-24 01:15:56 +02:00
|
|
|
button_open->hide();
|
|
|
|
button_open->set_focus_mode(FOCUS_NONE);
|
|
|
|
button_open->set_tooltip("Open the selected file.\nOpen as scene if a scene, or as resource otherwise.");
|
|
|
|
|
2014-05-16 13:48:23 +02:00
|
|
|
|
|
|
|
button_instance = memnew( Button );
|
|
|
|
button_instance->set_flat(true);
|
|
|
|
button_instance->connect("pressed",this,"_instance_pressed");
|
|
|
|
toolbar_hbc->add_child(button_instance);
|
2015-08-24 01:15:56 +02:00
|
|
|
button_instance->hide();
|
|
|
|
button_instance->set_focus_mode(FOCUS_NONE);
|
2016-05-04 03:25:37 +02:00
|
|
|
button_instance->set_tooltip(TTR("Instance the selected scene(s) as child of the selected node."));
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
*/
|
|
|
|
file_options = memnew( PopupMenu );
|
|
|
|
add_child(file_options);
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
split_box = memnew( VSplitContainer );
|
|
|
|
add_child(split_box);
|
|
|
|
split_box->set_v_size_flags(SIZE_EXPAND_FILL);
|
2014-05-16 13:48:23 +02:00
|
|
|
|
|
|
|
tree = memnew( Tree );
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
tree->set_hide_root(true);
|
2016-05-16 01:25:51 +02:00
|
|
|
split_box->add_child(tree);
|
|
|
|
tree->set_custom_minimum_size(Size2(0,200));
|
|
|
|
tree->set_drag_forwarding(this);
|
2014-05-16 13:48:23 +02:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
//tree->set_v_size_flags(SIZE_EXPAND_FILL);
|
2014-05-16 13:48:23 +02:00
|
|
|
tree->connect("item_edited",this,"_favorite_toggled");
|
2014-10-15 00:44:41 +02:00
|
|
|
tree->connect("item_activated",this,"_open_pressed");
|
2015-08-24 01:15:56 +02:00
|
|
|
tree->connect("cell_selected",this,"_dir_selected");
|
|
|
|
|
|
|
|
files = memnew( ItemList );
|
|
|
|
files->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
files->set_select_mode(ItemList::SELECT_MULTI);
|
2016-05-11 16:46:08 +02:00
|
|
|
files->set_drag_forwarding(this);
|
2016-05-16 01:25:51 +02:00
|
|
|
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);
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
path_hb = memnew( HBoxContainer );
|
2016-05-16 01:25:51 +02:00
|
|
|
file_list_vb->add_child(path_hb);
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
button_back = memnew( ToolButton );
|
|
|
|
path_hb->add_child(button_back);
|
2016-05-16 01:25:51 +02:00
|
|
|
button_back->hide();
|
|
|
|
|
|
|
|
search_box = memnew( LineEdit );
|
|
|
|
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
path_hb->add_child(search_box);
|
|
|
|
search_box->connect("text_changed",this,"_search_changed");
|
|
|
|
|
2016-05-24 04:24:17 +02:00
|
|
|
search_icon = memnew( TextureFrame );
|
|
|
|
search_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED);
|
|
|
|
path_hb->add_child(search_icon);
|
2016-05-16 01:25:51 +02:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
display_mode = memnew( ToolButton );
|
|
|
|
path_hb->add_child(display_mode);
|
|
|
|
display_mode->set_toggle_mode(true);
|
|
|
|
|
2016-05-16 01:25:51 +02:00
|
|
|
file_list_vb->add_child(files);
|
2015-08-24 01:15:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
scanning_vb = memnew( VBoxContainer );
|
|
|
|
Label *slabel = memnew( Label );
|
|
|
|
slabel->set_text("Scanning Files,\nPlease Wait..");
|
|
|
|
slabel->set_align(Label::ALIGN_CENTER);
|
|
|
|
scanning_vb->add_child(slabel);
|
|
|
|
scanning_progress = memnew( ProgressBar );
|
|
|
|
scanning_vb->add_child(scanning_progress);
|
|
|
|
add_child(scanning_vb);
|
|
|
|
scanning_vb->hide();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deps_editor = memnew( DependencyEditor );
|
|
|
|
add_child(deps_editor);
|
|
|
|
|
|
|
|
owners_editor = memnew( DependencyEditorOwners);
|
|
|
|
add_child(owners_editor);
|
|
|
|
|
|
|
|
remove_dialog = memnew( DependencyRemoveDialog);
|
|
|
|
add_child(remove_dialog);
|
|
|
|
|
|
|
|
move_dialog = memnew( EditorDirDialog );
|
2016-03-09 00:00:52 +01:00
|
|
|
add_child(move_dialog);
|
2015-08-24 01:15:56 +02:00
|
|
|
move_dialog->connect("dir_selected",this,"_move_operation");
|
2016-05-04 03:25:37 +02:00
|
|
|
move_dialog->get_ok()->set_text(TTR("Move"));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
rename_dialog = memnew( EditorFileDialog );
|
|
|
|
rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
|
|
|
rename_dialog->connect("file_selected",this,"_rename_operation");
|
|
|
|
add_child(rename_dialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
updating_tree=false;
|
2015-08-24 01:15:56 +02:00
|
|
|
initialized=false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
history.push_back("res://");
|
|
|
|
history_pos=0;
|
2016-05-16 01:25:51 +02:00
|
|
|
|
|
|
|
split_mode=false;
|
2014-05-16 13:48:23 +02:00
|
|
|
|
2016-01-10 18:38:45 +01:00
|
|
|
path="res://";
|
|
|
|
|
2014-05-16 13:48:23 +02:00
|
|
|
|
2016-05-24 04:24:17 +02:00
|
|
|
add_constant_override("separation",3);
|
2014-05-16 13:48:23 +02:00
|
|
|
}
|
|
|
|
|
2015-08-24 01:15:56 +02:00
|
|
|
ScenesDock::~ScenesDock() {
|
2014-05-16 13:48:23 +02:00
|
|
|
|
|
|
|
}
|