tabs to spaces, remove trailing white space. (apart of pep8)
[blender-staging.git] / release / scripts / ui / space_text.py
1
2 import bpy
3
4 class TEXT_HT_header(bpy.types.Header):
5     bl_space_type = 'TEXT_EDITOR'
6
7     def draw(self, context):
8         layout = self.layout
9
10         st = context.space_data
11         text = st.text
12
13         row = layout.row(align=True)
14         row.template_header()
15
16         if context.area.show_menus:
17             sub = row.row(align=True)
18             sub.itemM("TEXT_MT_text")
19             if text:
20                 sub.itemM("TEXT_MT_edit")
21                 sub.itemM("TEXT_MT_format")
22
23         if text and text.modified:
24             row = layout.row()
25             # row.color(redalert)
26             row.itemO("text.resolve_conflict", text="", icon='ICON_HELP')
27
28         layout.template_ID(st, "text", new="text.new", unlink="text.unlink")
29
30         row = layout.row(align=True)
31         row.itemR(st, "line_numbers", text="")
32         row.itemR(st, "word_wrap", text="")
33         row.itemR(st, "syntax_highlight", text="")
34
35         if text:
36             row = layout.row()
37             if text.filename != "":
38                 if text.dirty:
39                     row.itemL(text="File: *%s (unsaved)" % text.filename)
40                 else:
41                     row.itemL(text="File: %s" % text.filename )
42             else:
43                 if text.library:
44                     row.itemL(text="Text: External")
45                 else:
46                     row.itemL(text="Text: Internal")
47
48         row = layout.row()
49         row.itemO("text.run_script")
50
51 class TEXT_PT_properties(bpy.types.Panel):
52     bl_space_type = 'TEXT_EDITOR'
53     bl_region_type = 'UI'
54     bl_label = "Properties"
55
56     def draw(self, context):
57         layout = self.layout
58
59         st = context.space_data
60
61         flow = layout.column_flow()
62         flow.itemR(st, "line_numbers")
63         flow.itemR(st, "word_wrap")
64         flow.itemR(st, "syntax_highlight")
65         flow.itemR(st, "live_edit")
66
67         flow = layout.column_flow()
68         flow.itemR(st, "font_size")
69         flow.itemR(st, "tab_width")
70
71 class TEXT_PT_find(bpy.types.Panel):
72     bl_space_type = 'TEXT_EDITOR'
73     bl_region_type = 'UI'
74     bl_label = "Find"
75
76     def draw(self, context):
77         layout = self.layout
78
79         st = context.space_data
80
81         # find
82         col = layout.column(align=True)
83         row = col.row()
84         row.itemR(st, "find_text", text="")
85         row.itemO("text.find_set_selected", text="", icon='ICON_TEXT')
86         col.itemO("text.find")
87
88         # replace
89         col = layout.column(align=True)
90         row = col.row()
91         row.itemR(st, "replace_text", text="")
92         row.itemO("text.replace_set_selected", text="", icon='ICON_TEXT')
93         col.itemO("text.replace")
94
95         # mark
96         layout.itemO("text.mark_all")
97
98         # settings
99         row = layout.row()
100         row.itemR(st, "find_wrap", text="Wrap")
101         row.itemR(st, "find_all", text="All")
102
103 class TEXT_MT_text(bpy.types.Menu):
104     bl_label = "Text"
105
106     def draw(self, context):
107         layout = self.layout
108
109         st = context.space_data
110         text = st.text
111
112         layout.column()
113         layout.itemO("text.new")
114         layout.itemO("text.open")
115
116         if text:
117             layout.itemO("text.reload")
118
119             layout.column()
120             layout.itemO("text.save")
121             layout.itemO("text.save_as")
122
123             if text.filename != "":
124                 layout.itemO("text.make_internal")
125
126             layout.column()
127             layout.itemO("text.run_script")
128
129             #ifndef DISABLE_PYTHON
130             # XXX if(BPY_is_pyconstraint(text))
131             # XXX   uiMenuItemO(head, 0, "text.refresh_pyconstraints");
132             #endif
133
134         layout.itemS()
135
136         layout.itemO("text.properties", icon='ICON_MENU_PANEL')
137
138
139
140         #ifndef DISABLE_PYTHON
141         # XXX layout.column()
142         # XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
143         # XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
144         #endif
145
146         layout.itemM("TEXT_MT_templates")
147
148
149
150 class TEXT_MT_templates(bpy.types.Menu):
151     '''
152     Creates the menu items by scanning scripts/templates
153     '''
154     bl_label = "Script Templates"
155
156     def draw(self, context):
157         import os
158
159         def path_to_name(f):
160             f_base = os.path.splitext(f)[0]
161             f_base = f_base.replace("_", " ")
162             return ' '.join([w[0].upper() + w[1:] for w in f_base.split()])
163
164         layout = self.layout
165         template_dir = os.path.join(os.path.dirname(__file__), os.path.pardir, "templates")
166
167         for f in sorted(os.listdir(template_dir)):
168
169             if f.startswith("."):
170                 continue
171
172             path = os.path.join(template_dir, f)
173             layout.item_stringO("text.open", "path", path, text=path_to_name(f))
174
175
176
177 class TEXT_MT_edit_view(bpy.types.Menu):
178     bl_label = "View"
179
180     def draw(self, context):
181         layout = self.layout
182
183         layout.item_enumO("text.move", "type", 'FILE_TOP', text="Top of File")
184         layout.item_enumO("text.move", "type", 'FILE_BOTTOM', text="Bottom of File")
185
186 class TEXT_MT_edit_select(bpy.types.Menu):
187     bl_label = "Select"
188
189     def draw(self, context):
190         layout = self.layout
191
192         layout.itemO("text.select_all")
193         layout.itemO("text.select_line")
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 class TEXT_MT_format(bpy.types.Menu):
206     bl_label = "Format"
207
208     def draw(self, context):
209         layout = self.layout
210
211         layout.itemO("text.indent")
212         layout.itemO("text.unindent")
213
214         layout.itemS()
215
216         layout.itemO("text.comment")
217         layout.itemO("text.uncomment")
218
219         layout.itemS()
220
221         layout.item_menu_enumO("text.convert_whitespace", "type")
222
223 class TEXT_MT_edit_to3d(bpy.types.Menu):
224     bl_label = "Text To 3D Object"
225
226     def draw(self, context):
227         layout = self.layout
228
229         layout.item_booleanO("text.to_3d_object", "split_lines", False, text="One Object");
230         layout.item_booleanO("text.to_3d_object", "split_lines", True, text="One Object Per Line");
231
232 class TEXT_MT_edit(bpy.types.Menu):
233     bl_label = "Edit"
234
235     def poll(self, context):
236         return (context.space_data.text)
237
238     def draw(self, context):
239         layout = self.layout
240
241         layout.itemO("ed.undo")
242         layout.itemO("ed.redo")
243
244         layout.itemS()
245
246         layout.itemO("text.cut")
247         layout.itemO("text.copy")
248         layout.itemO("text.paste")
249
250         layout.itemS()
251
252         layout.itemM("TEXT_MT_edit_view")
253         layout.itemM("TEXT_MT_edit_select")
254         layout.itemM("TEXT_MT_edit_markers")
255
256         layout.itemS()
257
258         layout.itemO("text.jump")
259         layout.itemO("text.properties", text="Find...")
260
261         layout.itemS()
262
263         layout.itemM("TEXT_MT_edit_to3d")
264
265 bpy.types.register(TEXT_HT_header)
266 bpy.types.register(TEXT_PT_properties)
267 bpy.types.register(TEXT_PT_find)
268 bpy.types.register(TEXT_MT_text)
269 bpy.types.register(TEXT_MT_templates)
270 bpy.types.register(TEXT_MT_format)
271 bpy.types.register(TEXT_MT_edit)
272 bpy.types.register(TEXT_MT_edit_view)
273 bpy.types.register(TEXT_MT_edit_select)
274 bpy.types.register(TEXT_MT_edit_markers)
275 bpy.types.register(TEXT_MT_edit_to3d)