Skip to content

Commit

Permalink
Feature #50 : Option to filter tags by name when removing all
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorgious56 committed Jun 5, 2022
1 parent 0ffa9d7 commit 15e2f5c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
19 changes: 16 additions & 3 deletions tag/operator/remove.py
@@ -1,4 +1,5 @@
from asset_browser_utilities.core.log.logger import Logger
from asset_browser_utilities.filter.name import FilterName
from bpy.types import Operator
from bpy.props import PointerProperty

Expand All @@ -10,6 +11,9 @@ class BatchExecuteOverride(BatchExecute):
def __init__(self, operator, context):
self.tags = [t.name for t in operator.operator_settings.tag_collection.items if not t.is_empty()]
self.remove_all = operator.operator_settings.tag_collection.remove_all
self.filter_name_allow = operator.operator_settings.filter_name.active
self.filter_name_method = operator.operator_settings.filter_name.method
self.filter_name_text = operator.operator_settings.filter_name.value
super().__init__(operator, context)

def do_on_asset(self, asset):
Expand All @@ -21,8 +25,18 @@ def do_on_asset(self, asset):

def execute_tags(self, asset_tags):
if self.remove_all:
while asset_tags:
asset_tags.remove(asset_tags[0])
if self.filter_name_allow:
self.remove_tags(
asset_tags,
[
t.name
for t in asset_tags
if FilterName.filter_static(t.name, self.filter_name_method, self.filter_name_text)
],
)
else:
while asset_tags:
asset_tags.remove(asset_tags[0])
else:
self.remove_tags(asset_tags, self.tags)

Expand All @@ -32,7 +46,6 @@ def remove_tags(self, asset_tags, tags_to_remove):
asset_tags.remove(asset_tags[i])



class ASSET_OT_batch_remove_tags(Operator, BatchFolderOperator):
"Remove tags"
bl_idname = "asset.batch_remove_tags"
Expand Down
7 changes: 6 additions & 1 deletion tag/operator/tool.py
Expand Up @@ -2,15 +2,20 @@
from bpy.props import PointerProperty

from asset_browser_utilities.tag.tag_collection import TagCollection
from asset_browser_utilities.filter.name import FilterName


class AddOrRemoveTagsOperatorProperties(PropertyGroup):
tag_collection: PointerProperty(type=TagCollection)
MAX_TAGS = 10
filter_name: PointerProperty(type=FilterName)

def init(self, add=True):
self.tag_collection.add = add
self.tag_collection.init(tags=self.MAX_TAGS)

def draw(self, layout):
self.tag_collection.draw(layout)
box = layout.box()
self.tag_collection.draw(box)
if self.tag_collection.remove_all:
self.filter_name.draw(box)
2 changes: 1 addition & 1 deletion tag/tag_collection.py
Expand Up @@ -39,7 +39,7 @@ def init(self, tags: int = 10):
self.items.add()

def draw(self, layout):
box = layout.box()
box = layout
row = box.row()
split = row.split(factor=0.2)
split.label(text="Tags")
Expand Down

0 comments on commit 15e2f5c

Please sign in to comment.