static link_t _create_tree(char **str) { if (**str == '#') { return NULL; } item_t item = **str - '0'; link_t root = newlink(item, NULL, NULL); (*str)++; root->left = _create_tree(str); (*str)++; root->right = _create_tree(str); return root; }
void ScenesDock::_update_tree() { tree->clear(); updating_tree=true; TreeItem *root = tree->create_item(); TreeItem *favorites = tree->create_item(root); favorites->set_icon(0, get_icon("Favorites","EditorIcons") ); favorites->set_text(0,TTR("Favorites:")); 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()); updating_tree=false; }
bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) { String search_term = tree_filter->get_search_term(); String file_filter = tree_filter->get_file_filter(); TreeItem *item = tree->create_item(p_parent); item->set_text(0,p_dir->get_name()+"/"); item->set_icon(0,get_icon("Folder","EditorIcons")); item->set_custom_bg_color(0,get_color("prop_subsection","Editor")); 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; } for (int i=0;i<p_dir->get_file_count();i++) { String file_name = p_dir->get_file(i); String extension = file_name.extension(); if (search_term!="" && file_name.findn(search_term)==-1) continue; if (file_filter!="*" && extension != file_filter ) continue; bool isfave = favorites.has(p_dir->get_file_path(i)); 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); fitem->set_text(0,file_name); 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 ); fitem->set_metadata(0,p_dir->get_file_path(i)); //if (p_dir->files[i]->icon.is_valid()) { // fitem->set_icon(0,p_dir->files[i]->icon); // } has_items=true; } if (!has_items) { memdelete(item); return false; } return true; }
bool FileSystemDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) { TreeItem *item = tree->create_item(p_parent); String dname=p_dir->get_name(); if (dname=="") dname="res://"; item->set_text(0,dname); item->set_icon(0,get_icon("Folder","EditorIcons")); 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); } for(int i=0;i<p_dir->get_subdir_count();i++) _create_tree(item,p_dir->get_subdir(i)); return true; }
void ScenesDock::_update_tree() { tree->clear(); updating_tree=true; _create_tree(NULL,EditorFileSystem::get_singleton()->get_filesystem()); updating_tree=false; }
bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) { TreeItem *item = tree->create_item(p_parent); String dname=p_dir->get_name(); if (dname=="") dname="res://"; item->set_text(0,dname); item->set_icon(0,get_icon("Folder","EditorIcons")); 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")); 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; } #if 0 for (int i=0;i<p_dir->get_file_count();i++) { String file_name = p_dir->get_file(i); String file_path = p_dir->get_file_path(i); // 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(); if (search_term!="" && search_from.findn(search_term)==-1) continue; bool isfave = favorites.has(file_path); 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); fitem->set_text(0,file_name); 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 ); fitem->set_metadata(0,file_path); //if (p_dir->files[i]->icon.is_valid()) { // fitem->set_icon(0,p_dir->files[i]->icon); // } has_items=true; } #endif /*if (!has_items) { memdelete(item); return false; }*/ return true; }
T btree_init(char *str) { T t = alloc(sizeof * t); t->root = _create_tree(&str); return t; }