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