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