|
39 | 39 | OBJECT_OT_copy_without_keyframes, |
40 | 40 | ) |
41 | 41 |
|
42 | | -from .operators.text_editor_import import ( |
43 | | - ImportFromTextEditorAsCurveOperator, |
44 | | - ImportFromTextEditorAsMeshOperator, |
45 | | - ImportFromTextEditorAsUnfilledCurveOperator, |
| 42 | +from .operators.textbox_import import ( |
| 43 | + ImportFromTextboxAsCurveOperator, |
| 44 | + ImportFromTextboxAsMeshOperator, |
| 45 | + ImportFromTextboxAsUnfilledCurveOperator, |
46 | 46 | ) |
47 | 47 |
|
48 | 48 | from .operators.export_svg import ( |
|
55 | 55 | addon_keymaps = [] |
56 | 56 |
|
57 | 57 |
|
58 | | -# Property to store selected text editor document |
59 | | -bpy.types.WindowManager.typst_selected_text = bpy.props.StringProperty( |
60 | | - name="Selected Text", |
61 | | - description="Selected text document from Blender's text editor", |
| 58 | +# Property to store the Typst content entered in the textbox |
| 59 | +bpy.types.Scene.typst_text = bpy.props.StringProperty( |
| 60 | + name="Typst Text", |
| 61 | + description="Typst content to import", |
62 | 62 | default="", |
63 | 63 | ) |
64 | 64 |
|
|
85 | 85 | ) |
86 | 86 |
|
87 | 87 |
|
88 | | -# Panel for text editor import |
89 | | -class VIEW3D_PT_typst_text_editor_import(bpy.types.Panel): |
| 88 | +# Panel for textbox import |
| 89 | +class VIEW3D_PT_typst_textbox_import(bpy.types.Panel): |
90 | 90 | bl_space_type = "VIEW_3D" |
91 | 91 | bl_region_type = "UI" |
92 | 92 | bl_category = "Typst Tools" |
93 | | - bl_label = "Text Editor Import" |
| 93 | + bl_label = "Typst Input" |
94 | 94 |
|
95 | 95 | def draw(self, context): |
96 | 96 | layout = self.layout |
97 | 97 | wm = context.window_manager |
98 | | - |
99 | | - # Get available text documents |
100 | | - text_docs = list(bpy.data.texts.keys()) |
101 | | - |
102 | | - if not text_docs: |
103 | | - layout.label(text="No text documents found", icon="INFO") |
104 | | - layout.label(text="Create one in the Text Editor") |
105 | | - return |
106 | | - |
107 | | - # Text document selector |
| 98 | + scene = context.scene |
| 99 | + |
| 100 | + # Multi-line textbox for Typst content |
108 | 101 | box = layout.box() |
109 | | - box.label(text="Select Text Document") |
110 | | - box.prop_search( |
111 | | - wm, |
112 | | - "typst_selected_text", |
113 | | - bpy.data, |
114 | | - "texts", |
115 | | - text="Document", |
116 | | - icon="TEXT", |
117 | | - ) |
118 | | - |
119 | | - # Show selected text name or placeholder |
120 | | - selected_text = wm.typst_selected_text |
121 | | - if not selected_text: |
122 | | - box.label(text="No document selected", icon="INFO") |
123 | | - else: |
124 | | - box.label(text=f"Selected: {selected_text}", icon="FILE_TEXT") |
125 | | - |
| 102 | + box.label(text="Typst Content") |
| 103 | + box.textbox(scene, "typst_text") |
| 104 | + |
126 | 105 | # Import options |
127 | 106 | box = layout.box() |
128 | 107 | box.label(text="Import Options") |
129 | | - |
| 108 | + |
130 | 109 | # Origin to character option |
131 | 110 | box.prop(wm, "typst_origin_to_char", text="Origin to Character") |
132 | | - |
| 111 | + |
133 | 112 | # Custom header option |
134 | 113 | box.prop(wm, "typst_use_custom_header", text="Use Custom Header") |
135 | | - |
136 | | - # Disable buttons if no text is selected |
| 114 | + |
| 115 | + # Disable buttons if the textbox is empty |
| 116 | + has_content = bool(scene.typst_text.strip()) |
137 | 117 | row = box.row() |
138 | | - op = row.operator( |
139 | | - ImportFromTextEditorAsUnfilledCurveOperator.bl_idname, |
| 118 | + row.operator( |
| 119 | + ImportFromTextboxAsUnfilledCurveOperator.bl_idname, |
140 | 120 | text="Import as Unfilled Curve", |
141 | 121 | icon="CURVE_BEZCURVE", |
142 | 122 | ) |
143 | | - op.text_name = selected_text |
144 | | - row.enabled = bool(selected_text) |
145 | | - |
| 123 | + row.enabled = has_content |
| 124 | + |
146 | 125 | row = box.row() |
147 | | - op = row.operator( |
148 | | - ImportFromTextEditorAsCurveOperator.bl_idname, |
| 126 | + row.operator( |
| 127 | + ImportFromTextboxAsCurveOperator.bl_idname, |
149 | 128 | text="Import as Curve", |
150 | 129 | icon="CURVE_DATA", |
151 | 130 | ) |
152 | | - op.text_name = selected_text |
153 | | - row.enabled = bool(selected_text) |
154 | | - |
| 131 | + row.enabled = has_content |
| 132 | + |
155 | 133 | row = box.row() |
156 | | - op = row.operator( |
157 | | - ImportFromTextEditorAsMeshOperator.bl_idname, |
| 134 | + row.operator( |
| 135 | + ImportFromTextboxAsMeshOperator.bl_idname, |
158 | 136 | text="Import as Mesh", |
159 | 137 | icon="MESH_DATA", |
160 | 138 | ) |
161 | | - op.text_name = selected_text |
162 | | - row.enabled = bool(selected_text) |
| 139 | + row.enabled = has_content |
163 | 140 |
|
164 | 141 |
|
165 | 142 | # Panel for the N-panel sidebar |
@@ -305,10 +282,10 @@ def register(): |
305 | 282 | bpy.utils.register_class(VIEW3D_PT_typst_animation_tools) |
306 | 283 | bpy.utils.register_class(OBJECT_OT_join_to_plane) |
307 | 284 | bpy.utils.register_class(OBJECT_OT_copy_to_plane) |
308 | | - bpy.utils.register_class(ImportFromTextEditorAsCurveOperator) |
309 | | - bpy.utils.register_class(ImportFromTextEditorAsMeshOperator) |
310 | | - bpy.utils.register_class(ImportFromTextEditorAsUnfilledCurveOperator) |
311 | | - bpy.utils.register_class(VIEW3D_PT_typst_text_editor_import) |
| 285 | + bpy.utils.register_class(ImportFromTextboxAsCurveOperator) |
| 286 | + bpy.utils.register_class(ImportFromTextboxAsMeshOperator) |
| 287 | + bpy.utils.register_class(ImportFromTextboxAsUnfilledCurveOperator) |
| 288 | + bpy.utils.register_class(VIEW3D_PT_typst_textbox_import) |
312 | 289 | bpy.utils.register_class(ExportTypstSvgOperator) |
313 | 290 | bpy.utils.register_class(VIEW3D_PT_typst_export) |
314 | 291 |
|
@@ -339,10 +316,10 @@ def unregister(): |
339 | 316 | # Unregister Blender classes in reverse order |
340 | 317 | bpy.utils.unregister_class(VIEW3D_PT_typst_export) |
341 | 318 | bpy.utils.unregister_class(ExportTypstSvgOperator) |
342 | | - bpy.utils.unregister_class(VIEW3D_PT_typst_text_editor_import) |
343 | | - bpy.utils.unregister_class(ImportFromTextEditorAsUnfilledCurveOperator) |
344 | | - bpy.utils.unregister_class(ImportFromTextEditorAsMeshOperator) |
345 | | - bpy.utils.unregister_class(ImportFromTextEditorAsCurveOperator) |
| 319 | + bpy.utils.unregister_class(VIEW3D_PT_typst_textbox_import) |
| 320 | + bpy.utils.unregister_class(ImportFromTextboxAsUnfilledCurveOperator) |
| 321 | + bpy.utils.unregister_class(ImportFromTextboxAsMeshOperator) |
| 322 | + bpy.utils.unregister_class(ImportFromTextboxAsCurveOperator) |
346 | 323 | bpy.utils.unregister_class(OBJECT_OT_copy_to_plane) |
347 | 324 | bpy.utils.unregister_class(OBJECT_OT_join_to_plane) |
348 | 325 | bpy.utils.unregister_class(VIEW3D_PT_typst_animation_tools) |
|
0 commit comments