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