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