@@ -45,8 +45,11 @@ def get_description(self):
4545 else :
4646 STB_pref = get_preferences (bpy .context )
4747 text_name = STB_pref .texts_list
48- text = bpy .data .texts [text_name ].as_string () # Get selected Text
49- return functions .get_description (text )
48+ if bpy .data .texts .find (text_name ) != - 1 :
49+ text = bpy .data .texts [text_name ].as_string () # Get selected Text
50+ return functions .get_description (text )
51+ else :
52+ return ""
5053 return value
5154
5255 description : StringProperty (
@@ -110,6 +113,7 @@ def execute(self, context: Context) -> set[str]:
110113 elif STB_pref .texts_list == "" :
111114 self .report ({"ERROR" }, "You need to select a Text" )
112115 return {"FINISHED" }
116+
113117 fails = functions .add_button (context , self .name , txt , self .description )
114118 if len (fails [0 ]) or len (fails [1 ]):
115119 self .report (
@@ -684,7 +688,6 @@ def execute(self, context):
684688
685689 STB_pref = get_preferences (context )
686690 button : STB_button_properties = context .scene .stb [STB_pref .selected_button ]
687- property_changed = False
688691
689692 text_index = bpy .data .texts .find (STB_pref .selected_button )
690693 if text_index == - 1 :
@@ -693,35 +696,28 @@ def execute(self, context):
693696 else :
694697 text = bpy .data .texts [text_index ]
695698 lines = [line .body for line in text .lines ]
699+ first_line = ""
696700
697701 if len (self .stb_areas ):
698- property_changed = True
699- if lines [0 ].strip ().startswith ("#STB" ):
700- line = ""
701- else :
702- line = ""
703- lines .insert (0 , line )
704- line += " /// " .join (map (lambda x : "#STB-Area-%s" % x .name , self .stb_areas ))
705- lines [0 ] = line
706-
707- if button .description != self .description :
708- property_changed = True
709- button .description = self .description
710- escaped_description = self .description .replace ('"' , '\\ "' )
711- if lines [0 ].strip ().startswith ("#STB-Area" ):
712- line = lines [0 ]
713- line += " /// "
714- elif lines [0 ].strip ().startswith ("#STB-Tooltip" ):
715- line = ""
716- else :
717- line = ""
718- lines .insert (0 , line )
719- line += f'#STB-Tooltip-"{ escaped_description } "'
720- lines [0 ] = line
702+ if not (lines [0 ].strip () == "" or lines [0 ].strip ().startswith ("#STB" )):
703+ lines .insert (0 , first_line )
704+ first_line += " /// " .join (
705+ map (lambda x : "#STB-Area-%s" % x .name , self .stb_areas )
706+ )
707+
708+ button .description = self .description
709+ escaped_description = self .description .replace ('"' , '\\ "' )
710+ if first_line != "" :
711+ first_line += " /// "
712+ elif not (lines [0 ].strip () == "" or lines [0 ].strip ().startswith ("#STB" )):
713+ lines .insert (0 , first_line )
714+ first_line += f'#STB-Tooltip-"{ escaped_description } "'
715+
716+ if first_line != "" :
717+ lines [0 ] = first_line
721718
722719 edited_lines = []
723720 for prop in filter (lambda x : x .use_delete , self .stb_properties ):
724- property_changed = True
725721 line : str = lines [prop .line - 1 ]
726722 line_start = line .find ("#STB" )
727723 if line_start == - 1 :
@@ -759,10 +755,9 @@ def execute(self, context):
759755 if line .strip () == "" :
760756 lines .pop (i )
761757
762- if property_changed :
763- text .clear ()
764- text .write ("\n " .join (lines ))
765- bpy .ops .stb .reload ()
758+ text .clear ()
759+ text .write ("\n " .join (lines ))
760+ bpy .ops .stb .reload ()
766761 context .area .tag_redraw ()
767762 return {"FINISHED" }
768763
@@ -821,10 +816,12 @@ def text_properties_items(self, context):
821816 @classmethod
822817 def poll (cls , context : Context ):
823818 STB_pref = get_preferences (context )
824- area = context .area .ui_type
825- button = context .scene .stb [STB_pref .selected_button ]
826- is_visible = area in button .areas
827- return STB_pref .selected_button != "" and is_visible
819+ if STB_pref .selected_button != "" :
820+ button = context .scene .stb [STB_pref .selected_button ]
821+ area = context .area .ui_type
822+ is_visible = len (button .areas ) == 0 or area in button .areas
823+ return is_visible
824+ return False
828825
829826 def invoke (self , context : Context , event : Event ):
830827 STB_pref = get_preferences (context )
0 commit comments