Page MenuHome

Fix T93368: Dragging Blends Without Previews
ClosedPublic

Authored by Harley Acheson (harley) on Nov 26 2021, 5:17 PM.

Details

Summary

Fix blend_file_drop_poll so that it will allow dropping blend files
that do not have previews, which have different icon. This allows
dragging blend backup files (.blend1) too.


The small icon used to represent blend files used to be the blender logo. This was changed to one that looks like a smaller logo inside of a document. Unfortunately this looks funny when in Thumbnail view and the blend file does not have a preview, which means you get a document with a blend logo inside a larger document. I recently changed that so that it used just a blender logo in the large document in this case.

Unfortunately the drag and drop poll function, which gives a "yah/nay" if a drop is allowed, only checks for the icon. This patch changes the allowed icons from just ICON_FILE_BLEND to ICON_FILE_BLEND, ICON_BLENDER, ICON_FILE_BACKUP. Note that this allows dragging of blender backup files (.blend1) which appears to have never worked.

Diff Detail

Repository
rB Blender

Event Timeline

Harley Acheson (harley) requested review of this revision.Nov 26 2021, 5:17 PM
Harley Acheson (harley) created this revision.

Gosh... making this based on the used icon is quite bad (existing code I mean, not your fault!), let's move away from that. Pretty sure this could just check the extension of wmDrag.path. There is BLO_has_bfile_extension(), but that doesn't cover backup .blends. For that file_is_blend_backup() could be moved to BLO.

Alternatively if we stick to the drag based icon (may be safer for 3.0), we can make sure to always pass ICON_FILE_BLEND to UI_but_drag_set_image() in file_draw_preview(), by calling filelist_geticon() again with is_main = true and pass that to .

@Julian Eisel (Severin):

There are some issues with both approaches, this patch is the first of your two so you can give it a think.

The weird thing about this one is that existing file_is_blend_backup returns true on regular blend files too. I don't mind this behavior as much when it is private, but seems weird as a public function. I added a comment about that in this patch though.

With the "alternative" idea we'd have to make filelist_geticon_ex public as that takes a FileDirEntry, not just a list with index. Not too bad, but the resulting code would be non-obvious with the is_main set to true. Commenting would just be explaining that we have two icons doing the same thing, so in the end it seems no better than using a list of icons. I didn't quite like it, but can do so if you don't like this patch.

This revision was not accepted when it landed; it landed in state Needs Review.Nov 30 2021, 3:41 PM
This revision was automatically updated to reflect the committed changes.

I ended up committing the icon based fix for the 3.0 branch (crediting you as author).

Two notes:

  • I removed the backup file support again, since at this point in the release cycle such functional changes shouldn't be done. Even if that trivial.
  • Checking on how to best solve this longer term, I decided this should be properly handled by the drag and drop code, not just ad-hoc for this case. So created a patch to refactor all cases that use icon based drag & drop logic: D13428: UI: Refactor path dropping so logic doesn't depend on icons

Just to reply to the previous comment (even though it doesn't matter for this anymore):

The weird thing about this one is that existing file_is_blend_backup returns true on regular blend files too. I don't mind this behavior as much when it is private, but seems weird as a public function. I added a comment about that in this patch though.

We could do two things in such a case, both fine with me:

  • Change the function name to reflect that, e.g. BLO_has_bfile_or_bfile_backup_extension().
  • Call BLO_has_bfile_extension() in the beginning of the function and early-exit with false if that is true. Some code paths may end up calling it multiple times, but I don't think that's an issue (and branch prediction might even optimize it away).

Just to reply to the previous comment (even though it doesn't matter for this anymore):

The weird thing about this one is that existing file_is_blend_backup returns true on regular blend files too. I don't mind this behavior as much when it is private, but seems weird as a public function. I added a comment about that in this patch though.

We could do two things in such a case, both fine with me:

  • Change the function name to reflect that, e.g. BLO_has_bfile_or_bfile_backup_extension().
  • Call BLO_has_bfile_extension() in the beginning of the function and early-exit with false if that is true. Some code paths may end up calling it multiple times, but I don't think that's an issue (and branch prediction might even optimize it away).

It can be replace with a one-liner:

/* Return true for .blend1, .blend23, .blend102, etc. */
static bool file_is_blend_backup(const char *str)
{
  return (!BLO_has_bfile_extension(str) && BLI_strcasestr(BLI_path_extension(str), ".blend"));
}