change python scripts so modules which register with blender have a register() functi...
[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_text")
38             if text:
39                 sub.menu("TEXT_MT_edit")
40                 sub.menu("TEXT_MT_format")
41
42         if text and text.modified:
43             row = layout.row()
44             # row.color(redalert)
45             row.operator("text.resolve_conflict", text="", icon='HELP')
46
47         layout.template_ID(st, "text", new="text.new", unlink="text.unlink")
48
49         row = layout.row(align=True)
50         row.prop(st, "line_numbers", text="")
51         row.prop(st, "word_wrap", text="")
52         row.prop(st, "syntax_highlight", text="")
53
54         if text:
55             row = layout.row()
56             row.operator("text.run_script")
57             row.prop(text, "use_module")
58
59             row = layout.row()
60             if text.filename != "":
61                 if text.dirty:
62                     row.label(text="File: *%s (unsaved)" % text.filename)
63                 else:
64                     row.label(text="File: %s" % text.filename)
65             else:
66                 if text.library:
67                     row.label(text="Text: External")
68                 else:
69                     row.label(text="Text: Internal")
70
71
72 class TEXT_PT_properties(bpy.types.Panel):
73     bl_space_type = 'TEXT_EDITOR'
74     bl_region_type = 'UI'
75     bl_label = "Properties"
76
77     def draw(self, context):
78         layout = self.layout
79
80         st = context.space_data
81
82         flow = layout.column_flow()
83         flow.prop(st, "line_numbers")
84         flow.prop(st, "word_wrap")
85         flow.prop(st, "syntax_highlight")
86         flow.prop(st, "live_edit")
87
88         flow = layout.column_flow()
89         flow.prop(st, "font_size")
90         flow.prop(st, "tab_width")
91
92         text = st.text
93         if text:
94             flow.prop(text, "tabs_as_spaces")
95
96
97 class TEXT_PT_find(bpy.types.Panel):
98     bl_space_type = 'TEXT_EDITOR'
99     bl_region_type = 'UI'
100     bl_label = "Find"
101
102     def draw(self, context):
103         layout = self.layout
104
105         st = context.space_data
106
107         # find
108         col = layout.column(align=True)
109         row = col.row()
110         row.prop(st, "find_text", text="")
111         row.operator("text.find_set_selected", text="", icon='TEXT')
112         col.operator("text.find")
113
114         # replace
115         col = layout.column(align=True)
116         row = col.row()
117         row.prop(st, "replace_text", text="")
118         row.operator("text.replace_set_selected", text="", icon='TEXT')
119         col.operator("text.replace")
120
121         # mark
122         layout.operator("text.mark_all")
123
124         # settings
125         row = layout.row()
126         row.prop(st, "find_wrap", text="Wrap")
127         row.prop(st, "find_all", text="All")
128
129
130 class TEXT_MT_text(bpy.types.Menu):
131     bl_label = "Text"
132
133     def draw(self, context):
134         layout = self.layout
135
136         st = context.space_data
137         text = st.text
138
139         layout.column()
140         layout.operator("text.new")
141         layout.operator("text.open")
142
143         if text:
144             layout.operator("text.reload")
145
146             layout.column()
147             layout.operator("text.save")
148             layout.operator("text.save_as")
149
150             if text.filename != "":
151                 layout.operator("text.make_internal")
152
153             layout.column()
154             layout.operator("text.run_script")
155
156             #ifndef DISABLE_PYTHON
157             # XXX if(BPY_is_pyconstraint(text))
158             # XXX   uiMenuItemO(head, 0, "text.refresh_pyconstraints");
159             #endif
160
161         layout.separator()
162
163         layout.operator("text.properties", icon='MENU_PANEL')
164
165         layout.menu("TEXT_MT_templates")
166
167         layout.separator()
168
169         layout.operator("screen.area_dupli")
170         layout.operator("screen.screen_full_area")
171
172
173 class TEXT_MT_templates(bpy.types.Menu):
174     '''
175     Creates the menu items by scanning scripts/templates
176     '''
177     bl_label = "Script Templates"
178
179     def draw(self, context):
180         self.path_menu(bpy.utils.script_paths("templates"), "text.open")
181
182
183 class TEXT_MT_edit_view(bpy.types.Menu):
184     bl_label = "View"
185
186     def draw(self, context):
187         layout = self.layout
188
189         layout.operator("text.move", text="Top of File").type = 'FILE_TOP'
190         layout.operator("text.move", text="Bottom of File").type = 'FILE_BOTTOM'
191
192
193 class TEXT_MT_edit_select(bpy.types.Menu):
194     bl_label = "Select"
195
196     def draw(self, context):
197         layout = self.layout
198
199         layout.operator("text.select_all")
200         layout.operator("text.select_line")
201
202
203 class TEXT_MT_edit_markers(bpy.types.Menu):
204     bl_label = "Markers"
205
206     def draw(self, context):
207         layout = self.layout
208
209         layout.operator("text.markers_clear")
210         layout.operator("text.next_marker")
211         layout.operator("text.previous_marker")
212
213
214 class TEXT_MT_format(bpy.types.Menu):
215     bl_label = "Format"
216
217     def draw(self, context):
218         layout = self.layout
219
220         layout.operator("text.indent")
221         layout.operator("text.unindent")
222
223         layout.separator()
224
225         layout.operator("text.comment")
226         layout.operator("text.uncomment")
227
228         layout.separator()
229
230         layout.operator_menu_enum("text.convert_whitespace", "type")
231
232
233 class TEXT_MT_edit_to3d(bpy.types.Menu):
234     bl_label = "Text To 3D Object"
235
236     def draw(self, context):
237         layout = self.layout
238
239         layout.operator("text.to_3d_object", text="One Object").split_lines = False
240         layout.operator("text.to_3d_object", text="One Object Per Line").split_lines = True
241
242
243 class TEXT_MT_edit(bpy.types.Menu):
244     bl_label = "Edit"
245
246     def poll(self, context):
247         return (context.space_data.text)
248
249     def draw(self, context):
250         layout = self.layout
251
252         layout.operator("ed.undo")
253         layout.operator("ed.redo")
254
255         layout.separator()
256
257         layout.operator("text.cut")
258         layout.operator("text.copy")
259         layout.operator("text.paste")
260
261         layout.separator()
262
263         layout.menu("TEXT_MT_edit_view")
264         layout.menu("TEXT_MT_edit_select")
265         layout.menu("TEXT_MT_edit_markers")
266
267         layout.separator()
268
269         layout.operator("text.jump")
270         layout.operator("text.properties", text="Find...")
271
272         layout.separator()
273
274         layout.menu("TEXT_MT_edit_to3d")
275
276
277 classes = [
278     TEXT_HT_header,
279     TEXT_PT_properties,
280     TEXT_PT_find,
281     TEXT_MT_text,
282     TEXT_MT_templates,
283     TEXT_MT_format,
284     TEXT_MT_edit,
285     TEXT_MT_edit_view,
286     TEXT_MT_edit_select,
287     TEXT_MT_edit_markers,
288     TEXT_MT_edit_to3d]
289
290
291 def register():
292     register = bpy.types.register
293     for cls in classes:
294         register(cls)
295
296 def unregister():
297     unregister = bpy.types.unregister
298     for cls in classes:
299         unregister(cls)