fix [#26754] Live Edit and Editing UI scripts don't work
[blender.git] / release / scripts / startup / bl_ui / space_text.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22
23 class TEXT_HT_header(bpy.types.Header):
24     bl_space_type = 'TEXT_EDITOR'
25
26     def draw(self, context):
27         layout = self.layout
28
29         st = context.space_data
30         text = st.text
31
32         row = layout.row(align=True)
33         row.template_header()
34
35         if context.area.show_menus:
36             sub = row.row(align=True)
37             sub.menu("TEXT_MT_view")
38             sub.menu("TEXT_MT_text")
39             if text:
40                 sub.menu("TEXT_MT_edit")
41                 sub.menu("TEXT_MT_format")
42
43         if text and text.is_modified:
44             row = layout.row()
45             # row.color(redalert)
46             row.operator("text.resolve_conflict", text="", icon='HELP')
47
48         layout.template_ID(st, "text", new="text.new", unlink="text.unlink")
49
50         row = layout.row(align=True)
51         row.prop(st, "show_line_numbers", text="")
52         row.prop(st, "show_word_wrap", text="")
53         row.prop(st, "show_syntax_highlight", text="")
54
55         if text:
56             row = layout.row()
57             row.operator("text.run_script")
58
59             row = layout.row()
60             row.active = text.name.endswith(".py")
61             row.prop(text, "use_module")
62
63             row = layout.row()
64             if text.filepath:
65                 if text.is_dirty:
66                     row.label(text="File: *%s (unsaved)" % text.filepath)
67                 else:
68                     row.label(text="File: %s" % text.filepath)
69             else:
70                 row.label(text="Text: External" if text.library else "Text: Internal")
71
72
73 class TEXT_PT_properties(bpy.types.Panel):
74     bl_space_type = 'TEXT_EDITOR'
75     bl_region_type = 'UI'
76     bl_label = "Properties"
77
78     def draw(self, context):
79         layout = self.layout
80
81         st = context.space_data
82
83         flow = layout.column_flow()
84         flow.prop(st, "show_line_numbers")
85         flow.prop(st, "show_word_wrap")
86         flow.prop(st, "show_syntax_highlight")
87         flow.prop(st, "show_line_highlight")
88         flow.prop(st, "use_live_edit")
89
90         flow = layout.column_flow()
91         flow.prop(st, "font_size")
92         flow.prop(st, "tab_width")
93
94         text = st.text
95         if text:
96             flow.prop(text, "use_tabs_as_spaces")
97
98         flow.prop(st, "show_margin")
99         col = flow.column()
100         col.active = st.show_margin
101         col.prop(st, "margin_column")
102
103
104 class TEXT_PT_find(bpy.types.Panel):
105     bl_space_type = 'TEXT_EDITOR'
106     bl_region_type = 'UI'
107     bl_label = "Find"
108
109     def draw(self, context):
110         layout = self.layout
111
112         st = context.space_data
113
114         # find
115         col = layout.column(align=True)
116         row = col.row()
117         row.prop(st, "find_text", text="")
118         row.operator("text.find_set_selected", text="", icon='TEXT')
119         col.operator("text.find")
120
121         # replace
122         col = layout.column(align=True)
123         row = col.row()
124         row.prop(st, "replace_text", text="")
125         row.operator("text.replace_set_selected", text="", icon='TEXT')
126         col.operator("text.replace")
127
128         # mark
129         layout.operator("text.mark_all")
130
131         # settings
132         row = layout.row()
133         row.prop(st, "use_find_wrap", text="Wrap")
134         row.prop(st, "use_find_all", text="All")
135
136
137 class TEXT_MT_view(bpy.types.Menu):
138     bl_label = "View"
139
140     def draw(self, context):
141         layout = self.layout
142
143         layout.operator("text.properties", icon='MENU_PANEL')
144
145         layout.separator()
146
147         layout.operator("screen.area_dupli")
148         layout.operator("screen.screen_full_area")
149
150         layout.separator()
151
152         layout.operator("text.move", text="Top of File").type = 'FILE_TOP'
153         layout.operator("text.move", text="Bottom of File").type = 'FILE_BOTTOM'
154
155
156 class TEXT_MT_text(bpy.types.Menu):
157     bl_label = "Text"
158
159     def draw(self, context):
160         layout = self.layout
161
162         st = context.space_data
163         text = st.text
164
165         layout.column()
166         layout.operator("text.new")
167         layout.operator("text.open")
168
169         if text:
170             layout.operator("text.reload")
171
172             layout.column()
173             layout.operator("text.save")
174             layout.operator("text.save_as")
175
176             if text.filepath:
177                 layout.operator("text.make_internal")
178
179             layout.column()
180             layout.operator("text.run_script")
181
182             #ifdef WITH_PYTHON
183             # XXX if(BPY_is_pyconstraint(text))
184             # XXX   uiMenuItemO(head, 0, "text.refresh_pyconstraints");
185             #endif
186
187         layout.separator()
188
189         layout.menu("TEXT_MT_templates")
190
191
192 class TEXT_MT_templates(bpy.types.Menu):
193     '''
194     Creates the menu items by scanning scripts/templates
195     '''
196     bl_label = "Script Templates"
197
198     def draw(self, context):
199         self.path_menu(bpy.utils.script_paths("templates"), "text.open", {"internal": True})
200
201
202 class TEXT_MT_edit_select(bpy.types.Menu):
203     bl_label = "Select"
204
205     def draw(self, context):
206         layout = self.layout
207
208         layout.operator("text.select_all")
209         layout.operator("text.select_line")
210
211
212 class TEXT_MT_edit_markers(bpy.types.Menu):
213     bl_label = "Markers"
214
215     def draw(self, context):
216         layout = self.layout
217
218         layout.operator("text.markers_clear")
219         layout.operator("text.next_marker")
220         layout.operator("text.previous_marker")
221
222
223 class TEXT_MT_format(bpy.types.Menu):
224     bl_label = "Format"
225
226     def draw(self, context):
227         layout = self.layout
228
229         layout.operator("text.indent")
230         layout.operator("text.unindent")
231
232         layout.separator()
233
234         layout.operator("text.comment")
235         layout.operator("text.uncomment")
236
237         layout.separator()
238
239         layout.operator_menu_enum("text.convert_whitespace", "type")
240
241
242 class TEXT_MT_edit_to3d(bpy.types.Menu):
243     bl_label = "Text To 3D Object"
244
245     def draw(self, context):
246         layout = self.layout
247
248         layout.operator("text.to_3d_object", text="One Object").split_lines = False
249         layout.operator("text.to_3d_object", text="One Object Per Line").split_lines = True
250
251
252 class TEXT_MT_edit(bpy.types.Menu):
253     bl_label = "Edit"
254
255     @classmethod
256     def poll(cls, context):
257         return (context.space_data.text)
258
259     def draw(self, context):
260         layout = self.layout
261
262         layout.operator("ed.undo")
263         layout.operator("ed.redo")
264
265         layout.separator()
266
267         layout.operator("text.cut")
268         layout.operator("text.copy")
269         layout.operator("text.paste")
270
271         layout.separator()
272
273         layout.menu("TEXT_MT_edit_select")
274         layout.menu("TEXT_MT_edit_markers")
275
276         layout.separator()
277
278         layout.operator("text.jump")
279         layout.operator("text.properties", text="Find...")
280
281         layout.separator()
282
283         layout.menu("TEXT_MT_edit_to3d")
284
285
286 class TEXT_MT_toolbox(bpy.types.Menu):
287     bl_label = ""
288
289     def draw(self, context):
290         layout = self.layout
291         layout.operator_context = 'INVOKE_DEFAULT'
292
293         layout.operator("text.cut")
294         layout.operator("text.copy")
295         layout.operator("text.paste")
296
297         layout.separator()
298
299         layout.operator("text.run_script")
300
301 if __name__ == "__main__":  # only for live edit.
302     bpy.utils.register_module(__name__)