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