File Browser: Make full file name label draggable
Previously only the icon of a file could be dragged in the list display modes, the name label would invoke box select. This made dragging quite finicky. I've seen this cause quite some frustration, especially when the file browser is used as a regular editor to drag data from into other editors. Instead follow the Outliner (and some other file browsers like the macOS one): Dragging on empty space invokes box select, dragging on the name or icon invokes drag & drop of the item. The hitbox for the dragging is the width of the string, and the full row height. So there's no space between rows to do box-select from, it always triggers dragging. This is based on feedback during testing. Note that1e9564864cand6da512f0bcwere needed to prepare this change. Pull Request: #104830
This commit is contained in:
@@ -1037,6 +1037,33 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
}
|
||||
else {
|
||||
const int icon = filelist_geticon(files, i, true);
|
||||
|
||||
icon_ofs += ICON_DEFAULT_WIDTH_SCALE + 0.2f * UI_UNIT_X;
|
||||
|
||||
/* Add dummy draggable button covering the icon and the label. */
|
||||
if (do_drag) {
|
||||
const uiStyle *style = UI_style_get();
|
||||
const int str_width = UI_fontstyle_string_width(&style->widget, file->name);
|
||||
const int drag_width = MIN2(str_width + icon_ofs, column_width - ATTRIBUTE_COLUMN_PADDING);
|
||||
uiBut *drag_but = uiDefBut(block,
|
||||
UI_BTYPE_LABEL,
|
||||
0,
|
||||
"",
|
||||
tile_draw_rect.xmin,
|
||||
tile_draw_rect.ymin - 1,
|
||||
drag_width,
|
||||
layout->tile_h + layout->tile_border_y * 2,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
UI_but_dragflag_enable(drag_but, UI_BUT_DRAG_FULL_BUT);
|
||||
file_but_enable_drag(drag_but, sfile, file, path, NULL, icon, UI_DPI_FAC);
|
||||
}
|
||||
|
||||
/* Add this after the fake draggable button, so the icon button tooltip is displayed. */
|
||||
uiBut *icon_but = file_add_icon_but(sfile,
|
||||
block,
|
||||
path,
|
||||
@@ -1046,9 +1073,10 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
ICON_DEFAULT_HEIGHT_SCALE,
|
||||
is_hidden);
|
||||
if (do_drag) {
|
||||
/* For some reason the dragging is unreliable for the icon button if we don't explicitly
|
||||
* enable dragging, even though the dummy drag button above covers the same area. */
|
||||
file_but_enable_drag(icon_but, sfile, file, path, NULL, icon, UI_DPI_FAC);
|
||||
}
|
||||
icon_ofs += ICON_DEFAULT_WIDTH_SCALE + 0.2f * UI_UNIT_X;
|
||||
}
|
||||
|
||||
if (file_selflag & FILE_SEL_EDITING) {
|
||||
|
||||
Reference in New Issue
Block a user