BlenderKit: fix poll of Fast metadata edit and rating operators
previous fix broke other use cases (in panels and in BGL element)
This commit is contained in:
parent
08e9ab150d
commit
414f63669f
|
@ -426,7 +426,7 @@ class FastRateMenu(Operator):
|
|||
def poll(cls, context):
|
||||
scene = bpy.context.scene
|
||||
ui_props = scene.blenderkitUI
|
||||
return ui_props.active_index > -1
|
||||
return True;
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
@ -500,6 +500,8 @@ class FastRateMenu(Operator):
|
|||
self.asset_id = asset_data['id']
|
||||
self.asset_type = asset_data['assetType']
|
||||
|
||||
if self.asset_id == '':
|
||||
return {'CANCELLED'}
|
||||
self.message = f"Rate asset {self.asset_name}"
|
||||
wm = context.window_manager
|
||||
|
||||
|
|
|
@ -1285,6 +1285,7 @@ def draw_asset_context_menu(layout, context, asset_data, from_panel=False):
|
|||
row.operator_context = 'INVOKE_DEFAULT'
|
||||
op = layout.operator('wm.blenderkit_fast_metadata', text='Fast Edit Metadata')
|
||||
op.asset_id = asset_data['id']
|
||||
op.asset_type = asset_data['assetType']
|
||||
|
||||
if author_id == str(profile['user']['id']):
|
||||
row = layout.row()
|
||||
|
|
|
@ -596,6 +596,11 @@ class FastMetadata(bpy.types.Operator):
|
|||
description="Unique name of the asset (hidden)",
|
||||
default=""
|
||||
)
|
||||
asset_type: StringProperty(
|
||||
name="Asset Type",
|
||||
description="Asset Type",
|
||||
default=""
|
||||
)
|
||||
name: StringProperty(
|
||||
name="Name",
|
||||
description="Main name of the asset",
|
||||
|
@ -658,7 +663,7 @@ class FastMetadata(bpy.types.Operator):
|
|||
def poll(cls, context):
|
||||
scene = bpy.context.scene
|
||||
ui_props = scene.blenderkitUI
|
||||
return can_edit_asset(active_index=ui_props.active_index)
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
@ -717,9 +722,9 @@ class FastMetadata(bpy.types.Operator):
|
|||
sr = bpy.context.window_manager['search results']
|
||||
asset_data = dict(sr[ui_props.active_index])
|
||||
else:
|
||||
for result in bpy.context.window_manager['search results']:
|
||||
if result['id'] == self.asset_id:
|
||||
asset_data = dict(result)
|
||||
|
||||
active_asset = utils.get_active_asset_by_type(asset_type = self.asset_type)
|
||||
asset_data = active_asset.get('asset_data')
|
||||
|
||||
if not can_edit_asset(asset_data=asset_data):
|
||||
return {'CANCELLED'}
|
||||
|
|
|
@ -181,6 +181,27 @@ def get_search_props():
|
|||
return props
|
||||
|
||||
|
||||
def get_active_asset_by_type(asset_type = 'model'):
|
||||
asset_type =asset_type.lower()
|
||||
if asset_type == 'model':
|
||||
if bpy.context.view_layer.objects.active is not None:
|
||||
ob = get_active_model()
|
||||
return ob
|
||||
if asset_type == 'scene':
|
||||
return bpy.context.scene
|
||||
if asset_type == 'hdr':
|
||||
return get_active_HDR()
|
||||
if asset_type == 'material':
|
||||
if bpy.context.view_layer.objects.active is not None and bpy.context.active_object.active_material is not None:
|
||||
return bpy.context.active_object.active_material
|
||||
if asset_type == 'texture':
|
||||
return None
|
||||
if asset_type == 'brush':
|
||||
b = get_active_brush()
|
||||
if b is not None:
|
||||
return b
|
||||
return None
|
||||
|
||||
def get_active_asset():
|
||||
scene = bpy.context.scene
|
||||
ui_props = scene.blenderkitUI
|
||||
|
|
Loading…
Reference in New Issue