rename and negate DISABLE_PYTHON --> WITH_PYTHON
[blender.git] / release / scripts / 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
99 class TEXT_PT_find(bpy.types.Panel):
100     bl_space_type = 'TEXT_EDITOR'
101     bl_region_type = 'UI'
102     bl_label = "Find"
103
104     def draw(self, context):
105         layout = self.layout
106
107         st = context.space_data
108
109         # find
110         col = layout.column(align=True)
111         row = col.row()
112         row.prop(st, "find_text", text="")
113         row.operator("text.find_set_selected", text="", icon='TEXT')
114         col.operator("text.find")
115
116         # replace
117         col = layout.column(align=True)
118         row = col.row()
119         row.prop(st, "replace_text", text="")
120         row.operator("text.replace_set_selected", text="", icon='TEXT')
121         col.operator("text.replace")
122
123         # mark
124         layout.operator("text.mark_all")
125
126         # settings
127         row = layout.row()
128         row.prop(st, "use_find_wrap", text="Wrap")
129         row.prop(st, "use_find_all", text="All")
130
131
132 class TEXT_MT_view(bpy.types.Menu):
133     bl_label = "View"
134
135     def draw(self, context):
136         layout = self.layout
137
138         layout.operator("text.properties", icon='MENU_PANEL')
139
140         layout.separator()
141
142         layout.operator("screen.area_dupli")
143         layout.operator("screen.screen_full_area")
144
145         layout.separator()
146
147         layout.operator("text.move", text="Top of File").type = 'FILE_TOP'
148         layout.operator("text.move", text="Bottom of File").type = 'FILE_BOTTOM'
149
150
151 class TEXT_MT_text(bpy.types.Menu):
152     bl_label = "Text"
153
154     def draw(self, context):
155         layout = self.layout
156
157         st = context.space_data
158         text = st.text
159
160         layout.column()
161         layout.operator("text.new")
162         layout.operator("text.open")
163
164         if text:
165             layout.operator("text.reload")
166
167             layout.column()
168             layout.operator("text.save")
169             layout.operator("text.save_as")
170
171             if text.filepath:
172                 layout.operator("text.make_internal")
173
174             layout.column()
175             layout.operator("text.run_script")
176
177             #ifdef WITH_PYTHON
178             # XXX if(BPY_is_pyconstraint(text))
179             # XXX   uiMenuItemO(head, 0, "text.refresh_pyconstraints");
180             #endif
181
182         layout.separator()
183
184         layout.menu("TEXT_MT_templates")
185
186
187 class TEXT_MT_templates(bpy.types.Menu):
188     '''
189     Creates the menu items by scanning scripts/templates
190     '''
191     bl_label = "Script Templates"
192
193     def draw(self, context):
194         self.path_menu(bpy.utils.script_paths("templates"), "text.open", {"internal": True})
195
196
197 class TEXT_MT_edit_select(bpy.types.Menu):
198     bl_label = "Select"
199
200     def draw(self, context):
201         layout = self.layout
202
203         layout.operator("text.select_all")
204         layout.operator("text.select_line")
205
206
207 class TEXT_MT_edit_markers(bpy.types.Menu):
208     bl_label = "Markers"
209
210     def draw(self, context):
211         layout = self.layout
212
213         layout.operator("text.markers_clear")
214         layout.operator("text.next_marker")
215         layout.operator("text.previous_marker")
216
217
218 class TEXT_MT_format(bpy.types.Menu):
219     bl_label = "Format"
220
221     def draw(self, context):
222         layout = self.layout
223
224         layout.operator("text.indent")
225         layout.operator("text.unindent")
226
227         layout.separator()
228
229         layout.operator("text.comment")
230         layout.operator("text.uncomment")
231
232         layout.separator()
233
234         layout.operator_menu_enum("text.convert_whitespace", "type")
235
236
237 class TEXT_MT_edit_to3d(bpy.types.Menu):
238     bl_label = "Text To 3D Object"
239
240     def draw(self, context):
241         layout = self.layout
242
243         layout.operator("text.to_3d_object", text="One Object").split_lines = False
244         layout.operator("text.to_3d_object", text="One Object Per Line").split_lines = True
245
246
247 class TEXT_MT_edit(bpy.types.Menu):
248     bl_label = "Edit"
249
250     @classmethod
251     def poll(cls, context):
252         return (context.space_data.text)
253
254     def draw(self, context):
255         layout = self.layout
256
257         layout.operator("ed.undo")
258         layout.operator("ed.redo")
259
260         layout.separator()
261
262         layout.operator("text.cut")
263         layout.operator("text.copy")
264         layout.operator("text.paste")
265
266         layout.separator()
267
268         layout.menu("TEXT_MT_edit_select")
269         layout.menu("TEXT_MT_edit_markers")
270
271         layout.separator()
272
273         layout.operator("text.jump")
274         layout.operator("text.properties", text="Find...")
275
276         layout.separator()
277
278         layout.menu("TEXT_MT_edit_to3d")
279
280
281 class TEXT_MT_toolbox(bpy.types.Menu):
282     bl_label = ""
283
284     def draw(self, context):
285         layout = self.layout
286         layout.operator_context = 'INVOKE_DEFAULT'
287
288         layout.operator("text.cut")
289         layout.operator("text.copy")
290         layout.operator("text.paste")
291
292         layout.separator()
293
294         layout.operator("text.run_script")
295
296
297 def register():
298     pass
299
300
301 def unregister():
302     pass
303
304 if __name__ == "__main__":
305     register()