Durian text editor requests:
[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                 row = layout.row()
49                 row.itemO("text.run_script")
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                 layout = self.layout
58                 
59                 st = context.space_data
60
61                 flow = layout.column_flow()
62                 flow.itemR(st, "line_numbers")
63                 flow.itemR(st, "word_wrap")
64                 flow.itemR(st, "syntax_highlight")
65                 flow.itemR(st, "live_edit")
66
67                 flow = layout.column_flow()
68                 flow.itemR(st, "font_size")
69                 flow.itemR(st, "tab_width")
70
71 class TEXT_PT_find(bpy.types.Panel):
72         __space_type__ = 'TEXT_EDITOR'
73         __region_type__ = 'UI'
74         __label__ = "Find"
75
76         def draw(self, context):
77                 layout = self.layout
78                 
79                 st = context.space_data
80
81                 # find
82                 col = layout.column(align=True)
83                 row = col.row()
84                 row.itemR(st, "find_text", text="")
85                 row.itemO("text.find_set_selected", text="", icon='ICON_TEXT')
86                 col.itemO("text.find")
87
88                 # replace
89                 col = layout.column(align=True)
90                 row = col.row()
91                 row.itemR(st, "replace_text", text="")
92                 row.itemO("text.replace_set_selected", text="", icon='ICON_TEXT')
93                 col.itemO("text.replace")
94
95                 # mark
96                 layout.itemO("text.mark_all")
97
98                 # settings
99                 row = layout.row()
100                 row.itemR(st, "find_wrap", text="Wrap")
101                 row.itemR(st, "find_all", text="All")
102
103 class TEXT_MT_text(bpy.types.Menu):
104         __label__ = "Text"
105
106         def draw(self, context):
107                 layout = self.layout
108                 
109                 st = context.space_data
110                 text = st.text
111
112                 layout.column()
113                 layout.itemO("text.new")
114                 layout.itemO("text.open")
115
116                 if text:
117                         layout.itemO("text.reload")
118
119                         layout.column()
120                         layout.itemO("text.save")
121                         layout.itemO("text.save_as")
122
123                         if text.filename != "":
124                                 layout.itemO("text.make_internal")
125
126                         layout.column()
127                         layout.itemO("text.run_script")
128
129                         #ifndef DISABLE_PYTHON
130                         # XXX if(BPY_is_pyconstraint(text))
131                         # XXX   uiMenuItemO(head, 0, "text.refresh_pyconstraints");
132                         #endif
133
134                 layout.itemS()
135
136                 layout.itemO("text.properties", icon='ICON_MENU_PANEL')
137                 
138                 #ifndef DISABLE_PYTHON
139                 # XXX layout.column()
140                 # XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
141                 # XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
142                 #endif
143
144 class TEXT_MT_edit_view(bpy.types.Menu):
145         __label__ = "View"
146
147         def draw(self, context):
148                 layout = self.layout
149
150                 layout.item_enumO("text.move", "type", 'FILE_TOP', text="Top of File")
151                 layout.item_enumO("text.move", "type", 'FILE_BOTTOM', text="Bottom of File")
152
153 class TEXT_MT_edit_select(bpy.types.Menu):
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         __label__ = "Markers"
164
165         def draw(self, context):
166                 layout = self.layout
167
168                 layout.itemO("text.markers_clear")
169                 layout.itemO("text.next_marker")
170                 layout.itemO("text.previous_marker")
171
172 class TEXT_MT_format(bpy.types.Menu):
173         __label__ = "Format"
174
175         def draw(self, context):
176                 layout = self.layout
177
178                 layout.itemO("text.indent")
179                 layout.itemO("text.unindent")
180
181                 layout.itemS()
182
183                 layout.itemO("text.comment")
184                 layout.itemO("text.uncomment")
185
186                 layout.itemS()
187
188                 layout.item_menu_enumO("text.convert_whitespace", "type")
189
190 class TEXT_MT_edit_to3d(bpy.types.Menu):
191         __label__ = "Text To 3D Object"
192
193         def draw(self, context):
194                 layout = self.layout
195
196                 layout.item_booleanO("text.to_3d_object", "split_lines", False, text="One Object");
197                 layout.item_booleanO("text.to_3d_object", "split_lines", True, text="One Object Per Line");
198
199 class TEXT_MT_edit(bpy.types.Menu):
200         __label__ = "Edit"
201
202         def poll(self, context):
203                 return (context.space_data.text)
204
205         def draw(self, context):
206                 layout = self.layout
207
208                 layout.itemO("ed.undo")
209                 layout.itemO("ed.redo")
210
211                 layout.itemS()
212
213                 layout.itemO("text.cut")
214                 layout.itemO("text.copy")
215                 layout.itemO("text.paste")
216
217                 layout.itemS()
218
219                 layout.itemM("TEXT_MT_edit_view")
220                 layout.itemM("TEXT_MT_edit_select")
221                 layout.itemM("TEXT_MT_edit_markers")
222
223                 layout.itemS()
224
225                 layout.itemO("text.jump")
226                 layout.itemO("text.properties", text="Find...")
227
228                 layout.itemS()
229
230                 layout.itemM("TEXT_MT_edit_to3d")
231
232 bpy.types.register(TEXT_HT_header)
233 bpy.types.register(TEXT_PT_properties)
234 bpy.types.register(TEXT_PT_find)
235 bpy.types.register(TEXT_MT_text)
236 bpy.types.register(TEXT_MT_format)
237 bpy.types.register(TEXT_MT_edit)
238 bpy.types.register(TEXT_MT_edit_view)
239 bpy.types.register(TEXT_MT_edit_select)
240 bpy.types.register(TEXT_MT_edit_markers)
241 bpy.types.register(TEXT_MT_edit_to3d)