From f583ecf0ad14d969c8b53f8a4234c1b5df9a0703 Mon Sep 17 00:00:00 2001 From: Ryan Inch Date: Sun, 29 Aug 2021 22:15:39 -0400 Subject: Collection Manager: Improve UI for adding QCD slots. Task: T69577 Replace the X labels in the QCD header widget with operators that generate the corresponding slot when clicked, allows for moving objects to the new slot by pressing hotkeys when clicking. Each unassigned slot operator has a tooltip specifying it's an unassigned slot, which slot number it corresponds to, and lists the hotkeys that can be used with it and their functions. Adds a menu item to the QVT menu (the eye icon beside the QCD header widget) to add any missing QCD slots so that you end up with a full 20 slots. --- object_collection_manager/__init__.py | 2 +- object_collection_manager/qcd_init.py | 2 + object_collection_manager/qcd_operators.py | 64 ++++++++++++++++++++++++++++++ object_collection_manager/ui.py | 7 +++- 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py index 3936d11b..aa9211d6 100644 --- a/object_collection_manager/__init__.py +++ b/object_collection_manager/__init__.py @@ -22,7 +22,7 @@ bl_info = { "name": "Collection Manager", "description": "Manage collections and their objects", "author": "Ryan Inch", - "version": (2, 22, 3), + "version": (2, 23, 0), "blender": (2, 80, 0), "location": "View3D - Object Mode (Shortcut - M)", "warning": '', # used for warning icon and text in addons panel diff --git a/object_collection_manager/qcd_init.py b/object_collection_manager/qcd_init.py index 49951da3..ed235a63 100644 --- a/object_collection_manager/qcd_init.py +++ b/object_collection_manager/qcd_init.py @@ -59,6 +59,8 @@ qcd_classes = ( qcd_operators.MoveToQCDSlot, qcd_operators.ViewQCDSlot, qcd_operators.ViewMoveQCDSlot, + qcd_operators.UnassignedQCDSlot, + qcd_operators.CreateAllQCDSlots, qcd_operators.RenumerateQCDSlots, ui.EnableAllQCDSlotsMenu, ) diff --git a/object_collection_manager/qcd_operators.py b/object_collection_manager/qcd_operators.py index 5f465eb5..0fdf1045 100644 --- a/object_collection_manager/qcd_operators.py +++ b/object_collection_manager/qcd_operators.py @@ -759,6 +759,70 @@ class ViewQCDSlot(Operator): return {'FINISHED'} +class UnassignedQCDSlot(Operator): + bl_label = "" + bl_idname = "view3d.unassigned_qcd_slot" + bl_options = {'REGISTER', 'UNDO'} + + slot: StringProperty() + + @classmethod + def description(cls, context, properties): + slot_string = f"Unassigned QCD Slot {properties.slot}:\n" + + hotkey_string = ( + " * LMB - Create slot.\n" + " * Shift+LMB - Create and isolate slot.\n" + " * Ctrl+LMB - Create and move objects to slot.\n" + " * Ctrl+Shift+LMB - Create and add objects to slot" + ) + + return f"{slot_string}{hotkey_string}" + + def invoke(self, context, event): + modifiers = get_modifiers(event) + + new_collection = bpy.data.collections.new(f"Collection {self.slot}") + context.scene.collection.children.link(new_collection) + internals.qcd_slots.add_slot(f"{self.slot}", new_collection.name) + + # update tree view property + update_property_group(context) + + if modifiers == {"shift"}: + bpy.ops.view3d.view_qcd_slot(slot=self.slot, toggle=False) + + elif modifiers == {"ctrl"}: + bpy.ops.view3d.move_to_qcd_slot(slot=self.slot, toggle=False) + + elif modifiers == {"ctrl", "shift"}: + bpy.ops.view3d.move_to_qcd_slot(slot=self.slot, toggle=True) + + else: + pass + + return {'FINISHED'} + + +class CreateAllQCDSlots(Operator): + bl_label = "Create All QCD Slots" + bl_description = "Create any missing QCD slots so you have a full 20" + bl_idname = "view3d.create_all_qcd_slots" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, context): + for slot_number in range(1, 21): + if not internals.qcd_slots.get_name(f"{slot_number}"): + new_collection = bpy.data.collections.new(f"Collection {slot_number}") + context.scene.collection.children.link(new_collection) + internals.qcd_slots.add_slot(f"{slot_number}", new_collection.name) + + # update tree view property + update_property_group(context) + + return {'FINISHED'} + + class RenumerateQCDSlots(Operator): bl_label = "Renumber QCD Slots" bl_description = ( diff --git a/object_collection_manager/ui.py b/object_collection_manager/ui.py index b7bc1b32..ec2c7354 100644 --- a/object_collection_manager/ui.py +++ b/object_collection_manager/ui.py @@ -1016,6 +1016,10 @@ class EnableAllQCDSlotsMenu(Menu): def draw(self, context): layout = self.layout + layout.operator("view3d.create_all_qcd_slots") + + layout.separator() + layout.operator("view3d.enable_all_qcd_slots") layout.operator("view3d.enable_all_qcd_slots_isolated") @@ -1100,7 +1104,8 @@ def view3d_header_qcd_slots(self, context): prop.slot = str(x+1) else: - row.label(text="", icon='X') + prop = row.operator("view3d.unassigned_qcd_slot", text="", icon='X', emboss=False) + prop.slot = str(x+1) if idx%5==0: -- cgit v1.2.3