Ejemplo n.º 1
0
static void column_widths(struct FileList *files, struct FileLayout *layout)
{
	int i;
	int numfiles = filelist_numfiles(files);

	for (i = 0; i < MAX_FILE_COLUMN; ++i) {
		layout->column_widths[i] = 0;
	}

	for (i = 0; (i < numfiles); ++i) {
		struct direntry *file = filelist_file(files, i);
		if (file) {
			float len;
			len = file_string_width(file->relname);
			if (len > layout->column_widths[COLUMN_NAME]) layout->column_widths[COLUMN_NAME] = len;
			len = file_string_width(file->date);
			if (len > layout->column_widths[COLUMN_DATE]) layout->column_widths[COLUMN_DATE] = len;
			len = file_string_width(file->time);
			if (len > layout->column_widths[COLUMN_TIME]) layout->column_widths[COLUMN_TIME] = len;
			len = file_string_width(file->size);
			if (len > layout->column_widths[COLUMN_SIZE]) layout->column_widths[COLUMN_SIZE] = len;
			len = file_string_width(file->mode1);
			if (len > layout->column_widths[COLUMN_MODE1]) layout->column_widths[COLUMN_MODE1] = len;
			len = file_string_width(file->mode2);
			if (len > layout->column_widths[COLUMN_MODE2]) layout->column_widths[COLUMN_MODE2] = len;
			len = file_string_width(file->mode3);
			if (len > layout->column_widths[COLUMN_MODE3]) layout->column_widths[COLUMN_MODE3] = len;
			len = file_string_width(file->owner);
			if (len > layout->column_widths[COLUMN_OWNER]) layout->column_widths[COLUMN_OWNER] = len;
		}
	}
}
Ejemplo n.º 2
0
/* Shorten a string to a given width w. 
 * If front is set, shorten from the front,
 * otherwise shorten from the end. */
float file_shorten_string(char *string, float w, int front)
{	
	char temp[FILE_MAX];
	short shortened = 0;
	float sw = 0;
	float pad = 0;

	if (w <= 0) {
		*string = '\0';
		return 0.0;
	}

	sw = file_string_width(string);
	if (front == 1) {
		const char *s = string;
		BLI_strncpy(temp, "...", 4);
		pad = file_string_width(temp);
		while ((*s) && (sw + pad > w)) {
			s++;
			sw = file_string_width(s);
			shortened = 1;
		}
		if (shortened) {
			int slen = strlen(s);
			BLI_strncpy(temp + 3, s, slen + 1);
			temp[slen + 4] = '\0';
			BLI_strncpy(string, temp, slen + 4);
		}
	}
	else {
		const char *s = string;
		while (sw > w) {
			int slen = strlen(string);
			string[slen - 1] = '\0';
			sw = file_string_width(s);
			shortened = 1;
		}

		if (shortened) {
			int slen = strlen(string);
			if (slen > 3) {
				BLI_strncpy(string + slen - 3, "...", 4);
			}
		}
	}
	
	return sw;
}