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