Deprecate LaunchAddElement, LaunchRenameType

TIL that it's possible to set invoke context from draw by changing operator_context property in UILayout 😅
This commit is contained in:
Andrej730
2025-03-12 17:05:16 +05:00
parent 6596f5bc4b
commit 63aada25dd
5 changed files with 5 additions and 34 deletions
+5 -3
View File
@@ -54,7 +54,8 @@ class BIM_MT_type_menu(bpy.types.Menu):
def draw(self, context): def draw(self, context):
props = tool.Model.get_model_props() props = tool.Model.get_model_props()
layout = self.layout layout = self.layout
op = layout.operator("bim.launch_rename_type", icon="GREASEPENCIL", text="Rename Type") layout.operator_context = "INVOKE_REGION_WIN"
op = layout.operator("bim.rename_type", icon="GREASEPENCIL", text="Rename Type")
op.element = props.menu_relating_type_id op.element = props.menu_relating_type_id
op = layout.operator("bim.select_type", icon="OBJECT_DATA") op = layout.operator("bim.select_type", icon="OBJECT_DATA")
op.relating_type = props.menu_relating_type_id op.relating_type = props.menu_relating_type_id
@@ -699,6 +700,7 @@ class BIM_PT_roof(bpy.types.Panel):
row.operator("bim.add_roof", icon="ADD", text="") row.operator("bim.add_roof", icon="ADD", text="")
def add_menu(self, context): def add_menu(self: bpy.types.Menu, context: bpy.types.Context) -> None:
self.layout.operator("bim.launch_add_element", icon_value=bonsai.bim.icons["IFC"].icon_id, text="IFC Element") self.layout.operator_context = "INVOKE_REGION_WIN"
self.layout.operator("bim.add_element", icon_value=bonsai.bim.icons["IFC"].icon_id, text="IFC Element")
self.layout.separator() self.layout.separator()
@@ -24,7 +24,6 @@ classes = (
operator.AssignClass, operator.AssignClass,
operator.DisableReassignClass, operator.DisableReassignClass,
operator.EnableReassignClass, operator.EnableReassignClass,
operator.LaunchAddElement,
operator.ReassignClass, operator.ReassignClass,
operator.UnlinkObject, operator.UnlinkObject,
prop.BIMRootProperties, prop.BIMRootProperties,
@@ -625,19 +625,3 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
row.prop(props, "profile", text="Profile") row.prop(props, "profile", text="Profile")
if props.representation_template != "EMPTY": if props.representation_template != "EMPTY":
prop_with_search(self.layout, props, "contexts", should_click_ok=True) prop_with_search(self.layout, props, "contexts", should_click_ok=True)
class LaunchAddElement(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.launch_add_element"
bl_label = "Launch Add Element"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Add an IFC physical product, construction type, and more"
@classmethod
def poll(cls, context):
return tool.Ifc.get()
def execute(self, context):
# This stub operator is needed because operators from menu skip the invoke call
bpy.ops.bim.add_element("INVOKE_DEFAULT")
return {"FINISHED"}
@@ -25,7 +25,6 @@ classes = (
operator.DisableEditingType, operator.DisableEditingType,
operator.DuplicateType, operator.DuplicateType,
operator.EnableEditingType, operator.EnableEditingType,
operator.LaunchRenameType,
operator.RemoveType, operator.RemoveType,
operator.RenameType, operator.RenameType,
operator.SelectSimilarType, operator.SelectSimilarType,
@@ -279,19 +279,6 @@ class RenameType(bpy.types.Operator, tool.Ifc.Operator):
self.layout.prop(self, "name") self.layout.prop(self, "name")
class LaunchRenameType(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.launch_rename_type"
bl_label = "Launch Rename Type"
bl_options = {"REGISTER", "UNDO"}
element: bpy.props.IntProperty()
name: bpy.props.StringProperty(name="Name")
def execute(self, context):
# This stub operator is needed because operators from menu skip the invoke call
bpy.ops.bim.rename_type("INVOKE_DEFAULT", element=self.element, name=self.name)
return {"FINISHED"}
class AutoRenameOccurrences(bpy.types.Operator): class AutoRenameOccurrences(bpy.types.Operator):
bl_idname = "bim.auto_rename_occurrences" bl_idname = "bim.auto_rename_occurrences"
bl_label = "Auto Rename Occurrences" bl_label = "Auto Rename Occurrences"