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