[feat] add confirm window for some dangerous opers

- add clear oper in Virtools group panel.
- add confirm window for clear Virtools groups opers. both panel and context menu.
This commit is contained in:
yyc12345 2023-01-28 11:15:41 +08:00
parent 5fe865c621
commit b58f837a94
3 changed files with 29 additions and 3 deletions

View File

@ -169,11 +169,14 @@ class BALLANCE_OT_ctx_clear_group(bpy.types.Operator):
def poll(self, context): def poll(self, context):
return len(bpy.context.selected_objects) != 0 return len(bpy.context.selected_objects) != 0
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_confirm(self, event)
def execute(self, context): def execute(self, context):
# iterate object # iterate object
for obj in bpy.context.selected_objects: for obj in bpy.context.selected_objects:
UTILS_virtools_prop.clear_virtools_group_data(obj) UTILS_virtools_prop.clear_virtools_group_data(obj)
return {'FINISHED'} return {'FINISHED'}

View File

@ -44,9 +44,29 @@ class BALLANCE_OT_rm_virtools_group(bpy.types.Operator):
UTILS_virtools_prop.remove_virtools_group_data_by_index(obj, int(UTILS_virtools_prop.get_active_virtools_group(obj))) UTILS_virtools_prop.remove_virtools_group_data_by_index(obj, int(UTILS_virtools_prop.get_active_virtools_group(obj)))
return {'FINISHED'} return {'FINISHED'}
class BALLANCE_OT_clear_virtools_group(bpy.types.Operator):
"""Clear All Virtools Group for Active Object."""
bl_idname = "ballance.clear_virtools_group"
bl_label = "Clear Virtools Group"
bl_options = {'UNDO'}
@classmethod
def poll(self, context):
return context.object is not None
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_confirm(self, event)
def execute(self, context):
obj = context.object
UTILS_virtools_prop.clear_virtools_group_data(obj)
return {'FINISHED'}
class BALLANCE_UL_virtools_group(bpy.types.UIList): class BALLANCE_UL_virtools_group(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname): def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
layout.prop(item, 'group_name', icon='GROUP', emboss=False, text="") layout.label(text=item.group_name, translate=False, icon='GROUP')
#layout.prop(item, 'group_name', icon='GROUP', emboss=False, text="")
class BALLANCE_PT_virtools_group(bpy.types.Panel): class BALLANCE_PT_virtools_group(bpy.types.Panel):
"""Show Virtools Group Properties.""" """Show Virtools Group Properties."""
@ -71,3 +91,5 @@ class BALLANCE_PT_virtools_group(bpy.types.Panel):
col = row.column(align=True) col = row.column(align=True)
col.operator(BALLANCE_OT_add_virtools_group.bl_idname, icon='ADD', text="") col.operator(BALLANCE_OT_add_virtools_group.bl_idname, icon='ADD', text="")
col.operator(BALLANCE_OT_rm_virtools_group.bl_idname, icon='REMOVE', text="") col.operator(BALLANCE_OT_rm_virtools_group.bl_idname, icon='REMOVE', text="")
col.separator()
col.operator(BALLANCE_OT_clear_virtools_group.bl_idname, icon='TRASH', text="")

View File

@ -150,6 +150,7 @@ classes = (
UTILS_virtools_prop.BALLANCE_PG_virtools_group, UTILS_virtools_prop.BALLANCE_PG_virtools_group,
PROPS_virtools_group.BALLANCE_OT_add_virtools_group, PROPS_virtools_group.BALLANCE_OT_add_virtools_group,
PROPS_virtools_group.BALLANCE_OT_rm_virtools_group, PROPS_virtools_group.BALLANCE_OT_rm_virtools_group,
PROPS_virtools_group.BALLANCE_OT_clear_virtools_group,
PROPS_virtools_group.BALLANCE_UL_virtools_group, PROPS_virtools_group.BALLANCE_UL_virtools_group,
PROPS_virtools_group.BALLANCE_PT_virtools_group, PROPS_virtools_group.BALLANCE_PT_virtools_group,
PROPS_virtools_material.BALLANCE_OT_apply_virtools_material, PROPS_virtools_material.BALLANCE_OT_apply_virtools_material,