File Browser: Scroll view on normal selection too

Adjusts view after mouse/border selection if some selected items are out of view bounds.
To get as much of the selection into view as possible, this adjusts view first for the last, then for the first element in the selection.
Also, if region is pretty small, view adjustment is skipped, as otherwise the view is focused on the first element only, which isn't really useful IMHO.

Maybe not so nice: Since we do two view alignment iterations, UI_view2d_curRect_validate, which is a rather big function *might* be called twice under certain circumstances (border select & total size of selected elements is exceeds view bounds). I think that's totally acceptable though.
This commit is contained in:
Julian Eisel
2015-09-19 04:24:48 +02:00
parent d7e88fe1fd
commit 36d64240e6

View File

@@ -305,6 +305,20 @@ static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select,
if (select != FILE_SEL_ADD && !file_is_any_selected(sfile->files)) {
sfile->params->active_file = -1;
}
else {
ARegion *ar = CTX_wm_region(C);
const FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
/* Adjust view to display selection. Doing iterations for first and last
* selected item makes view showing as much of the selection possible.
* Not really useful if tiles are (almost) bigger than viewbounds though. */
if (((layout->flag & FILE_LAYOUT_HOR) && ar->winx > (1.2f * layout->tile_w)) ||
((layout->flag & FILE_LAYOUT_VER) && ar->winy > (2.0f * layout->tile_h)))
{
file_ensure_inside_viewbounds(ar, sfile, sel.last);
file_ensure_inside_viewbounds(ar, sfile, sel.first);
}
}
/* update operator for name change event */
file_draw_check(C);