Merge with 2.5 -r 21619:21756.
[blender.git] / release / ui / space_text.py
1
2 import bpy
3
4 class TEXT_HT_header(bpy.types.Header):
5         __space_type__ = "TEXT_EDITOR"
6         __idname__ = "TEXT_HT_header"
7
8         def draw(self, context):
9                 st = context.space_data
10                 text = st.text
11                 layout = self.layout
12
13                 layout.template_header()
14
15                 if context.area.show_menus:
16                         row = layout.row()
17                         row.itemM("TEXT_MT_text")
18                         if text:
19                                 row.itemM("TEXT_MT_edit")
20                                 row.itemM("TEXT_MT_format")
21
22                 if text and text.modified:
23                         row = layout.row()
24                         # row.color(redalert)
25                         row.itemO("text.resolve_conflict", text="", icon='ICON_HELP')
26
27                 row = layout.row(align=True)
28                 row.itemR(st, "line_numbers", text="")
29                 row.itemR(st, "word_wrap", text="")
30                 row.itemR(st, "syntax_highlight", text="")
31
32                 layout.template_ID(st, "text", new="text.new", unlink="text.unlink")
33
34                 if text:
35                         row = layout.row()
36                         if text.filename != "":
37                                 if text.dirty:
38                                         row.itemL(text="File: *" + text.filename + " (unsaved)")
39                                 else:
40                                         row.itemL(text="File: " + text.filename)
41                         else:
42                                 if text.library:
43                                         row.itemL(text="Text: External")
44                                 else:
45                                         row.itemL(text="Text: Internal")
46
47 class TEXT_PT_properties(bpy.types.Panel):
48         __space_type__ = "TEXT_EDITOR"
49         __region_type__ = "UI"
50         __label__ = "Properties"
51
52         def draw(self, context):
53                 st = context.space_data
54                 layout = self.layout
55
56                 flow = layout.column_flow()
57                 flow.itemR(st, "line_numbers")
58                 flow.itemR(st, "word_wrap")
59                 flow.itemR(st, "syntax_highlight")
60                 flow.itemR(st, "live_edit")
61
62                 flow = layout.column_flow()
63                 flow.itemR(st, "font_size")
64                 flow.itemR(st, "tab_width")
65
66 class TEXT_PT_find(bpy.types.Panel):
67         __space_type__ = "TEXT_EDITOR"
68         __region_type__ = "UI"
69         __label__ = "Find"
70
71         def draw(self, context):
72                 st = context.space_data
73                 layout = self.layout
74
75                 # find
76                 col = layout.column(align=True)
77                 row = col.row()
78                 row.itemR(st, "find_text", text="")
79                 row.itemO("text.find_set_selected", text="", icon='ICON_TEXT')
80                 col.itemO("text.find")
81
82                 # replace
83                 col = layout.column(align=True)
84                 row = col.row()
85                 row.itemR(st, "replace_text", text="")
86                 row.itemO("text.replace_set_selected", text="", icon='ICON_TEXT')
87                 col.itemO("text.replace")
88
89                 # mark
90                 layout.itemO("text.mark_all")
91
92                 # settings
93                 row = layout.row()
94                 row.itemR(st, "find_wrap", text="Wrap")
95                 row.itemR(st, "find_all", text="All")
96
97 class TEXT_MT_text(bpy.types.Menu):
98         __space_type__ = "TEXT_EDITOR"
99         __label__ = "Text"
100
101         def draw(self, context):
102                 layout = self.layout
103                 st = context.space_data
104                 text = st.text
105
106                 layout.column()
107                 layout.itemO("text.new")
108                 layout.itemO("text.open")
109
110                 if text:
111                         layout.itemO("text.reload")
112
113                         layout.column()
114                         layout.itemO("text.save")
115                         layout.itemO("text.save_as")
116
117                         if text.filename != "":
118                                 layout.itemO("text.make_internal")
119
120                         layout.column()
121                         layout.itemO("text.run_script")
122
123                         #ifndef DISABLE_PYTHON
124                         # XXX if(BPY_is_pyconstraint(text))
125                         # XXX   uiMenuItemO(head, 0, "text.refresh_pyconstraints");
126                         #endif
127                 
128                 #ifndef DISABLE_PYTHON
129                 # XXX layout.column()
130                 # XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
131                 # XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
132                 #endif
133
134 class TEXT_MT_edit_view(bpy.types.Menu):
135         __space_type__ = "TEXT_EDITOR"
136         __label__ = "View"
137
138         def draw(self, context):
139                 layout = self.layout
140
141                 layout.item_enumO("text.move", "type", "FILE_TOP", text="Top of File")
142                 layout.item_enumO("text.move", "type", "FILE_BOTTOM", text="Bottom of File")
143
144 class TEXT_MT_edit_select(bpy.types.Menu):
145         __space_type__ = "TEXT_EDITOR"
146         __label__ = "Select"
147
148         def draw(self, context):
149                 layout = self.layout
150
151                 layout.itemO("text.select_all")
152                 layout.itemO("text.select_line")
153
154 class TEXT_MT_edit_markers(bpy.types.Menu):
155         __space_type__ = "TEXT_EDITOR"
156         __label__ = "Markers"
157
158         def draw(self, context):
159                 layout = self.layout
160
161                 layout.itemO("text.markers_clear")
162                 layout.itemO("text.next_marker")
163                 layout.itemO("text.previous_marker")
164
165 class TEXT_MT_format(bpy.types.Menu):
166         __space_type__ = "TEXT_EDITOR"
167         __label__ = "Format"
168
169         def draw(self, context):
170                 layout = self.layout
171
172                 layout.itemO("text.indent")
173                 layout.itemO("text.unindent")
174
175                 layout.itemS()
176
177                 layout.itemO("text.comment")
178                 layout.itemO("text.uncomment")
179
180                 layout.itemS()
181
182                 layout.item_menu_enumO("text.convert_whitespace", "type")
183
184 class TEXT_MT_edit_to3d(bpy.types.Menu):
185         __space_type__ = "TEXT_EDITOR"
186         __label__ = "Text To 3D Object"
187
188         def draw(self, context):
189                 layout = self.layout
190
191                 layout.item_booleanO("text.to_3d_object", "split_lines", False, text="One Object");
192                 layout.item_booleanO("text.to_3d_object", "split_lines", True, text="One Object Per Line");
193
194 class TEXT_MT_edit(bpy.types.Menu):
195         __space_type__ = "TEXT_EDITOR"
196         __label__ = "Edit"
197
198         def poll(self, context):
199                 st = context.space_data
200                 return st.text != None
201
202         def draw(self, context):
203                 layout = self.layout
204
205                 layout.itemO("ed.undo")
206                 layout.itemO("ed.redo")
207
208                 layout.itemS()
209
210                 layout.itemO("text.cut")
211                 layout.itemO("text.copy")
212                 layout.itemO("text.paste")
213
214                 layout.itemS()
215
216                 layout.itemM("TEXT_MT_edit_view")
217                 layout.itemM("TEXT_MT_edit_select")
218                 layout.itemM("TEXT_MT_edit_markers")
219
220                 layout.itemS()
221
222                 layout.itemO("text.jump")
223                 layout.itemO("text.properties")
224
225                 layout.itemS()
226
227                 layout.itemM("TEXT_MT_edit_to3d")
228
229 bpy.types.register(TEXT_HT_header)
230 bpy.types.register(TEXT_PT_properties)
231 bpy.types.register(TEXT_PT_find)
232 bpy.types.register(TEXT_MT_text)
233 bpy.types.register(TEXT_MT_format)
234 bpy.types.register(TEXT_MT_edit)
235 bpy.types.register(TEXT_MT_edit_view)
236 bpy.types.register(TEXT_MT_edit_select)
237 bpy.types.register(TEXT_MT_edit_markers)
238 bpy.types.register(TEXT_MT_edit_to3d)
239