Page MenuHome

Minimal Drag&Drop implementation

Authored by Campbell Barton (campbellbarton) on May 23 2015, 3:15 PM.



Implements Drag&Drop only for File Import Selection Window

Diff Detail

rB Blender

Event Timeline

Gaia Clary (gaiaclary) retitled this revision from to Minimal Drag&Drop implementation.
Gaia Clary (gaiaclary) updated this object.

removed unnecessarily changes on some blank lines (minor)

This implements the most simple drag&drop. The only benefit is that the user does not need to navigate in the file selection window, but can drag a file from the native file browser and drop it into the file selection window.


The Import Operator has already been selected by the user.
The user still can modify the import options before the file is imported to Blender


It is not a true drag&drop into canvas as proposed in the task.
But maybe its a begin


I am unsure if this is correct, because the operator already opened the file selection window, so calling it again may be is not the proper way? But i do not know for sure.

Sergey Sharybin (sergey) added inline comments.

Brace should be at the same line.


Don't think drag-drop to file browser should actually invoke operator, instead it should just fill int he file path and name.

Campbell Barton (campbellbarton) requested changes to this revision.May 29 2015, 8:08 AM
Campbell Barton (campbellbarton) edited edge metadata.
Campbell Barton (campbellbarton) added inline comments.

Its not certain that filepath is even available. There are directory only file selectors (File -> External Files -> Find Missing) for example.

This should instead check for directory and filepath properties, and set them if they're available.


Just access sfile->op->ot


Please keep style consistent.

This revision now requires changes to proceed.May 29 2015, 8:08 AM
Gaia Clary (gaiaclary) edited edge metadata.

Now checking if property filepath and directory exist.
fixed syntax (brace)

Gaia Clary (gaiaclary) edited edge metadata.

Fixed one more wrong placed brace

Gaia Clary (gaiaclary) marked 4 inline comments as done.May 29 2015, 11:08 AM

I have 2 issues still:

  1. file_ops.c:1299 I tried to just return OPERATOR_FINISHED here. But then the dropped filepath is not shown in the file import window. So i do not know how to avoid calling the operator here.
  2. When i drop a file into the file import window when the Collada Importer is open, then the dropped file is directly imported into the scene. Is this because the Collada importer does not have its own invoke function? What should i do best to avoid the collada importer's direct import of a dropped file? I did not do anything here for now because this may become obsolete after my first issue is solved.
Campbell Barton (campbellbarton) requested changes to this revision.Jun 10 2015, 10:12 AM
Campbell Barton (campbellbarton) edited edge metadata.

Think this is how (I think) it should work...

  • Drop path onto file selector.
  • access sfile->op, filepath / directory
  • Set the property in place, rather than invoking again... This is important, since you may have changes a bunch of options already.

As an extra it could also select the path in the file browser (select multiple paths for dropping multiple files...) but this can be done after.

This revision now requires changes to proceed.Jun 10 2015, 10:12 AM
Gaia Clary (gaiaclary) edited edge metadata.

Applied requested changes.

Found 2 odd things...

  • Dropping a file into the browser doesn't refresh the file browser.
  • Dropping a directory acts as if its a file (directory name shows up in the filename field).

Also calling this FILE_OT_import_activate is quite odd, since this doesnt import anything. Maybe best call it FILE_OT_filepath_drop ?

Campbell Barton (campbellbarton) requested changes to this revision.Nov 2 2015, 2:30 PM
Campbell Barton (campbellbarton) edited edge metadata.
This revision now requires changes to proceed.Nov 2 2015, 2:30 PM
Gaia Clary (gaiaclary) edited edge metadata.
  • Merge branch 'master' into arcpatch-D1322
  • adjusted operator name to something more understandable
  • adjusted an API change in the file selector calling function

    This is work in progress still. The automatic screen update after drop does not work at the moment, this needs more checking.
Gaia Clary (gaiaclary) edited edge metadata.
  • Added an event notifier to update the file browser area after dropping a new file path

    This is still work in progress, no need to review yet.

Added special case when only a directory is dropped

I am happy with this version. However there is one pitfall still:

Assume the user has enabled a file extension filter.
Now the user drops a file to the file browser with a different file extension.

The File browser switches to the new directory as intended.
The file is displayed in the filename field as expected
But the file is not visible in the file browser (because the extension filter hides it)

This might be confusing.

imho there are 3 solutions:

1.) Disable filter when filter is enabled but file with different extension is dropped
2.) Reject file when filter is enabled and file with wrong extension is dropped
3.) do nothing, just keep this as a "feature not a bug"

Added check for "file does not exist" (operator reports a message)

Moved the further development into a temporary branch remotes/origin/temp_file-dropper

other issues


No need for invoke function.


No need for all fileselector properties, single "filepath" is enough.


no need to check operator