Example #1
0
/*
 * Ordering function for sorting lists of files/directories. Returns -1 if
 * entry1 belongs before entry2, 0 if they are equal, 1 if they should be swapped.
 */
static int bli_compare(struct direntry *entry1, struct direntry *entry2)
{
	/* type is equal to stat.st_mode */

	/* directories come before non-directories */
	if (S_ISDIR(entry1->type)) {
		if (S_ISDIR(entry2->type) == 0) return (-1);
	}
	else {
		if (S_ISDIR(entry2->type)) return (1);
	}
	/* non-regular files come after regular files */
	if (S_ISREG(entry1->type)) {
		if (S_ISREG(entry2->type) == 0) return (-1);
	}
	else {
		if (S_ISREG(entry2->type)) return (1);
	}
	/* arbitrary, but consistent, ordering of different types of non-regular files */
	if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
	if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);

	/* OK, now we know their S_IFMT fields are the same, go on to a name comparison */
	/* make sure "." and ".." are always first */
	if (FILENAME_IS_CURRENT(entry1->relname)) return (-1);
	if (FILENAME_IS_CURRENT(entry2->relname)) return (1);
	if (FILENAME_IS_PARENT(entry1->relname)) return (-1);
	if (FILENAME_IS_PARENT(entry2->relname)) return (1);

	return (BLI_natstrcmp(entry1->relname, entry2->relname));
}
Example #2
0
static int compare_direntry_generic(const struct direntry *entry1, const struct direntry *entry2)
{
	/* type is equal to stat.st_mode */

	if (compare_is_directory(entry1)) {
		if (compare_is_directory(entry2) == 0) {
			return -1;
		}
	}
	else if (compare_is_directory(entry2)) {
		return 1;
	}

	if (S_ISREG(entry1->type)) {
		if (!S_ISREG(entry2->type)) {
			return -1;
		}
	}
	else if (S_ISREG(entry2->type)) {
		return 1;
	}
	if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return -1;
	if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return 1;
	
	/* make sure "." and ".." are always first */
	if (FILENAME_IS_CURRENT(entry1->relname)) return -1;
	if (FILENAME_IS_CURRENT(entry2->relname)) return 1;
	if (FILENAME_IS_PARENT(entry1->relname)) return -1;
	if (FILENAME_IS_PARENT(entry2->relname)) return 1;
	
	return 0;
}
Example #3
0
/**
 * Sets FileSelectParams->file (name of selected file)
 */
void fileselect_file_set(SpaceFile *sfile, const int index)
{
	const struct direntry *file = filelist_file(sfile->files, index);
	if (file && file->relname[0] && !FILENAME_IS_PARENT(file->relname)) {
		BLI_strncpy(sfile->params->file, file->relname, FILE_MAXFILE);
	}
}
Example #4
0
ImBuf *filelist_geticon(struct FileList *filelist, const int index)
{
	ImBuf *ibuf = NULL;
	struct direntry *file = NULL;
	int fidx = 0;

	BLI_assert(G.background == false);

	if ((index < 0) || (index >= filelist->numfiltered)) {
		return NULL;
	}
	fidx = filelist->fidx[index];
	file = &filelist->filelist[fidx];
	if (file->type & S_IFDIR) {
		if (FILENAME_IS_PARENT(filelist->filelist[fidx].relname)) {
			ibuf = gSpecialFileImages[SPECIAL_IMG_PARENT];
		}
		else if (FILENAME_IS_CURRENT(filelist->filelist[fidx].relname)) {
			ibuf = gSpecialFileImages[SPECIAL_IMG_REFRESH];
		}
		else {
			ibuf = gSpecialFileImages[SPECIAL_IMG_FOLDER];
		}
	}
	else {
		ibuf = gSpecialFileImages[SPECIAL_IMG_UNKNOWNFILE];
	}

	if (file->flags & FILE_TYPE_BLENDER) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_BLENDFILE];
	}
	else if (file->flags & FILE_TYPE_MOVIE) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_MOVIEFILE];
	}
	else if (file->flags & FILE_TYPE_SOUND) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_SOUNDFILE];
	}
	else if (file->flags & FILE_TYPE_PYSCRIPT) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_PYTHONFILE];
	}
	else if (file->flags & FILE_TYPE_FTFONT) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_FONTFILE];
	}
	else if (file->flags & FILE_TYPE_TEXT) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_TEXTFILE];
	}
	else if (file->flags & FILE_TYPE_IMAGE) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_LOADING];
	}
	else if (file->flags & FILE_TYPE_BLENDER_BACKUP) {
		ibuf = gSpecialFileImages[SPECIAL_IMG_BACKUP];
	}

	return ibuf;
}
Example #5
0
static int get_file_icon(struct direntry *file)
{
	if (file->type & S_IFDIR) {
		if (FILENAME_IS_PARENT(file->relname)) {
			return ICON_FILE_PARENT;
		}
		if (file->flags & FILE_TYPE_APPLICATIONBUNDLE) {
			return ICON_UGLYPACKAGE;
		}
		if (file->flags & FILE_TYPE_BLENDER) {
			return ICON_FILE_BLEND;
		}
		return ICON_FILE_FOLDER;
	}
	else if (file->flags & FILE_TYPE_BLENDER)
		return ICON_FILE_BLEND;
	else if (file->flags & FILE_TYPE_BLENDER_BACKUP)
		return ICON_FILE_BACKUP;
	else if (file->flags & FILE_TYPE_IMAGE)
		return ICON_FILE_IMAGE;
	else if (file->flags & FILE_TYPE_MOVIE)
		return ICON_FILE_MOVIE;
	else if (file->flags & FILE_TYPE_PYSCRIPT)
		return ICON_FILE_SCRIPT;
	else if (file->flags & FILE_TYPE_SOUND)
		return ICON_FILE_SOUND;
	else if (file->flags & FILE_TYPE_FTFONT)
		return ICON_FILE_FONT;
	else if (file->flags & FILE_TYPE_BTX)
		return ICON_FILE_BLANK;
	else if (file->flags & FILE_TYPE_COLLADA)
		return ICON_FILE_BLANK;
	else if (file->flags & FILE_TYPE_TEXT)
		return ICON_FILE_TEXT;
	else
		return ICON_FILE_BLANK;
}