11import typing
22import bpy
3- from bpy .types import Operator , Context , Event , PropertyGroup
3+ from bpy .types import Operator , Context , Event , PropertyGroup , UILayout
44from bpy .props import StringProperty , EnumProperty , BoolProperty , CollectionProperty
55from bpy_extras .io_utils import ImportHelper , ExportHelper
66from . functions import get_preferences
@@ -423,7 +423,7 @@ def execute(self, context: Context):
423423 return {'CANCELLED' }
424424 functions .export (
425425 self .mode ,
426- map (lambda x : x .use , self .export_buttons ),
426+ filter (lambda x : x .use , self .export_buttons ),
427427 self .filepath
428428 )
429429 return {"FINISHED" }
@@ -493,27 +493,108 @@ class STB_OT_Edit(Operator):
493493 bl_description = "Edit the selected Button"
494494 bl_options = {"UNDO" }
495495
496+ area_items = [ # (identifier, name, description, icon, value)
497+ ('' , 'General' , '' , '' ),
498+ ('3D_Viewport' , '3D Viewport' , '' , 'VIEW3D' ),
499+ ('Image_Editor' , 'Image Editor' , '' , 'IMAGE' ),
500+ ('UV_Editor' , 'UV Editor' , '' , 'UV' ),
501+ ('Compositor' , 'Compositor' , '' , 'NODE_COMPOSITING' ),
502+ ('Texture_Node_Editor' , 'Texture Node Editor' , '' , 'NODE_TEXTURE' ),
503+ ('Geomerty_Node_Editor' , 'Geomerty Node Editor' , '' , 'NODETREE' ),
504+ ('Shader_Editor' , 'Shader Editor' , '' , 'NODE_MATERIAL' ),
505+ ('Video_Sequencer' , 'Video Sequencer' , '' , 'SEQUENCE' ),
506+ ('Movie_Clip_Editor' , 'Movie Clip Editor' , '' , 'TRACKER' ),
507+
508+ ('' , 'Animation' , '' , '' ),
509+ ('Dope_Sheet' , 'Dope Sheet' , '' , 'ACTION' ),
510+ ('Timeline' , 'Timeline' , '' , 'TIME' ),
511+ ('Graph_Editor' , 'Graph Editor' , '' , 'GRAPH' ),
512+ ('Drivers' , 'Drivers' , '' , 'DRIVER' ),
513+ ('Nonlinear_Animation' , 'Nonlinear Animation' , '' , 'NLA' ),
514+
515+ ('' , 'Scripting' , '' , '' ),
516+ ('Text_Editor' , 'Text Editor' , '' , 'TEXT' )
517+ ]
518+
496519 name : StringProperty (name = "Name" )
497520 stb_properties : CollectionProperty (type = properties .STB_edit_property_item )
498521
522+ def items_stb_select_area (self , context : Context ):
523+ for item in self .stb_areas :
524+ if item .delete :
525+ self .stb_areas .remove (self .stb_areas .find (item .name ))
526+ used_areas = set (area .name for area in self .stb_areas )
527+ areas = []
528+ for i , (identifier , name , description , icon ) in enumerate (STB_OT_Edit .area_items ):
529+ if identifier in used_areas :
530+ continue
531+ areas .append ((
532+ identifier ,
533+ name ,
534+ description ,
535+ icon ,
536+ i * (identifier != '' ) - 1
537+ ))
538+ return areas
539+ stb_select_area : EnumProperty (items = items_stb_select_area , default = 0 )
540+ stb_areas : CollectionProperty (type = properties .STB_edit_area_item )
541+
542+ def get_add_area (self ):
543+ return False
544+
545+ def set_add_area (self , value ):
546+ identifier = self .stb_select_area
547+ icon = UILayout .enum_item_icon (self , 'stb_select_area' , identifier )
548+ label = UILayout .enum_item_name (self , 'stb_select_area' , identifier )
549+ if identifier == '' :
550+ return
551+ new = self .stb_areas .add ()
552+ new .name = identifier
553+ new .label = label
554+ new .icon = icon
555+ items = STB_OT_Edit .items_stb_select_area (self , bpy .context )
556+ for item in items :
557+ if item [0 ] == '' :
558+ continue
559+ self .stb_select_area = item [0 ]
560+ break
561+ add_area : BoolProperty (default = False , get = get_add_area , set = set_add_area )
562+
499563 def draw (self , context : Context ):
500564 layout = self .layout
501565 layout .prop (self , 'name' )
502566
503567 layout .separator (factor = 0.5 )
504- layout .label (text = "Properties" )
568+ layout .label (text = "Areas" )
569+ row = layout .row (align = True )
570+ row .prop (self , 'stb_select_area' )
571+ row .prop (self , 'add_area' , icon = "ADD" , icon_only = True )
505572 box = layout .box ()
506- for prop in filter (lambda x : not x .use_delete , self .stb_properties ):
507- row = box .row ()
508- row .label (text = f"{ prop .name } [Ln { prop .line } ]" )
509- row .prop (prop , 'use_delete' , icon = 'X' , icon_only = True , emboss = False )
573+ if len (self .stb_areas ):
574+ for area in filter (lambda x : not x .delete , self .stb_areas ):
575+ row = box .row ()
576+ row .label (text = area .label , icon_value = area .icon )
577+ row .prop (area , 'delete' , icon = 'X' , icon_only = True , emboss = False )
578+ else :
579+ box .label (text = "All Areas" , icon = 'RESTRICT_COLOR_ON' )
580+
581+ properties = list (filter (lambda x : not x .use_delete , self .stb_properties ))
582+ if len (properties ):
583+ layout .separator (factor = 0.5 )
584+ layout .label (text = "Properties" )
585+ box = layout .box ()
586+ for prop in properties :
587+ row = box .row ()
588+ row .label (text = f"{ prop .name } [Ln { prop .line } ]" )
589+ row .prop (prop , 'use_delete' , icon = 'X' , icon_only = True , emboss = False )
510590
511591 def invoke (self , context , event ):
512592 STB_pref = get_preferences (context )
513593 stb = context .scene .stb
514594 button = stb [STB_pref .selected_button ]
515595 self .name = button .name
516596 self .stb_properties .clear ()
597+ self .stb_areas .clear ()
517598 for prop in functions .get_all_properties (button ):
518599 new = self .stb_properties .add ()
519600 new .name = prop .name
@@ -525,9 +606,7 @@ def execute(self, context):
525606 functions .rename (context , self .name )
526607
527608 STB_pref = get_preferences (context )
528- stb = context .scene .stb
529609 property_changed = False
530- button = stb [STB_pref .selected_button ]
531610
532611 text_index = bpy .data .texts .find (STB_pref .selected_button )
533612 if text_index == - 1 :
@@ -537,22 +616,35 @@ def execute(self, context):
537616 text = bpy .data .texts [text_index ]
538617 lines = [line .body for line in text .lines ]
539618
619+ if len (self .stb_areas ):
620+ property_changed = True
621+ if lines [0 ].strip ().startswith ("#STB" ):
622+ line = lines [0 ]
623+ line += " /// "
624+ else :
625+ line = ""
626+ lines .insert (0 , line )
627+ line += " /// " .join (map (lambda x : "#STB-Area-%s" % x .name , self .stb_areas ))
628+ lines [0 ] = line
629+
630+ edited_lines = []
540631 for prop in filter (lambda x : x .use_delete , self .stb_properties ):
541632 property_changed = True
542633 line : str = lines [prop .line - 1 ]
543634 line_start = line .find ("#STB" )
544635 if line_start == - 1 :
545636 continue
546-
637+
547638 if (init_start_position := line .find ("#STB-InitValue-" )) != - 1 :
548639 init_start_position += len ("#STB-InitValue-" )
549640 init_end_position = line .find ("-END" , init_start_position )
550641 init_value = line [init_start_position : init_end_position ]
551- lines [prop .line ] = "%s= %s" % (prop .linename , init_value )
552-
642+ lines [prop .line ] = "%s= %s" % (prop .linename , init_value )
643+
553644 and_position = line .find ("///" , line_start )
554645 end_position = line .find ("#STB" , and_position )
555- while (and_next := line .find ("///" , end_position )) != - 1 and (end_next := line .find ("#STB" , and_next )) != - 1 :
646+ while ((and_next := line .find ("///" , end_position )) != - 1
647+ and (end_next := line .find ("#STB" , and_next )) != - 1 ):
556648 and_position = and_next
557649 end_position = end_next
558650
@@ -567,8 +659,12 @@ def execute(self, context):
567659 line = line [:line_start ] + line [line_end :]
568660
569661 lines [prop .line - 1 ] = line
662+ edited_lines .append (prop .line - 1 )
663+
664+ for i in sorted (edited_lines , reverse = True ):
665+ line = lines [i ]
570666 if line .strip () == "" :
571- lines .pop (prop . line - 1 )
667+ lines .pop (i )
572668
573669 if property_changed :
574670 text .clear ()
0 commit comments