Do not show confirm message when creating text block from menu.
[blender.git] / release / scripts / startup / bl_ui / space_text.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8-80 compliant>
20 import bpy
21 from bpy.types import Header, Menu, Panel
22
23
24 class TEXT_HT_header(Header):
25     bl_space_type = 'TEXT_EDITOR'
26
27     def draw(self, context):
28         layout = self.layout
29
30         st = context.space_data
31         text = st.text
32
33         row = layout.row(align=True)
34         row.template_header()
35
36         if context.area.show_menus:
37             row.menu("TEXT_MT_view")
38             row.menu("TEXT_MT_text")
39
40             if text:
41                 row.menu("TEXT_MT_edit")
42                 row.menu("TEXT_MT_format")
43
44             row.menu("TEXT_MT_templates")
45
46         if text and text.is_modified:
47             sub = row.row()
48             sub.alert = True
49             sub.operator("text.resolve_conflict", text="", icon='HELP')
50
51         row.template_ID(st, "text", new="text.new", unlink="text.unlink")
52
53         row = layout.row(align=True)
54         row.prop(st, "show_line_numbers", text="")
55         row.prop(st, "show_word_wrap", text="")
56         row.prop(st, "show_syntax_highlight", text="")
57
58         if text:
59             row = layout.row()
60             row.operator("text.run_script")
61
62             row = layout.row()
63             row.active = text.name.endswith(".py")
64             row.prop(text, "use_module")
65
66             row = layout.row()
67             if text.filepath:
68                 if text.is_dirty:
69                     row.label(text="File: *%r (unsaved)" % text.filepath)
70                 else:
71                     row.label(text="File: %r" % text.filepath)
72             else:
73                 row.label(text="Text: External"
74                           if text.library
75                           else "Text: Internal")
76
77
78 class TEXT_PT_properties(Panel):
79     bl_space_type = 'TEXT_EDITOR'
80     bl_region_type = 'UI'
81     bl_label = "Properties"
82
83     def draw(self, context):
84         layout = self.layout
85
86         st = context.space_data
87
88         flow = layout.column_flow()
89         flow.prop(st, "show_line_numbers")
90         flow.prop(st, "show_word_wrap")
91         flow.prop(st, "show_syntax_highlight")
92         flow.prop(st, "show_line_highlight")
93         flow.prop(st, "use_live_edit")
94
95         flow = layout.column_flow()
96         flow.prop(st, "font_size")
97         flow.prop(st, "tab_width")
98
99         text = st.text
100         if text:
101             flow.prop(text, "use_tabs_as_spaces")
102
103         flow.prop(st, "show_margin")
104         col = flow.column()
105         col.active = st.show_margin
106         col.prop(st, "margin_column")
107
108
109 class TEXT_PT_find(Panel):
110     bl_space_type = 'TEXT_EDITOR'
111     bl_region_type = 'UI'
112     bl_label = "Find"
113
114     def draw(self, context):
115         layout = self.layout
116
117         st = context.space_data
118
119         # find
120         col = layout.column(align=True)
121         row = col.row()
122         row.prop(st, "find_text", text="")
123         row.operator("text.find_set_selected", text="", icon='TEXT')
124         col.operator("text.find")
125
126         # replace
127         col = layout.column(align=True)
128         row = col.row()
129         row.prop(st, "replace_text", text="")
130         row.operator("text.replace_set_selected", text="", icon='TEXT')
131         col.operator("text.replace")
132
133         # mark
134         layout.operator("text.mark_all")
135
136         # settings
137         layout.prop(st, "use_match_case")
138         row = layout.row()
139         row.prop(st, "use_find_wrap", text="Wrap")
140         row.prop(st, "use_find_all", text="All")
141
142
143 class TEXT_MT_view(Menu):
144     bl_label = "View"
145
146     def draw(self, context):
147         layout = self.layout
148
149         layout.operator("text.properties", icon='MENU_PANEL')
150
151         layout.separator()
152
153         layout.operator("screen.area_dupli")
154         layout.operator("screen.screen_full_area")
155
156         layout.separator()
157
158         layout.operator("text.move",
159                         text="Top of File",
160                         ).type = 'FILE_TOP'
161         layout.operator("text.move",
162                         text="Bottom of File",
163                         ).type = 'FILE_BOTTOM'
164
165
166 class TEXT_MT_text(Menu):
167     bl_label = "Text"
168
169     def draw(self, context):
170         layout = self.layout
171
172         st = context.space_data
173         text = st.text
174
175         layout.operator_context = 'EXEC_AREA'
176         layout.operator("text.new")
177         layout.operator_context = 'INVOKE_AREA'
178         layout.operator("text.open")
179
180         if text:
181             layout.operator("text.reload")
182
183             layout.column()
184             layout.operator("text.save")
185             layout.operator("text.save_as")
186
187             if text.filepath:
188                 layout.operator("text.make_internal")
189
190             layout.column()
191             layout.operator("text.run_script")
192
193
194 class TEXT_MT_templates(Menu):
195     bl_label = "Templates"
196
197     def draw(self, context):
198         self.path_menu(bpy.utils.script_paths("templates"),
199                        "text.open",
200                        {"internal": True},
201                        )
202
203
204 class TEXT_MT_edit_select(Menu):
205     bl_label = "Select"
206
207     def draw(self, context):
208         layout = self.layout
209
210         layout.operator("text.select_all")
211         layout.operator("text.select_line")
212
213
214 class TEXT_MT_edit_markers(Menu):
215     bl_label = "Markers"
216
217     def draw(self, context):
218         layout = self.layout
219
220         layout.operator("text.markers_clear")
221         layout.operator("text.next_marker")
222         layout.operator("text.previous_marker")
223
224
225 class TEXT_MT_format(Menu):
226     bl_label = "Format"
227
228     def draw(self, context):
229         layout = self.layout
230
231         layout.operator("text.indent")
232         layout.operator("text.unindent")
233
234         layout.separator()
235
236         layout.operator("text.comment")
237         layout.operator("text.uncomment")
238
239         layout.separator()
240
241         layout.operator_menu_enum("text.convert_whitespace", "type")
242
243
244 class TEXT_MT_edit_to3d(Menu):
245     bl_label = "Text To 3D Object"
246
247     def draw(self, context):
248         layout = self.layout
249
250         layout.operator("text.to_3d_object",
251                         text="One Object",
252                         ).split_lines = False
253         layout.operator("text.to_3d_object",
254                         text="One Object Per Line",
255                         ).split_lines = True
256
257
258 class TEXT_MT_edit(Menu):
259     bl_label = "Edit"
260
261     @classmethod
262     def poll(cls, context):
263         return (context.space_data.text)
264
265     def draw(self, context):
266         layout = self.layout
267
268         layout.operator("ed.undo")
269         layout.operator("ed.redo")
270
271         layout.separator()
272
273         layout.operator("text.cut")
274         layout.operator("text.copy")
275         layout.operator("text.paste")
276
277         layout.separator()
278
279         layout.menu("TEXT_MT_edit_select")
280         layout.menu("TEXT_MT_edit_markers")
281
282         layout.separator()
283
284         layout.operator("text.jump")
285         layout.operator("text.properties", text="Find...")
286
287         layout.separator()
288
289         layout.menu("TEXT_MT_edit_to3d")
290
291
292 class TEXT_MT_toolbox(Menu):
293     bl_label = ""
294
295     def draw(self, context):
296         layout = self.layout
297         layout.operator_context = 'INVOKE_DEFAULT'
298
299         layout.operator("text.cut")
300         layout.operator("text.copy")
301         layout.operator("text.paste")
302
303         layout.separator()
304
305         layout.operator("text.run_script")
306
307 if __name__ == "__main__":  # only for live edit.
308     bpy.utils.register_module(__name__)