Outliner: move filter options to popover.

This commit is contained in:
Brecht Van Lommel
2018-05-09 13:40:34 +02:00
parent d3b80c4734
commit 03fc491048
6 changed files with 100 additions and 128 deletions

View File

@@ -18,7 +18,7 @@
# <pep8 compliant>
import bpy
from bpy.types import Header, Menu
from bpy.types import Header, Menu, Panel
class OUTLINER_HT_header(Header):
@@ -65,46 +65,13 @@ class OUTLINER_HT_header(Header):
row.prop(space, "use_filter_complete", text="")
row.prop(space, "use_filter_case_sensitive", text="")
row = layout.row()
if support_filters:
row.separator()
row.prop(space, "use_filters", text="")
if space.use_filters:
row.separator()
row.prop(space, "use_filter_collection", text="")
row.prop(space, "use_filter_object", text="")
sub = row.row(align=True)
sub.active = space.use_filter_object
sub.prop(space, "use_filter_object_content", text="")
sub.prop(space, "use_filter_children", text="")
sub.separator()
sub.prop(space, "use_filter_object_type", text="")
if space.use_filter_object_type:
if bpy.data.meshes:
sub.prop(space, "use_filter_object_mesh", text="")
if bpy.data.armatures:
sub.prop(space, "use_filter_object_armature", text="")
if bpy.data.lamps:
sub.prop(space, "use_filter_object_lamp", text="")
if bpy.data.cameras:
sub.prop(space, "use_filter_object_camera", text="")
sub.prop(space, "use_filter_object_empty", text="")
if bpy.data.curves or \
bpy.data.metaballs or \
bpy.data.lightprobes or \
bpy.data.lattices or \
bpy.data.fonts or bpy.data.speakers:
sub.prop(space, "use_filter_object_others", text="")
sub.separator()
sub.prop(space, "use_filter_object_state", text="")
if space.use_filter_object_state:
sub.prop(space, "filter_state", text="", expand=True)
row.popover(space_type='OUTLINER',
region_type='HEADER',
panel_type="OUTLINER_PT_filter",
text="",
icon='FILTER')
class OUTLINER_MT_editor_menus(Menu):
@@ -247,6 +214,50 @@ class OUTLINER_MT_context_object(Menu):
layout.operator("outliner.object_operation", text="Rename").type='RENAME'
class OUTLINER_PT_filter(Panel):
bl_space_type = 'OUTLINER'
bl_region_type = 'HEADER'
bl_label = "Filter"
def draw(self, context):
layout = self.layout
space = context.space_data
col = layout.column()
col.prop(space, "filter_state", text="")
sub = col.column(align=True)
sub.active = space.filter_state != 'NONE'
sub.prop(space, "use_filter_object_content", text="Object Contents")
sub.prop(space, "use_filter_children", text="Object Children")
layout.separator()
col = layout.column_flow(align=True)
col.active = space.filter_state != 'NONE'
if bpy.data.meshes:
col.prop(space, "use_filter_object_mesh", text="Meshes")
if bpy.data.armatures:
col.prop(space, "use_filter_object_armature", text="Armatures")
if bpy.data.lamps:
col.prop(space, "use_filter_object_lamp", text="Lamps")
if bpy.data.cameras:
col.prop(space, "use_filter_object_camera", text="Cameras")
col.prop(space, "use_filter_object_empty", text="Empties")
if bpy.data.curves or \
bpy.data.metaballs or \
bpy.data.lightprobes or \
bpy.data.lattices or \
bpy.data.fonts or bpy.data.speakers:
col.prop(space, "use_filter_object_others", text="Others")
layout.separator()
layout.prop(space, "use_filter_collection", text="Collections")
classes = (
OUTLINER_HT_header,
OUTLINER_MT_editor_menus,
@@ -259,6 +270,7 @@ classes = (
OUTLINER_MT_context_object_delete,
OUTLINER_MT_context_object_select,
OUTLINER_MT_context_object_collection,
OUTLINER_PT_filter,
)
if __name__ == "__main__": # only for live edit.

View File

@@ -95,10 +95,7 @@ static int outliner_objects_collection_poll(bContext *C)
}
/* Groups don't support filtering. */
if ((so->outlinevis != SO_GROUPS) &&
((so->filter & (SO_FILTER_ENABLE | SO_FILTER_NO_COLLECTION)) ==
(SO_FILTER_ENABLE | SO_FILTER_NO_COLLECTION)))
{
if ((so->outlinevis != SO_GROUPS) && (so->filter & SO_FILTER_NO_COLLECTION)) {
return 0;
}

View File

@@ -2089,8 +2089,7 @@ static int outliner_parenting_poll(bContext *C)
}
if (soops->outlinevis == SO_COLLECTIONS) {
return ((soops->filter & SO_FILTER_ENABLE) &&
(soops->filter & SO_FILTER_NO_COLLECTION));
return (soops->filter & SO_FILTER_NO_COLLECTION);
}
}

View File

@@ -1833,9 +1833,7 @@ static void outliner_store_scrolling_position(SpaceOops *soops, ARegion *ar, Out
static int outliner_exclude_filter_get(SpaceOops *soops)
{
int exclude_filter = soops->filter & ~(SO_FILTER_OB_STATE_VISIBLE |
SO_FILTER_OB_STATE_SELECTED |
SO_FILTER_OB_STATE_ACTIVE);
int exclude_filter = soops->filter & ~SO_FILTER_OB_STATE;
if (soops->filter & SO_FILTER_SEARCH) {
if (soops->search_string[0] == 0) {
@@ -1848,26 +1846,19 @@ static int outliner_exclude_filter_get(SpaceOops *soops)
return (exclude_filter & SO_FILTER_SEARCH);
}
if ((exclude_filter & SO_FILTER_NO_OB_ALL) == 0) {
exclude_filter &= ~SO_FILTER_OB_TYPE;
}
if (exclude_filter & SO_FILTER_OB_STATE) {
switch (soops->filter_state) {
case SO_FILTER_OB_VISIBLE:
exclude_filter |= SO_FILTER_OB_STATE_VISIBLE;
break;
case SO_FILTER_OB_SELECTED:
exclude_filter |= SO_FILTER_OB_STATE_SELECTED;
break;
case SO_FILTER_OB_ACTIVE:
exclude_filter |= SO_FILTER_OB_STATE_ACTIVE;
break;
}
}
if ((exclude_filter & SO_FILTER_ANY) == 0) {
exclude_filter &= ~(SO_FILTER_OB_STATE);
switch (soops->filter_state) {
case SO_FILTER_OB_NONE:
exclude_filter |= SO_FILTER_OB_TYPE;
break;
case SO_FILTER_OB_VISIBLE:
exclude_filter |= SO_FILTER_OB_STATE_VISIBLE;
break;
case SO_FILTER_OB_SELECTED:
exclude_filter |= SO_FILTER_OB_STATE_SELECTED;
break;
case SO_FILTER_OB_ACTIVE:
exclude_filter |= SO_FILTER_OB_STATE_ACTIVE;
break;
}
return exclude_filter;
@@ -1875,13 +1866,13 @@ static int outliner_exclude_filter_get(SpaceOops *soops)
static bool outliner_element_visible_get(ViewLayer *view_layer, TreeElement *te, const int exclude_filter)
{
if ((exclude_filter & SO_FILTER_ENABLE) == 0) {
if ((exclude_filter & SO_FILTER_ANY) == 0) {
return true;
}
TreeStoreElem *tselem = TREESTORE(te);
if ((tselem->type == 0) && (te->idcode == ID_OB)) {
if ((exclude_filter & SO_FILTER_NO_OBJECT)) {
if ((exclude_filter & SO_FILTER_OB_TYPE) == SO_FILTER_OB_TYPE) {
return false;
}
@@ -2202,7 +2193,7 @@ void outliner_build_tree(Main *mainvar, Scene *scene, ViewLayer *view_layer, Spa
tenlay->directdata = view_layer;
TREESTORE(tenlay)->flag &= ~TSE_CLOSED;
if ((soops->filter & SO_FILTER_ENABLE) && (soops->filter & SO_FILTER_NO_COLLECTION)) {
if (soops->filter & SO_FILTER_NO_COLLECTION) {
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
TreeElement *te_object = outliner_add_element(soops, &tenlay->subtree, base->object, NULL, 0, 0);
te_object->directdata = base;

View File

@@ -279,12 +279,12 @@ typedef enum eSpaceOutliner_Flag {
/* SpaceOops->filter */
typedef enum eSpaceOutliner_Filter {
SO_FILTER_SEARCH = (1 << 0),
SO_FILTER_ENABLE = (1 << 1),
SO_FILTER_NO_OBJECT = (1 << 2),
/* SO_FILTER_ENABLE = (1 << 1), */ /* Deprecated */
/* SO_FILTER_NO_OBJECT = (1 << 2), */ /* Deprecated */
SO_FILTER_NO_OB_CONTENT = (1 << 3), /* Not only mesh, but modifiers, constraints, ... */
SO_FILTER_NO_CHILDREN = (1 << 4),
SO_FILTER_OB_TYPE = (1 << 5),
/* SO_FILTER_OB_TYPE = (1 << 5), */ /* Deprecated */
SO_FILTER_NO_OB_MESH = (1 << 6),
SO_FILTER_NO_OB_ARMATURE = (1 << 7),
SO_FILTER_NO_OB_EMPTY = (1 << 8),
@@ -292,22 +292,25 @@ typedef enum eSpaceOutliner_Filter {
SO_FILTER_NO_OB_CAMERA = (1 << 10),
SO_FILTER_NO_OB_OTHERS = (1 << 11),
SO_FILTER_OB_STATE = (1 << 12),
/* SO_FILTER_OB_STATE = (1 << 12), */ /* Deprecated */
SO_FILTER_OB_STATE_VISIBLE = (1 << 13), /* Not set via DNA. */
SO_FILTER_OB_STATE_SELECTED = (1 << 14), /* Not set via DNA. */
SO_FILTER_OB_STATE_ACTIVE = (1 << 15), /* Not set via DNA. */
SO_FILTER_NO_COLLECTION = (1 << 16),
} eSpaceOutliner_Filter;
#define SO_FILTER_NO_OB_ALL (SO_FILTER_NO_OB_MESH | \
SO_FILTER_NO_OB_ARMATURE | \
SO_FILTER_NO_OB_EMPTY | \
SO_FILTER_NO_OB_LAMP | \
SO_FILTER_NO_OB_CAMERA | \
SO_FILTER_NO_OB_OTHERS)
#define SO_FILTER_OB_TYPE (SO_FILTER_NO_OB_MESH | \
SO_FILTER_NO_OB_ARMATURE | \
SO_FILTER_NO_OB_EMPTY | \
SO_FILTER_NO_OB_LAMP | \
SO_FILTER_NO_OB_CAMERA | \
SO_FILTER_NO_OB_OTHERS)
#define SO_FILTER_ANY (SO_FILTER_NO_OBJECT | \
SO_FILTER_NO_OB_CONTENT | \
#define SO_FILTER_OB_STATE (SO_FILTER_OB_STATE_VISIBLE | \
SO_FILTER_OB_STATE_SELECTED | \
SO_FILTER_OB_STATE_ACTIVE)
#define SO_FILTER_ANY (SO_FILTER_NO_OB_CONTENT | \
SO_FILTER_NO_CHILDREN | \
SO_FILTER_OB_TYPE | \
SO_FILTER_OB_STATE | \
@@ -315,9 +318,11 @@ typedef enum eSpaceOutliner_Filter {
/* SpaceOops->filter_state */
typedef enum eSpaceOutliner_StateFilter {
SO_FILTER_OB_VISIBLE = 0,
SO_FILTER_OB_SELECTED = 1,
SO_FILTER_OB_ACTIVE = 2,
SO_FILTER_OB_ALL = 0,
SO_FILTER_OB_VISIBLE = 1,
SO_FILTER_OB_SELECTED = 2,
SO_FILTER_OB_ACTIVE = 3,
SO_FILTER_OB_NONE = 4,
} eSpaceOutliner_StateFilter;
/* SpaceOops->outlinevis */

View File

@@ -2036,9 +2036,11 @@ static void rna_def_space_outliner(BlenderRNA *brna)
};
static const EnumPropertyItem filter_state_items[] = {
{SO_FILTER_OB_VISIBLE, "VISIBLE", ICON_RESTRICT_VIEW_OFF, "Visible", "Show visible objects"},
{SO_FILTER_OB_SELECTED, "SELECTED", ICON_RESTRICT_SELECT_OFF, "Selected", "Show selected objects"},
{SO_FILTER_OB_ACTIVE, "ACTIVE", ICON_LAYER_ACTIVE, "Active", "Show only the active object"},
{SO_FILTER_OB_NONE, "NONE", 0, "No Objects", "Don't show objects"},
{SO_FILTER_OB_ALL, "ALL", 0, "All Objects", "Show visible objects"},
{SO_FILTER_OB_VISIBLE, "VISIBLE", 0, "Visible Objects", "Show visible objects"},
{SO_FILTER_OB_SELECTED, "SELECTED", 0, "Selected Objects", "Show selected objects"},
{SO_FILTER_OB_ACTIVE, "ACTIVE", 0, "Active Object", "Show only the active object"},
{0, NULL, 0, NULL, NULL}
};
@@ -2088,91 +2090,57 @@ static void rna_def_space_outliner(BlenderRNA *brna)
RNA_def_property_ui_icon(prop, ICON_VIEWZOOM, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filters", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "filter", SO_FILTER_ENABLE);
RNA_def_property_ui_text(prop, "Use Filters", "Use filters");
RNA_def_property_ui_icon(prop, ICON_FILTER, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OBJECT);
RNA_def_property_ui_text(prop, "Filter Objects", "Show objects");
RNA_def_property_ui_icon(prop, ICON_OBJECT_DATA, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object_content", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_CONTENT);
RNA_def_property_ui_text(prop, "Filter Objects Contents", "Show what is inside the objects elements");
RNA_def_property_ui_icon(prop, ICON_MODIFIER, 0);
RNA_def_property_ui_text(prop, "Show Object Contents", "Show what is inside the objects elements");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_children", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_CHILDREN);
RNA_def_property_ui_text(prop, "Filter Objects Children", "Show children");
RNA_def_property_ui_icon(prop, ICON_PLUS, 0);
RNA_def_property_ui_text(prop, "Show Object Children", "Show children");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_collection", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_COLLECTION);
RNA_def_property_ui_text(prop, "Filter Collections", "Show collections");
RNA_def_property_ui_icon(prop, ICON_COLLAPSEMENU, 0);
RNA_def_property_ui_text(prop, "Show Collections", "Show collections");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
/* Filters object state. */
prop = RNA_def_property(srna, "use_filter_object_state", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "filter", SO_FILTER_OB_STATE);
RNA_def_property_ui_text(prop, "Filter Object State", "Filter objects based on their state (visible, ...)."
"This can be slow");
RNA_def_property_ui_icon(prop, ICON_LAYER_USED, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "filter_state", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "filter_state");
RNA_def_property_enum_items(prop, filter_state_items);
RNA_def_property_ui_text(prop, "State Filter", "");
RNA_def_property_ui_text(prop, "Object State Filter", "");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
/* Filters object type. */
prop = RNA_def_property(srna, "use_filter_object_type", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "filter", SO_FILTER_OB_TYPE);
RNA_def_property_ui_text(prop, "Filter Object Type", "Show specific objects types");
RNA_def_property_ui_icon(prop, ICON_MESH_CUBE, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object_mesh", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_MESH);
RNA_def_property_ui_text(prop, "Show Meshes", "Show mesh objects");
RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_MESH, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object_armature", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_ARMATURE);
RNA_def_property_ui_text(prop, "Show Armatures", "Show armature objects");
RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_ARMATURE, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object_empty", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_EMPTY);
RNA_def_property_ui_text(prop, "Show Empties", "Show empty objects");
RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_EMPTY, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object_lamp", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_LAMP);
RNA_def_property_ui_text(prop, "Show Lamps", "Show lamps objects");
RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_LAMP, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object_camera", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_CAMERA);
RNA_def_property_ui_text(prop, "Show Cameras", "Show camera objects");
RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_CAMERA, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_object_others", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_OTHERS);
RNA_def_property_ui_text(prop, "Show Other Objects", "Show curves, lattices, light probes, fonts, ...");
RNA_def_property_ui_icon(prop, ICON_ZOOMIN, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
}