Page MenuHome

Make File Select dialog's execute button use attached operator's poll function
AbandonedPublic

Authored by Colin Basnett (cmbasnett) on Jul 29 2022, 11:24 PM.

Details

Summary

This adds the ability for operators to disable the "execute" button in the file select dialog by having the button use the operator's poll function.

This will allow more responsive interface for import/export addons. When used in tandem with D15543: Make File Select dialog trigger update function on operator's filepath, directory and filename properties, this amounts to a significant upgrade to the import and export file select dialog.

The video below shows the button being disabled when a particular setting is unchecked.

Diff Detail

Repository
rB Blender
Branch
master
Build Status
Buildable 23210
Build 23210: arc lint + arc unit

Event Timeline

Colin Basnett (cmbasnett) requested review of this revision.Jul 29 2022, 11:24 PM
Colin Basnett (cmbasnett) created this revision.
Julian Eisel (Severin) requested changes to this revision.Sep 1 2022, 4:29 PM
Julian Eisel (Severin) added inline comments.
source/blender/editors/space_file/file_ops.c
1836

Function needs to be static, there's also no need for the struct keyword (it's visual noise).

1838–1840

All of these can be const.

1840

Relying on params->active_file active file here seems problematic: FILE_OT_mouse_execute() is supposed to act on the hovered, not the active file.

I'd could use the following pattern:

static bool the_operator_poll(bContext *C)
{
  FileDirEntry *the_file = ...;
  return file_execute_poll(C, file);
}
This revision now requires changes to proceed.Sep 1 2022, 4:29 PM

On second thought, this whole thing could be a bit of a footgun.

It's not possible to inspect the provisional properties of an operator without a direct reference to it, so any poll function would have to act only on things accessible from the context.

So it's possible to put the operator in a state where it's poll function fails (due to fiddling with settings in the file select browser), exiting out of the file browser dialog, then having the operator be stuck returning False in its poll function, and so not being able to run it again.

This would need its own separate function callback that is like a poll function for an instantiated operator so that its properties could inspected.

I think it's still good to add a poll() check to file execution, the fact that it's missing currently seems like an oversight.

So it's possible to put the operator in a state where it's poll function fails (due to fiddling with settings in the file select browser), exiting out of the file browser dialog, then having the operator be stuck returning False in its poll function, and so not being able to run it again.

Could you elaborate on this? What settings would be checked by the poll function that would lead to this?

This would need its own separate function callback that is like a poll function for an instantiated operator so that its properties could inspected.

The file operation is exposed via bpy.types.SpaceFile.active_operator, you should be able to get the operator properties from that. Is that not sufficient?