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