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