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