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