4860767d69decefb48bb041a00aa473a1786286e
[blender.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         __label__ = "Text"
102
103         def draw(self, context):
104                 layout = self.layout
105                 
106                 st = context.space_data
107                 text = st.text
108
109                 layout.column()
110                 layout.itemO("text.new")
111                 layout.itemO("text.open")
112
113                 if text:
114                         layout.itemO("text.reload")
115
116                         layout.column()
117                         layout.itemO("text.save")
118                         layout.itemO("text.save_as")
119
120                         if text.filename != "":
121                                 layout.itemO("text.make_internal")
122
123                         layout.column()
124                         layout.itemO("text.run_script")
125
126                         #ifndef DISABLE_PYTHON
127                         # XXX if(BPY_is_pyconstraint(text))
128                         # XXX   uiMenuItemO(head, 0, "text.refresh_pyconstraints");
129                         #endif
130
131                 layout.itemS()
132
133                 layout.itemO("text.properties", icon='ICON_MENU_PANEL')
134                 
135                 #ifndef DISABLE_PYTHON
136                 # XXX layout.column()
137                 # XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
138                 # XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
139                 #endif
140
141 class TEXT_MT_edit_view(bpy.types.Menu):
142         __label__ = "View"
143
144         def draw(self, context):
145                 layout = self.layout
146
147                 layout.item_enumO("text.move", "type", 'FILE_TOP', text="Top of File")
148                 layout.item_enumO("text.move", "type", 'FILE_BOTTOM', text="Bottom of File")
149
150 class TEXT_MT_edit_select(bpy.types.Menu):
151         __label__ = "Select"
152
153         def draw(self, context):
154                 layout = self.layout
155
156                 layout.itemO("text.select_all")
157                 layout.itemO("text.select_line")
158
159 class TEXT_MT_edit_markers(bpy.types.Menu):
160         __label__ = "Markers"
161
162         def draw(self, context):
163                 layout = self.layout
164
165                 layout.itemO("text.markers_clear")
166                 layout.itemO("text.next_marker")
167                 layout.itemO("text.previous_marker")
168
169 class TEXT_MT_format(bpy.types.Menu):
170         __label__ = "Format"
171
172         def draw(self, context):
173                 layout = self.layout
174
175                 layout.itemO("text.indent")
176                 layout.itemO("text.unindent")
177
178                 layout.itemS()
179
180                 layout.itemO("text.comment")
181                 layout.itemO("text.uncomment")
182
183                 layout.itemS()
184
185                 layout.item_menu_enumO("text.convert_whitespace", "type")
186
187 class TEXT_MT_edit_to3d(bpy.types.Menu):
188         __label__ = "Text To 3D Object"
189
190         def draw(self, context):
191                 layout = self.layout
192
193                 layout.item_booleanO("text.to_3d_object", "split_lines", False, text="One Object");
194                 layout.item_booleanO("text.to_3d_object", "split_lines", True, text="One Object Per Line");
195
196 class TEXT_MT_edit(bpy.types.Menu):
197         __label__ = "Edit"
198
199         def poll(self, context):
200                 return (context.space_data.text)
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", text="Find...")
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)