Пример #1
0
EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p_path) {

	if (!filesystem || scanning)
		return NULL;

	String f = ProjectSettings::get_singleton()->localize_path(p_path);

	if (!f.begins_with("res://"))
		return NULL;

	f = f.substr(6, f.length());
	f = f.replace("\\", "/");
	if (f == String())
		return filesystem;

	if (f.ends_with("/"))
		f = f.substr(0, f.length() - 1);

	Vector<String> path = f.split("/");

	if (path.size() == 0)
		return NULL;

	EditorFileSystemDirectory *fs = filesystem;

	for (int i = 0; i < path.size(); i++) {

		int idx = -1;
		for (int j = 0; j < fs->get_subdir_count(); j++) {

			if (fs->get_subdir(j)->get_name() == path[i]) {
				idx = j;
				break;
			}
		}

		if (idx == -1) {
			return NULL;
		} else {

			fs = fs->get_subdir(idx);
		}
	}

	return fs;
}
Пример #2
0
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();

	current_path->set_text(path);


	EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
	if (!efd)
		return;

	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();
	bool use_folders = !search_box->is_visible() && split_mode;

	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);
			Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
		}

		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);
			Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
		}

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

	}

	if (use_folders) {

		if (path!="res://") {

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

		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,path.plus_file(dname)+"/");

			if (cselection.has(dname))
				files->select(files->get_item_count()-1,false);
		}
	}


	List<FileInfo> filelist;

	if (search_box->is_visible()) {

		if (search_box->get_text().length()>1) {
			_search(EditorFileSystem::get_singleton()->get_filesystem(),&filelist,128);
		}

		filelist.sort();
	} else {

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

	StringName ei="EditorIcons"; //make it faster..
	StringName oi="Object";


	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;

		Ref<Texture> type_icon;

		if (has_icon(type,ei)) {
			type_icon=get_icon(type,ei);
		} else {
			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);
			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);

		}

		if (cselection.has(fname))
			files->select(files->get_item_count()-1,false);

	}


}
Пример #3
0
void FileSystemDock::_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();

	current_path->set_text(path);


	EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
	if (!efd)
		return;

	int thumbnail_size = EditorSettings::get_singleton()->get("filesystem_dock/thumbnail_size");
	thumbnail_size*=EDSCALE;
	Ref<Texture> folder_thumbnail;
	Ref<Texture> file_thumbnail;

	bool use_thumbnails = (display_mode == DISPLAY_THUMBNAILS);
	bool use_folders = search_box->get_text().length()==0 && split_mode;

	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_fixed_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);
			Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
		}

		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);
			Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
		}

		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_fixed_icon_size(Size2());

	}

	if (use_folders) {

		if (path!="res://") {

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

		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,path.plus_file(dname)+"/");

			if (cselection.has(dname))
				files->select(files->get_item_count()-1,false);
		}
	}


	List<FileInfo> filelist;

	if (search_box->get_text().length()) {

		if (search_box->get_text().length()>1) {
			_search(EditorFileSystem::get_singleton()->get_filesystem(),&filelist,128);
		}

		filelist.sort();
	} else {

		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);
			if (efd->get_file_meta(i)) {
				if (efd->is_missing_sources(i)) {
					fi.import_status=3;
				} else if (efd->have_sources_changed(i)) {
					fi.import_status=2;
				} else {
					fi.import_status=1;
				}

				for(int j=0;j<efd->get_source_count(i);j++) {
					String s = EditorImportPlugin::expand_source_path(efd->get_source_file(i,j));
					if (efd->is_source_file_missing(i,j)) {
						s+=" (Missing)";
					}
					fi.sources.push_back(s);
				}
			} else {
				fi.import_status=0;
			}



			filelist.push_back(fi);
		}
	}

	StringName ei="EditorIcons"; //make it faster..
	StringName oi="Object";


	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;

		Ref<Texture> type_icon;

		String tooltip=fname;

		if (E->get().import_status==0) {

			if (has_icon(type,ei)) {
				type_icon=get_icon(type,ei);
			} else {
				type_icon=get_icon(oi,ei);
			}
		} else if (E->get().import_status==1) {
			type_icon=get_icon("DependencyOk","EditorIcons");
		} else if (E->get().import_status==2) {
			type_icon=get_icon("DependencyChanged","EditorIcons");
			tooltip+"\nStatus: Needs Re-Import";
		} else if (E->get().import_status==3) {
			type_icon=get_icon("ImportFail","EditorIcons");
			tooltip+"\nStatus: Missing Dependencies";
		}

		if (E->get().sources.size()) {
			for(int i=0;i<E->get().sources.size();i++) {
				tooltip+="\nSource: "+E->get().sources[i];
			}
		}



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

		}

		if (cselection.has(fname))
			files->select(files->get_item_count()-1,false);

		files->set_item_tooltip(files->get_item_count()-1,tooltip);


	}


}
Пример #4
0
bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirectory **r_d, int &r_file_pos) const {
	//todo make faster

	if (!filesystem || scanning)
		return false;

	String f = ProjectSettings::get_singleton()->localize_path(p_file);

	if (!f.begins_with("res://"))
		return false;
	f = f.substr(6, f.length());
	f = f.replace("\\", "/");

	Vector<String> path = f.split("/");

	if (path.size() == 0)
		return false;
	String file = path[path.size() - 1];
	path.resize(path.size() - 1);

	EditorFileSystemDirectory *fs = filesystem;

	for (int i = 0; i < path.size(); i++) {

		if (path[i].begins_with("."))
			return false;

		int idx = -1;
		for (int j = 0; j < fs->get_subdir_count(); j++) {

			if (fs->get_subdir(j)->get_name() == path[i]) {
				idx = j;
				break;
			}
		}

		if (idx == -1) {
			//does not exist, create i guess?
			EditorFileSystemDirectory *efsd = memnew(EditorFileSystemDirectory);

			efsd->name = path[i];
			efsd->parent = fs;

			int idx2 = 0;
			for (int j = 0; j < fs->get_subdir_count(); j++) {

				if (efsd->name < fs->get_subdir(j)->get_name())
					break;
				idx2++;
			}

			if (idx2 == fs->get_subdir_count())
				fs->subdirs.push_back(efsd);
			else
				fs->subdirs.insert(idx2, efsd);
			fs = efsd;
		} else {

			fs = fs->get_subdir(idx);
		}
	}

	int cpos = -1;
	for (int i = 0; i < fs->files.size(); i++) {

		if (fs->files[i]->file == file) {
			cpos = i;
			break;
		}
	}

	r_file_pos = cpos;
	*r_d = fs;

	if (cpos != -1) {

		return true;
	} else {

		return false;
	}
}
Пример #5
0
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();

	EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path);
	if (!efd)
		return;

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

	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);
			Theme::get_default()->set_icon("ResizedFolder","EditorIcons",resized_folder);
		}

		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);
			Theme::get_default()->set_icon("ResizedFile","EditorIcons",resized_file);
		}

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

	}


	if (path!="res://") {

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

	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,path.plus_file(dname)+"/");

		if (cselection.has(dname))
			files->select(files->get_item_count()-1,false);
	}

	for(int i=0;i<efd->get_file_count();i++) {

		String fname=efd->get_file(i);
		String fp = path.plus_file(fname);


		String type = efd->get_file_type(i);
		Ref<Texture> type_icon;

		if (has_icon(type,"EditorIcons")) {
			type_icon=get_icon(type,"EditorIcons");
		} else {
			type_icon=get_icon("Object","EditorIcons");
		}

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

	}


}