[Bf-taskforce25] operators and context

Jean-Luc Peurière jlp at nerim.net
Tue Oct 7 19:04:38 CEST 2008


Le 7 oct. 08 à 18:03, Brecht Van Lommel a écrit :

>
> Hi,
>
> I'm trying to get a grip on the design of this context concept in 2.5,
> but parts of it are quite unclear to me. One of the areas that I'm
> unsure about is how operators figure out which data to operate on.
>
> Let's take a practical example, a "delete object" operator. In the 3D
> view the delete object operator would work on all selected objects.
> However you can also delete objects from the outliner, were it would
> work on the objects as selected there (selection state is completely
> separate here). One could also imagine a button that would delete the
> active object in the buttons window.
>
> There's a few possibilities to figure out this data:
> a) The operator is aware of the space it is running in, and knows that
> for the 3d view it uses the selected objects, for the outliner the
> selection state there, .. etc. Here you could have multiple operators,
> one for each case, or a single operator handling all these cases.
> b) The operator is directly passed the objects it operates on somehow,
> for example through a property of the operator.
> c) There is an abstraction that allows you to ask the context things
> like 'give a list of selected objects', and then the context can  
> return
> different things based on the space, etc.

there is a d) case :

d) the space controller define the context, and the operator that is
called when a command is issued, when that space is active.
Some spaces dont define their own context but use the general
  one (buttons).

I did not look at the 2.5 code for a long time, but this is how I saw
things originally, and I thought Kaito used that idea.

So there is a need to decouple commands and operator called
depending of the context, but no direct knowledge of the context
nor abstraction is needed.

this also allow temp local loops overloading, or easier script handling.

So in your delete example, if the active context was setup by 3Dview
a given delete operator is called, but when the outliner is the active
one, it is either a different one or the context being different, it  
acts
on a different selection.
>


Again, that is theorical MVC stuff, not checked if it works that way in
the actual code

-- 
Jean-Luc Peurière
jlp at nerim.net





More information about the Bf-taskforce25 mailing list