Remove from Local View operator
authorDalai Felinto <dfelinto@gmail.com>
Fri, 30 Nov 2018 01:44:37 +0000 (23:44 -0200)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 30 Nov 2018 04:28:41 +0000 (02:28 -0200)
This was the old, obscure, little known, M shortcut operator when in local view
back in the 2.7x days.

release/scripts/presets/keyconfig/keymap_data/blender_default.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/object/object_edit.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/space_view3d/view3d_view.c

index 05f821524eb7f567b936445cb9d60989cff8428b..50609d2b3b80252f0f84e8cbd97fb977713727d5 100644 (file)
@@ -869,6 +869,7 @@ def km_view3d(params):
         # Visibility.
         ("view3d.localview", {"type": 'NUMPAD_SLASH', "value": 'PRESS'}, None),
         ("view3d.localview", {"type": 'SLASH', "value": 'PRESS'}, None),
+        ("view3d.localview_remove_from", {"type": 'M', "value": 'PRESS'}, None),
         # Navigation.
         ("view3d.rotate", {"type": 'MIDDLEMOUSE', "value": 'PRESS'}, None),
         ("view3d.move", {"type": 'MIDDLEMOUSE', "value": 'PRESS', "shift": True}, None),
index 3a95eb698c7eee6c28565a94c3e8750f7ab59fc7..56b57f0d4907350db8efe412efe6845a4b9bef8c 100644 (file)
@@ -596,7 +596,7 @@ class VIEW3D_MT_view(Menu):
 
         layout.operator("view3d.view_all", text="Frame All").center = False
         layout.operator("view3d.view_persportho", text="Perspective/Orthographic")
-        layout.operator("view3d.localview")
+        layout.menu("VIEW3D_MT_view_local")
 
         layout.separator()
 
@@ -626,6 +626,17 @@ class VIEW3D_MT_view(Menu):
         layout.menu("INFO_MT_area")
 
 
+class VIEW3D_MT_view_local(Menu):
+    bl_label = "Local View"
+
+    def draw(self, context):
+        layout = self.layout
+        view = context.space_data
+
+        layout.operator("view3d.localview", text="Toggle Local View")
+        layout.operator("view3d.localview_remove_from")
+
+
 class VIEW3D_MT_view_cameras(Menu):
     bl_label = "Cameras"
 
@@ -1723,6 +1734,7 @@ class VIEW3D_MT_object_specials(Menu):
     def draw(self, context):
 
         layout = self.layout
+        view = context.space_data
 
         obj = context.object
         is_eevee = context.scene.render.engine == 'BLENDER_EEVEE'
@@ -1762,7 +1774,6 @@ class VIEW3D_MT_object_specials(Menu):
                 props.header_text = "Camera Lens Scale: %.3f"
 
             if not obj.data.dof_object:
-                view = context.space_data
                 if view and view.camera == obj and view.region_3d.view_perspective == 'CAMERA':
                     props = layout.operator("ui.eyedropper_depth", text="DOF Distance (Pick)")
                 else:
@@ -1771,7 +1782,6 @@ class VIEW3D_MT_object_specials(Menu):
                     props.data_path_item = "data.dof_distance"
                     props.input_scale = 0.02
                     props.header_text = "DOF Distance: %.3f"
-                del view
 
         if obj.type in {'CURVE', 'FONT'}:
             layout.operator_context = 'INVOKE_REGION_WIN'
@@ -1874,7 +1884,11 @@ class VIEW3D_MT_object_specials(Menu):
         layout.menu("VIEW3D_MT_snap")
         layout.menu("VIEW3D_MT_object_parent")
         layout.operator_context = 'INVOKE_REGION_WIN'
-        layout.operator("object.move_to_collection")
+
+        if view and view.local_view:
+            layout.operator("view3d.localview_remove_from")
+        else:
+            layout.operator("object.move_to_collection")
 
         layout.separator()
 
@@ -5419,6 +5433,7 @@ classes = (
     VIEW3D_MT_uv_map,
     VIEW3D_MT_edit_proportional,
     VIEW3D_MT_view,
+    VIEW3D_MT_view_local,
     VIEW3D_MT_view_cameras,
     VIEW3D_MT_view_navigation,
     VIEW3D_MT_view_align,
index 5852fcff7e933be7534996df7d0c4a51eef62367..2723198b27974b0759ac60bd6bdabefacefb5486 100644 (file)
@@ -1834,6 +1834,12 @@ static bool move_to_collection_poll(bContext *C)
                return ED_outliner_collections_editor_poll(C);
        }
        else {
+               View3D *v3d = CTX_wm_view3d(C);
+
+               if (v3d && v3d->localvd) {
+                       return false;
+               }
+
                return ED_operator_object_active_editable(C);
        }
 }
index 9f77f671a7dd103476d2b907cbafdfda41cc903e..164c444d9a53574a4179eae4dc55f21ca80f3a34 100644 (file)
@@ -177,6 +177,7 @@ void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot);
 void VIEW3D_OT_camera_to_view_selected(struct wmOperatorType *ot);
 void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot);
 void VIEW3D_OT_localview(struct wmOperatorType *ot);
+void VIEW3D_OT_localview_remove_from(struct wmOperatorType *ot);
 
 bool ED_view3d_boundbox_clip_ex(const RegionView3D *rv3d, const struct BoundBox *bb, float obmat[4][4]);
 bool ED_view3d_boundbox_clip(RegionView3D *rv3d, const struct BoundBox *bb);
index 8092dc9f0f78d0a139a25e7f9740250c20239c22..7e4f04feaef4255cff7866e166f09c4421a38068 100644 (file)
@@ -205,6 +205,7 @@ void view3d_operatortypes(void)
        WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
        WM_operatortype_append(VIEW3D_OT_object_as_camera);
        WM_operatortype_append(VIEW3D_OT_localview);
+       WM_operatortype_append(VIEW3D_OT_localview_remove_from);
        WM_operatortype_append(VIEW3D_OT_fly);
        WM_operatortype_append(VIEW3D_OT_walk);
        WM_operatortype_append(VIEW3D_OT_navigate);
index 059274a14fde4bfe38c5c2edf3320655a978b1a4..98ae57e9c426614aaee5460d8a162840e06b9ebf 100644 (file)
@@ -1412,6 +1412,63 @@ void VIEW3D_OT_localview(wmOperatorType *ot)
        ot->poll = ED_operator_view3d_active;
 }
 
+static int localview_remove_from_exec(bContext *C, wmOperator *op)
+{
+       View3D *v3d = CTX_wm_view3d(C);
+       Main *bmain = CTX_data_main(C);
+       Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       bool changed = false;
+
+       for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
+               if (TESTBASE(v3d, base)) {
+                       base->local_view_bits &= ~v3d->local_view_uuid;
+                       ED_object_base_select(base, BA_DESELECT);
+
+                       if (base == BASACT(view_layer)) {
+                               view_layer->basact = NULL;
+                       }
+                       changed = true;
+               }
+       }
+
+       if (changed) {
+               DEG_on_visible_update(bmain, false);
+               DEG_id_tag_update(&scene->id, DEG_TAG_SELECT_UPDATE);
+               WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
+               WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
+               return OPERATOR_FINISHED;
+       }
+       else {
+               BKE_report(op->reports, RPT_ERROR, "No object selected");
+               return OPERATOR_CANCELLED;
+       }
+}
+
+static bool localview_remove_from_poll(bContext *C)
+{
+       if (CTX_data_edit_object(C) != NULL) {
+               return false;
+       }
+
+       View3D *v3d = CTX_wm_view3d(C);
+       return v3d && v3d->localvd;
+}
+
+void VIEW3D_OT_localview_remove_from(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Remove from Local View";
+       ot->description = "Move selected objects out of local view";
+       ot->idname = "VIEW3D_OT_localview_remove_from";
+
+       /* api callbacks */
+       ot->exec = localview_remove_from_exec;
+       ot->invoke = WM_operator_confirm;
+       ot->poll = localview_remove_from_poll;
+       ot->flag = OPTYPE_UNDO;
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */