Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_file/filesel.c
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_fnmatch.h" | #include "BLI_fnmatch.h" | ||||
| #include "BLT_translation.h" | |||||
| #include "BKE_appdir.h" | #include "BKE_appdir.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "ED_fileselect.h" | #include "ED_fileselect.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_interface_icons.h" | #include "UI_interface_icons.h" | ||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "file_intern.h" | #include "file_intern.h" | ||||
| #include "filelist.h" | #include "filelist.h" | ||||
| #define VERTLIST_MAJORCOLUMN_WIDTH (25 * UI_UNIT_X) | |||||
| FileSelectParams *ED_fileselect_get_params(struct SpaceFile *sfile) | FileSelectParams *ED_fileselect_get_params(struct SpaceFile *sfile) | ||||
| { | { | ||||
| if (!sfile->params) { | if (!sfile->params) { | ||||
| ED_fileselect_set_params(sfile); | ED_fileselect_set_params(sfile); | ||||
| } | } | ||||
| return sfile->params; | return sfile->params; | ||||
| } | } | ||||
| Show All 14 Lines | if (!sfile->params) { | ||||
| BLI_split_dirfile(blendfile_path, | BLI_split_dirfile(blendfile_path, | ||||
| sfile->params->dir, | sfile->params->dir, | ||||
| sfile->params->file, | sfile->params->file, | ||||
| sizeof(sfile->params->dir), | sizeof(sfile->params->dir), | ||||
| sizeof(sfile->params->file)); | sizeof(sfile->params->file)); | ||||
| sfile->params->filter_glob[0] = '\0'; | sfile->params->filter_glob[0] = '\0'; | ||||
| /* set the default thumbnails size */ | /* set the default thumbnails size */ | ||||
| sfile->params->thumbnail_size = 128; | sfile->params->thumbnail_size = 128; | ||||
| /* Show size column by default. */ | |||||
| sfile->params->details_flags = FILE_DETAILS_SIZE | FILE_DETAILS_DATETIME; | |||||
| } | } | ||||
| params = sfile->params; | params = sfile->params; | ||||
| /* set the parameters from the operator, if it exists */ | /* set the parameters from the operator, if it exists */ | ||||
| if (op) { | if (op) { | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| const bool is_files = (RNA_struct_find_property(op->ptr, "files") != NULL); | const bool is_files = (RNA_struct_find_property(op->ptr, "files") != NULL); | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (op) { | ||||
| if (is_directory == true && is_filename == false && is_filepath == false && | if (is_directory == true && is_filename == false && is_filepath == false && | ||||
| is_files == false) { | is_files == false) { | ||||
| params->flag |= FILE_DIRSEL_ONLY; | params->flag |= FILE_DIRSEL_ONLY; | ||||
| } | } | ||||
| else { | else { | ||||
| params->flag &= ~FILE_DIRSEL_ONLY; | params->flag &= ~FILE_DIRSEL_ONLY; | ||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "hide_props_region"))) { | |||||
| params->flag |= RNA_property_boolean_get(op->ptr, prop) ? FILE_HIDE_TOOL_PROPS : 0; | |||||
| } | |||||
| params->filter = 0; | params->filter = 0; | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "filter_blender"))) { | if ((prop = RNA_struct_find_property(op->ptr, "filter_blender"))) { | ||||
| params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER : 0; | params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER : 0; | ||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "filter_blenlib"))) { | if ((prop = RNA_struct_find_property(op->ptr, "filter_blenlib"))) { | ||||
| params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDERLIB : 0; | params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDERLIB : 0; | ||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "filter_backup"))) { | if ((prop = RNA_struct_find_property(op->ptr, "filter_backup"))) { | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (op) { | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "sort_method"))) { | if ((prop = RNA_struct_find_property(op->ptr, "sort_method"))) { | ||||
| params->sort = RNA_property_enum_get(op->ptr, prop); | params->sort = RNA_property_enum_get(op->ptr, prop); | ||||
| } | } | ||||
| else { | else { | ||||
| params->sort = FILE_SORT_ALPHA; | params->sort = FILE_SORT_ALPHA; | ||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "action_type"))) { | |||||
| params->action_type = RNA_property_enum_get(op->ptr, prop); | |||||
| } | |||||
| if (params->display == FILE_DEFAULTDISPLAY) { | if (params->display == FILE_DEFAULTDISPLAY) { | ||||
| if (params->display_previous == FILE_DEFAULTDISPLAY) { | if (params->display_previous == FILE_DEFAULTDISPLAY) { | ||||
| if (U.uiflag & USER_SHOW_THUMBNAILS) { | if (U.uiflag & USER_SHOW_THUMBNAILS) { | ||||
| if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE | FILE_TYPE_FTFONT)) { | if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE | FILE_TYPE_FTFONT)) { | ||||
| params->display = FILE_IMGDISPLAY; | params->display = FILE_IMGDISPLAY; | ||||
| } | } | ||||
| else { | else { | ||||
| params->display = FILE_SHORTDISPLAY; | params->display = FILE_VERTICALDISPLAY; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| params->display = FILE_SHORTDISPLAY; | params->display = FILE_VERTICALDISPLAY; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| params->display = params->display_previous; | params->display = params->display_previous; | ||||
| } | } | ||||
| } | } | ||||
| if (is_relative_path) { | if (is_relative_path) { | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) { | if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) { | ||||
| if (!RNA_property_is_set_ex(op->ptr, prop, false)) { | if (!RNA_property_is_set_ex(op->ptr, prop, false)) { | ||||
| RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_RELPATHS) != 0); | RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_RELPATHS) != 0); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* default values, if no operator */ | /* default values, if no operator */ | ||||
| params->type = FILE_UNIX; | params->type = FILE_UNIX; | ||||
| params->flag |= FILE_HIDE_DOT; | params->flag |= FILE_HIDE_DOT; | ||||
| params->flag &= ~FILE_DIRSEL_ONLY; | params->flag &= ~FILE_DIRSEL_ONLY; | ||||
| params->display = FILE_SHORTDISPLAY; | params->display = FILE_VERTICALDISPLAY; | ||||
| params->display_previous = FILE_DEFAULTDISPLAY; | params->display_previous = FILE_DEFAULTDISPLAY; | ||||
| params->sort = FILE_SORT_ALPHA; | params->sort = FILE_SORT_ALPHA; | ||||
| params->filter = 0; | params->filter = 0; | ||||
| params->filter_glob[0] = '\0'; | params->filter_glob[0] = '\0'; | ||||
| } | } | ||||
| /* operator has no setting for this */ | /* operator has no setting for this */ | ||||
| params->active_file = -1; | params->active_file = -1; | ||||
| Show All 34 Lines | |||||
| } | } | ||||
| /** | /** | ||||
| * Sets FileSelectParams->file (name of selected file) | * Sets FileSelectParams->file (name of selected file) | ||||
| */ | */ | ||||
| void fileselect_file_set(SpaceFile *sfile, const int index) | void fileselect_file_set(SpaceFile *sfile, const int index) | ||||
| { | { | ||||
| const struct FileDirEntry *file = filelist_file(sfile->files, index); | const struct FileDirEntry *file = filelist_file(sfile->files, index); | ||||
| if (file && file->relpath && file->relpath[0] && !(file->typeflag & FILE_TYPE_FOLDER)) { | if (file && file->relpath && file->relpath[0] && !(file->typeflag & FILE_TYPE_DIR)) { | ||||
| BLI_strncpy(sfile->params->file, file->relpath, FILE_MAXFILE); | BLI_strncpy(sfile->params->file, file->relpath, FILE_MAXFILE); | ||||
| } | } | ||||
| } | } | ||||
| int ED_fileselect_layout_numfiles(FileLayout *layout, ARegion *ar) | int ED_fileselect_layout_numfiles(FileLayout *layout, ARegion *ar) | ||||
| { | { | ||||
| int numfiles; | int numfiles; | ||||
| Show All 11 Lines | if (layout->flag & FILE_LAYOUT_HOR) { | ||||
| const int x_item = layout->tile_w + (2 * layout->tile_border_x); | const int x_item = layout->tile_w + (2 * layout->tile_border_x); | ||||
| const int x_view = (int)(BLI_rctf_size_x(&ar->v2d.cur)); | const int x_view = (int)(BLI_rctf_size_x(&ar->v2d.cur)); | ||||
| const int x_over = x_item - (x_view % x_item); | const int x_over = x_item - (x_view % x_item); | ||||
| numfiles = (int)((float)(x_view + x_over) / (float)(x_item)); | numfiles = (int)((float)(x_view + x_over) / (float)(x_item)); | ||||
| return numfiles * layout->rows; | return numfiles * layout->rows; | ||||
| } | } | ||||
| else { | else { | ||||
| const int y_item = layout->tile_h + (2 * layout->tile_border_y); | const int y_item = layout->tile_h + (2 * layout->tile_border_y); | ||||
| const int y_view = (int)(BLI_rctf_size_y(&ar->v2d.cur)); | const int y_view = (int)(BLI_rctf_size_y(&ar->v2d.cur)) - layout->offset_top; | ||||
| const int y_over = y_item - (y_view % y_item); | const int y_over = y_item - (y_view % y_item); | ||||
| numfiles = (int)((float)(y_view + y_over) / (float)(y_item)); | numfiles = (int)((float)(y_view + y_over) / (float)(y_item)); | ||||
| return numfiles * layout->columns; | return numfiles * layout->flow_columns; | ||||
| } | } | ||||
| } | } | ||||
| static bool is_inside(int x, int y, int cols, int rows) | static bool is_inside(int x, int y, int cols, int rows) | ||||
| { | { | ||||
| return ((x >= 0) && (x < cols) && (y >= 0) && (y < rows)); | return ((x >= 0) && (x < cols) && (y >= 0) && (y < rows)); | ||||
| } | } | ||||
| FileSelection ED_fileselect_layout_offset_rect(FileLayout *layout, const rcti *rect) | FileSelection ED_fileselect_layout_offset_rect(FileLayout *layout, const rcti *rect) | ||||
| { | { | ||||
| int colmin, colmax, rowmin, rowmax; | int colmin, colmax, rowmin, rowmax; | ||||
| FileSelection sel; | FileSelection sel; | ||||
| sel.first = sel.last = -1; | sel.first = sel.last = -1; | ||||
| if (layout == NULL) { | if (layout == NULL) { | ||||
| return sel; | return sel; | ||||
| } | } | ||||
| colmin = (rect->xmin) / (layout->tile_w + 2 * layout->tile_border_x); | colmin = (rect->xmin) / (layout->tile_w + 2 * layout->tile_border_x); | ||||
| rowmin = (rect->ymin) / (layout->tile_h + 2 * layout->tile_border_y); | rowmin = (rect->ymin - layout->offset_top) / (layout->tile_h + 2 * layout->tile_border_y); | ||||
| colmax = (rect->xmax) / (layout->tile_w + 2 * layout->tile_border_x); | colmax = (rect->xmax) / (layout->tile_w + 2 * layout->tile_border_x); | ||||
| rowmax = (rect->ymax) / (layout->tile_h + 2 * layout->tile_border_y); | rowmax = (rect->ymax - layout->offset_top) / (layout->tile_h + 2 * layout->tile_border_y); | ||||
| if (is_inside(colmin, rowmin, layout->columns, layout->rows) || | if (is_inside(colmin, rowmin, layout->flow_columns, layout->rows) || | ||||
| is_inside(colmax, rowmax, layout->columns, layout->rows)) { | is_inside(colmax, rowmax, layout->flow_columns, layout->rows)) { | ||||
| CLAMP(colmin, 0, layout->columns - 1); | CLAMP(colmin, 0, layout->flow_columns - 1); | ||||
| CLAMP(rowmin, 0, layout->rows - 1); | CLAMP(rowmin, 0, layout->rows - 1); | ||||
| CLAMP(colmax, 0, layout->columns - 1); | CLAMP(colmax, 0, layout->flow_columns - 1); | ||||
| CLAMP(rowmax, 0, layout->rows - 1); | CLAMP(rowmax, 0, layout->rows - 1); | ||||
| } | } | ||||
| if ((colmin > layout->columns - 1) || (rowmin > layout->rows - 1)) { | if ((colmin > layout->flow_columns - 1) || (rowmin > layout->rows - 1)) { | ||||
| sel.first = -1; | sel.first = -1; | ||||
| } | } | ||||
| else { | else { | ||||
| if (layout->flag & FILE_LAYOUT_HOR) { | if (layout->flag & FILE_LAYOUT_HOR) { | ||||
| sel.first = layout->rows * colmin + rowmin; | sel.first = layout->rows * colmin + rowmin; | ||||
| } | } | ||||
| else { | else { | ||||
| sel.first = colmin + layout->columns * rowmin; | sel.first = colmin + layout->flow_columns * rowmin; | ||||
| } | } | ||||
| } | } | ||||
| if ((colmax > layout->columns - 1) || (rowmax > layout->rows - 1)) { | if ((colmax > layout->flow_columns - 1) || (rowmax > layout->rows - 1)) { | ||||
| sel.last = -1; | sel.last = -1; | ||||
| } | } | ||||
| else { | else { | ||||
| if (layout->flag & FILE_LAYOUT_HOR) { | if (layout->flag & FILE_LAYOUT_HOR) { | ||||
| sel.last = layout->rows * colmax + rowmax; | sel.last = layout->rows * colmax + rowmax; | ||||
| } | } | ||||
| else { | else { | ||||
| sel.last = colmax + layout->columns * rowmax; | sel.last = colmax + layout->flow_columns * rowmax; | ||||
| } | } | ||||
| } | } | ||||
| return sel; | return sel; | ||||
| } | } | ||||
| int ED_fileselect_layout_offset(FileLayout *layout, int x, int y) | int ED_fileselect_layout_offset(FileLayout *layout, int x, int y) | ||||
| { | { | ||||
| int offsetx, offsety; | int offsetx, offsety; | ||||
| int active_file; | int active_file; | ||||
| if (layout == NULL) { | if (layout == NULL) { | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| offsetx = (x) / (layout->tile_w + 2 * layout->tile_border_x); | offsetx = (x) / (layout->tile_w + 2 * layout->tile_border_x); | ||||
| offsety = (y) / (layout->tile_h + 2 * layout->tile_border_y); | offsety = (y - layout->offset_top) / (layout->tile_h + 2 * layout->tile_border_y); | ||||
| if (offsetx > layout->columns - 1) { | if (offsetx > layout->flow_columns - 1) { | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| if (offsety > layout->rows - 1) { | if (offsety > layout->rows - 1) { | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| if (layout->flag & FILE_LAYOUT_HOR) { | if (layout->flag & FILE_LAYOUT_HOR) { | ||||
| active_file = layout->rows * offsetx + offsety; | active_file = layout->rows * offsetx + offsety; | ||||
| } | } | ||||
| else { | else { | ||||
| active_file = offsetx + layout->columns * offsety; | active_file = offsetx + layout->flow_columns * offsety; | ||||
| } | } | ||||
| return active_file; | return active_file; | ||||
| } | } | ||||
| /** | |||||
| * Get the currently visible bounds of the layout in screen space. Matches View2D.mask minus the | |||||
| * top column-header row. | |||||
| */ | |||||
| void ED_fileselect_layout_maskrect(const FileLayout *layout, const View2D *v2d, rcti *r_rect) | |||||
| { | |||||
| *r_rect = v2d->mask; | |||||
| r_rect->ymax -= layout->offset_top; | |||||
| } | |||||
| bool ED_fileselect_layout_is_inside_pt(const FileLayout *layout, const View2D *v2d, int x, int y) | |||||
| { | |||||
| rcti maskrect; | |||||
| ED_fileselect_layout_maskrect(layout, v2d, &maskrect); | |||||
| return BLI_rcti_isect_pt(&maskrect, x, y); | |||||
| } | |||||
| bool ED_fileselect_layout_isect_rect(const FileLayout *layout, | |||||
| const View2D *v2d, | |||||
| const rcti *rect, | |||||
| rcti *r_dst) | |||||
| { | |||||
| rcti maskrect; | |||||
| ED_fileselect_layout_maskrect(layout, v2d, &maskrect); | |||||
| return BLI_rcti_isect(&maskrect, rect, r_dst); | |||||
| } | |||||
| void ED_fileselect_layout_tilepos(FileLayout *layout, int tile, int *x, int *y) | void ED_fileselect_layout_tilepos(FileLayout *layout, int tile, int *x, int *y) | ||||
| { | { | ||||
| if (layout->flag == FILE_LAYOUT_HOR) { | if (layout->flag == FILE_LAYOUT_HOR) { | ||||
| *x = layout->tile_border_x + | *x = layout->tile_border_x + | ||||
| (tile / layout->rows) * (layout->tile_w + 2 * layout->tile_border_x); | (tile / layout->rows) * (layout->tile_w + 2 * layout->tile_border_x); | ||||
| *y = layout->tile_border_y + | *y = layout->offset_top + layout->tile_border_y + | ||||
| (tile % layout->rows) * (layout->tile_h + 2 * layout->tile_border_y); | (tile % layout->rows) * (layout->tile_h + 2 * layout->tile_border_y); | ||||
| } | } | ||||
| else { | else { | ||||
| *x = layout->tile_border_x + | *x = layout->tile_border_x + | ||||
| ((tile) % layout->columns) * (layout->tile_w + 2 * layout->tile_border_x); | ((tile) % layout->flow_columns) * (layout->tile_w + 2 * layout->tile_border_x); | ||||
| *y = layout->tile_border_y + | *y = layout->offset_top + layout->tile_border_y + | ||||
| ((tile) / layout->columns) * (layout->tile_h + 2 * layout->tile_border_y); | ((tile) / layout->flow_columns) * (layout->tile_h + 2 * layout->tile_border_y); | ||||
| } | |||||
| } | |||||
| /** | |||||
| * Check if the region coordinate defined by \a x and \a y are inside the column header. | |||||
| */ | |||||
| bool file_attribute_column_header_is_inside(const View2D *v2d, | |||||
| const FileLayout *layout, | |||||
| int x, | |||||
| int y) | |||||
| { | |||||
| rcti header_rect = v2d->mask; | |||||
| header_rect.ymin = header_rect.ymax - layout->attribute_column_header_h; | |||||
| return BLI_rcti_isect_pt(&header_rect, x, y); | |||||
| } | |||||
| bool file_attribute_column_type_enabled(const FileSelectParams *params, | |||||
| FileAttributeColumnType column) | |||||
| { | |||||
| switch (column) { | |||||
| case COLUMN_NAME: | |||||
| /* Always enabled */ | |||||
| return true; | |||||
| case COLUMN_DATETIME: | |||||
| return (params->details_flags & FILE_DETAILS_DATETIME) != 0; | |||||
| case COLUMN_SIZE: | |||||
| return (params->details_flags & FILE_DETAILS_SIZE) != 0; | |||||
| default: | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Find the column type at region coordinate given by \a x (y doesn't matter for this). | |||||
| */ | |||||
| FileAttributeColumnType file_attribute_column_type_find_isect(const View2D *v2d, | |||||
| const FileSelectParams *params, | |||||
| FileLayout *layout, | |||||
| int x) | |||||
| { | |||||
| float mx, my; | |||||
| int offset_tile; | |||||
| UI_view2d_region_to_view(v2d, x, v2d->mask.ymax - layout->offset_top - 1, &mx, &my); | |||||
| offset_tile = ED_fileselect_layout_offset( | |||||
| layout, (int)(v2d->tot.xmin + mx), (int)(v2d->tot.ymax - my)); | |||||
| if (offset_tile > -1) { | |||||
| int tile_x, tile_y; | |||||
| int pos_x = 0; | |||||
| int rel_x; /* x relative to the hovered tile */ | |||||
| ED_fileselect_layout_tilepos(layout, offset_tile, &tile_x, &tile_y); | |||||
| /* Column header drawing doesn't use left tile border, so subtract it. */ | |||||
| rel_x = mx - (tile_x - layout->tile_border_x); | |||||
| for (FileAttributeColumnType column = 0; column < ATTRIBUTE_COLUMN_MAX; column++) { | |||||
| if (!file_attribute_column_type_enabled(params, column)) { | |||||
| continue; | |||||
| } | |||||
| const int width = layout->attribute_columns[column].width; | |||||
| if (IN_RANGE(rel_x, pos_x, pos_x + width)) { | |||||
| return column; | |||||
| } | |||||
| pos_x += width; | |||||
| } | } | ||||
| } | } | ||||
| return COLUMN_NONE; | |||||
| } | |||||
| float file_string_width(const char *str) | float file_string_width(const char *str) | ||||
| { | { | ||||
| uiStyle *style = UI_style_get(); | uiStyle *style = UI_style_get(); | ||||
| float width; | float width; | ||||
| UI_fontstyle_set(&style->widget); | UI_fontstyle_set(&style->widget); | ||||
| if (style->widget.kerning == 1) { /* for BLF_width */ | if (style->widget.kerning == 1) { /* for BLF_width */ | ||||
| BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT); | BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT); | ||||
| Show All 19 Lines | #if 0 | ||||
| return style->widget.points; | return style->widget.points; | ||||
| #else | #else | ||||
| uiStyle *style = UI_style_get(); | uiStyle *style = UI_style_get(); | ||||
| UI_fontstyle_set(&style->widget); | UI_fontstyle_set(&style->widget); | ||||
| return style->widget.points * UI_DPI_FAC; | return style->widget.points * UI_DPI_FAC; | ||||
| #endif | #endif | ||||
| } | } | ||||
| static void column_widths(FileSelectParams *params, struct FileLayout *layout) | static void file_attribute_columns_widths(const FileSelectParams *params, FileLayout *layout) | ||||
| { | { | ||||
| int i; | FileAttributeColumn *columns = layout->attribute_columns; | ||||
| const bool small_size = SMALL_SIZE_CHECK(params->thumbnail_size); | const bool small_size = SMALL_SIZE_CHECK(params->thumbnail_size); | ||||
| const int pad = small_size ? 0 : ATTRIBUTE_COLUMN_PADDING * 2; | |||||
| for (i = 0; i < MAX_FILE_COLUMN; ++i) { | for (int i = 0; i < ATTRIBUTE_COLUMN_MAX; ++i) { | ||||
| layout->column_widths[i] = 0; | layout->attribute_columns[i].width = 0; | ||||
| } | } | ||||
| layout->column_widths[COLUMN_NAME] = ((float)params->thumbnail_size / 8.0f) * UI_UNIT_X; | |||||
| /* Biggest possible reasonable values... */ | /* Biggest possible reasonable values... */ | ||||
| layout->column_widths[COLUMN_DATE] = file_string_width(small_size ? "23/08/89" : "23-Dec-89"); | columns[COLUMN_DATETIME].width = file_string_width(small_size ? "23/08/89" : | ||||
| layout->column_widths[COLUMN_TIME] = file_string_width("23:59"); | "23 Dec 6789, 23:59") + | ||||
| layout->column_widths[COLUMN_SIZE] = file_string_width(small_size ? "98.7 M" : "98.7 MiB"); | pad; | ||||
| columns[COLUMN_SIZE].width = file_string_width(small_size ? "98.7 M" : "098.7 MB") + pad; | |||||
| if (params->display == FILE_IMGDISPLAY) { | |||||
| columns[COLUMN_NAME].width = ((float)params->thumbnail_size / 8.0f) * UI_UNIT_X; | |||||
| } | |||||
| /* Name column uses remaining width */ | |||||
| else { | |||||
| int remwidth = layout->tile_w; | |||||
| for (FileAttributeColumnType column_type = ATTRIBUTE_COLUMN_MAX - 1; column_type >= 0; | |||||
| column_type--) { | |||||
| if ((column_type == COLUMN_NAME) || | |||||
| !file_attribute_column_type_enabled(params, column_type)) { | |||||
| continue; | |||||
| } | |||||
| remwidth -= columns[column_type].width; | |||||
| } | |||||
| columns[COLUMN_NAME].width = remwidth; | |||||
| } | |||||
| } | |||||
| static void file_attribute_columns_init(const FileSelectParams *params, FileLayout *layout) | |||||
| { | |||||
| file_attribute_columns_widths(params, layout); | |||||
| layout->attribute_columns[COLUMN_NAME].name = N_("Name"); | |||||
| layout->attribute_columns[COLUMN_NAME].sort_type = FILE_SORT_ALPHA; | |||||
| layout->attribute_columns[COLUMN_NAME].text_align = UI_STYLE_TEXT_LEFT; | |||||
| layout->attribute_columns[COLUMN_DATETIME].name = N_("Date Modified"); | |||||
| layout->attribute_columns[COLUMN_DATETIME].sort_type = FILE_SORT_TIME; | |||||
mont29: Strings should be tagged for translation | |||||
Done Inline ActionsI don’t think using IFACE_() is valid here, thinkyou only want to tag the strings for message extraction (N_()), and do the translation when you are actually displaying them. Otherwise if user changes its language after this is called, it won't be updated. mont29: I don’t think using `IFACE_()` is valid here, thinkyou only want to tag the strings for… | |||||
| layout->attribute_columns[COLUMN_DATETIME].text_align = UI_STYLE_TEXT_LEFT; | |||||
| layout->attribute_columns[COLUMN_SIZE].name = N_("Size"); | |||||
| layout->attribute_columns[COLUMN_SIZE].sort_type = FILE_SORT_SIZE; | |||||
| layout->attribute_columns[COLUMN_SIZE].text_align = UI_STYLE_TEXT_RIGHT; | |||||
| } | } | ||||
| void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar) | void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar) | ||||
| { | { | ||||
| FileSelectParams *params = ED_fileselect_get_params(sfile); | FileSelectParams *params = ED_fileselect_get_params(sfile); | ||||
| FileLayout *layout = NULL; | FileLayout *layout = NULL; | ||||
| View2D *v2d = &ar->v2d; | View2D *v2d = &ar->v2d; | ||||
| int maxlen = 0; | |||||
| int numfiles; | int numfiles; | ||||
| int textheight; | int textheight; | ||||
| if (sfile->layout == NULL) { | if (sfile->layout == NULL) { | ||||
| sfile->layout = MEM_callocN(sizeof(struct FileLayout), "file_layout"); | sfile->layout = MEM_callocN(sizeof(struct FileLayout), "file_layout"); | ||||
| sfile->layout->dirty = true; | sfile->layout->dirty = true; | ||||
| } | } | ||||
| else if (sfile->layout->dirty == false) { | else if (sfile->layout->dirty == false) { | ||||
| Show All 10 Lines | if (params->display == FILE_IMGDISPLAY) { | ||||
| layout->prv_h = ((float)params->thumbnail_size / 20.0f) * UI_UNIT_Y; | layout->prv_h = ((float)params->thumbnail_size / 20.0f) * UI_UNIT_Y; | ||||
| layout->tile_border_x = 0.3f * UI_UNIT_X; | layout->tile_border_x = 0.3f * UI_UNIT_X; | ||||
| layout->tile_border_y = 0.3f * UI_UNIT_X; | layout->tile_border_y = 0.3f * UI_UNIT_X; | ||||
| layout->prv_border_x = 0.3f * UI_UNIT_X; | layout->prv_border_x = 0.3f * UI_UNIT_X; | ||||
| layout->prv_border_y = 0.3f * UI_UNIT_Y; | layout->prv_border_y = 0.3f * UI_UNIT_Y; | ||||
| layout->tile_w = layout->prv_w + 2 * layout->prv_border_x; | layout->tile_w = layout->prv_w + 2 * layout->prv_border_x; | ||||
| layout->tile_h = layout->prv_h + 2 * layout->prv_border_y + textheight; | layout->tile_h = layout->prv_h + 2 * layout->prv_border_y + textheight; | ||||
| layout->width = (int)(BLI_rctf_size_x(&v2d->cur) - 2 * layout->tile_border_x); | layout->width = (int)(BLI_rctf_size_x(&v2d->cur) - 2 * layout->tile_border_x); | ||||
| layout->columns = layout->width / (layout->tile_w + 2 * layout->tile_border_x); | layout->flow_columns = layout->width / (layout->tile_w + 2 * layout->tile_border_x); | ||||
| if (layout->columns > 0) { | layout->attribute_column_header_h = 0; | ||||
| layout->rows = numfiles / layout->columns + 1; // XXX dirty, modulo is zero | layout->offset_top = 0; | ||||
| if (layout->flow_columns > 0) { | |||||
| layout->rows = numfiles / layout->flow_columns + 1; // XXX dirty, modulo is zero | |||||
| } | } | ||||
| else { | else { | ||||
| layout->columns = 1; | layout->flow_columns = 1; | ||||
| layout->rows = numfiles + 1; // XXX dirty, modulo is zero | layout->rows = numfiles + 1; // XXX dirty, modulo is zero | ||||
| } | } | ||||
| layout->height = sfile->layout->rows * (layout->tile_h + 2 * layout->tile_border_y) + | layout->height = sfile->layout->rows * (layout->tile_h + 2 * layout->tile_border_y) + | ||||
| layout->tile_border_y * 2; | layout->tile_border_y * 2 - layout->offset_top; | ||||
| layout->flag = FILE_LAYOUT_VER; | layout->flag = FILE_LAYOUT_VER; | ||||
| } | } | ||||
| else { | else if (params->display == FILE_VERTICALDISPLAY) { | ||||
| int column_space = 0.6f * UI_UNIT_X; | int rowcount; | ||||
| int column_icon_space = 0.2f * UI_UNIT_X; | |||||
| layout->prv_w = 0; | layout->prv_w = ((float)params->thumbnail_size / 20.0f) * UI_UNIT_X; | ||||
| layout->prv_h = 0; | layout->prv_h = ((float)params->thumbnail_size / 20.0f) * UI_UNIT_Y; | ||||
| layout->tile_border_x = 0.4f * UI_UNIT_X; | |||||
| layout->tile_border_y = 0.1f * UI_UNIT_Y; | |||||
| layout->tile_h = textheight * 3 / 2; | |||||
| layout->width = (int)(BLI_rctf_size_x(&v2d->cur) - 2 * layout->tile_border_x); | |||||
| layout->tile_w = layout->width; | |||||
| layout->flow_columns = 1; | |||||
| layout->attribute_column_header_h = layout->tile_h * 1.2f + 2 * layout->tile_border_y; | |||||
| layout->offset_top = layout->attribute_column_header_h; | |||||
| rowcount = (int)(BLI_rctf_size_y(&v2d->cur) - layout->offset_top - 2 * layout->tile_border_y) / | |||||
| (layout->tile_h + 2 * layout->tile_border_y); | |||||
| file_attribute_columns_init(params, layout); | |||||
| layout->rows = MAX2(rowcount, numfiles); | |||||
| BLI_assert(layout->rows != 0); | |||||
| layout->height = sfile->layout->rows * (layout->tile_h + 2 * layout->tile_border_y) + | |||||
| layout->tile_border_y * 2 + layout->offset_top; | |||||
| layout->flag = FILE_LAYOUT_VER; | |||||
| } | |||||
| else if (params->display == FILE_HORIZONTALDISPLAY) { | |||||
| layout->prv_w = ((float)params->thumbnail_size / 20.0f) * UI_UNIT_X; | |||||
| layout->prv_h = ((float)params->thumbnail_size / 20.0f) * UI_UNIT_Y; | |||||
| layout->tile_border_x = 0.4f * UI_UNIT_X; | layout->tile_border_x = 0.4f * UI_UNIT_X; | ||||
| layout->tile_border_y = 0.1f * UI_UNIT_Y; | layout->tile_border_y = 0.1f * UI_UNIT_Y; | ||||
| layout->prv_border_x = 0; | |||||
| layout->prv_border_y = 0; | |||||
| layout->tile_h = textheight * 3 / 2; | layout->tile_h = textheight * 3 / 2; | ||||
| layout->attribute_column_header_h = 0; | |||||
| layout->offset_top = layout->attribute_column_header_h; | |||||
| layout->height = (int)(BLI_rctf_size_y(&v2d->cur) - 2 * layout->tile_border_y); | layout->height = (int)(BLI_rctf_size_y(&v2d->cur) - 2 * layout->tile_border_y); | ||||
| /* Padding by full scrollbar H is too much, can overlap tile border Y. */ | /* Padding by full scrollbar H is too much, can overlap tile border Y. */ | ||||
| layout->rows = (layout->height - V2D_SCROLL_HEIGHT + layout->tile_border_y) / | layout->rows = (layout->height - V2D_SCROLL_HEIGHT + layout->tile_border_y) / | ||||
| (layout->tile_h + 2 * layout->tile_border_y); | (layout->tile_h + 2 * layout->tile_border_y); | ||||
| layout->tile_w = VERTLIST_MAJORCOLUMN_WIDTH; | |||||
| file_attribute_columns_init(params, layout); | |||||
| column_widths(params, layout); | |||||
| if (params->display == FILE_SHORTDISPLAY) { | |||||
| maxlen = ICON_DEFAULT_WIDTH_SCALE + column_icon_space + | |||||
| (int)layout->column_widths[COLUMN_NAME] + column_space + | |||||
| (int)layout->column_widths[COLUMN_SIZE] + column_space; | |||||
| } | |||||
| else { | |||||
| maxlen = ICON_DEFAULT_WIDTH_SCALE + column_icon_space + | |||||
| (int)layout->column_widths[COLUMN_NAME] + column_space + | |||||
| (int)layout->column_widths[COLUMN_DATE] + column_space + | |||||
| (int)layout->column_widths[COLUMN_TIME] + column_space + | |||||
| (int)layout->column_widths[COLUMN_SIZE] + column_space; | |||||
| } | |||||
| layout->tile_w = maxlen; | |||||
| if (layout->rows > 0) { | if (layout->rows > 0) { | ||||
| layout->columns = numfiles / layout->rows + 1; // XXX dirty, modulo is zero | layout->flow_columns = numfiles / layout->rows + 1; // XXX dirty, modulo is zero | ||||
| } | } | ||||
| else { | else { | ||||
| layout->rows = 1; | layout->rows = 1; | ||||
| layout->columns = numfiles + 1; // XXX dirty, modulo is zero | layout->flow_columns = numfiles + 1; // XXX dirty, modulo is zero | ||||
| } | } | ||||
| layout->width = sfile->layout->columns * (layout->tile_w + 2 * layout->tile_border_x) + | layout->width = sfile->layout->flow_columns * (layout->tile_w + 2 * layout->tile_border_x) + | ||||
| layout->tile_border_x * 2; | layout->tile_border_x * 2; | ||||
| layout->flag = FILE_LAYOUT_HOR; | layout->flag = FILE_LAYOUT_HOR; | ||||
| } | } | ||||
| params->display_previous = params->display; | params->display_previous = params->display; | ||||
| layout->dirty = false; | layout->dirty = false; | ||||
| } | } | ||||
| FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, ARegion *ar) | FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, ARegion *ar) | ||||
| ▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines | |||||
Strings should be tagged for translation