Bugfix [#26792] blender crash when scaling action strip in NLA
[blender.git] / release / scripts / startup / bl_ui / space_nla.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 compliant>
20
21 import bpy
22
23
24 class NLA_HT_header(bpy.types.Header):
25     bl_space_type = 'NLA_EDITOR'
26
27     def draw(self, context):
28         from bl_ui.space_dopesheet import dopesheet_filter
29
30         layout = self.layout
31
32         st = context.space_data
33
34         row = layout.row(align=True)
35         row.template_header()
36
37         if context.area.show_menus:
38             sub = row.row(align=True)
39
40             sub.menu("NLA_MT_view")
41             sub.menu("NLA_MT_select")
42             sub.menu("NLA_MT_marker")
43             sub.menu("NLA_MT_edit")
44             sub.menu("NLA_MT_add")
45
46         dopesheet_filter(layout, context)
47
48         layout.prop(st, "auto_snap", text="")
49
50
51 class NLA_MT_view(bpy.types.Menu):
52     bl_label = "View"
53
54     def draw(self, context):
55         layout = self.layout
56
57         st = context.space_data
58
59         layout.column()
60
61         layout.operator("nla.properties", icon='MENU_PANEL')
62
63         layout.separator()
64
65         layout.prop(st, "use_realtime_update")
66         layout.prop(st, "show_frame_indicator")
67
68         layout.operator("anim.time_toggle", text="Show Frames" if st.show_seconds else "Show Seconds")
69
70         layout.prop(st, "show_strip_curves")
71
72         layout.separator()
73         layout.operator("anim.previewrange_set")
74         layout.operator("anim.previewrange_clear")
75
76         layout.separator()
77         layout.operator("screen.area_dupli")
78         layout.operator("screen.screen_full_area")
79
80
81 class NLA_MT_select(bpy.types.Menu):
82     bl_label = "Select"
83
84     def draw(self, context):
85         layout = self.layout
86
87         layout.column()
88         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
89         layout.operator("nla.select_all_toggle")
90         layout.operator("nla.select_all_toggle", text="Invert Selection").invert = True
91
92         layout.separator()
93         layout.operator("nla.select_border")
94         layout.operator("nla.select_border", text="Border Axis Range").axis_range = True
95
96         layout.separator()
97         layout.operator("nla.select_leftright", text="Before Current Frame").mode = 'LEFT'
98         layout.operator("nla.select_leftright", text="After Current Frame").mode = 'RIGHT'
99
100
101 class NLA_MT_marker(bpy.types.Menu):
102     bl_label = "Marker"
103
104     def draw(self, context):
105         layout = self.layout
106
107         #layout.operator_context = 'EXEC_REGION_WIN'
108
109         layout.column()
110         layout.operator("marker.add", "Add Marker")
111         layout.operator("marker.duplicate", text="Duplicate Marker")
112         layout.operator("marker.delete", text="Delete Marker")
113
114         layout.separator()
115
116         layout.operator("marker.rename", text="Rename Marker")
117         layout.operator("marker.move", text="Grab/Move Marker")
118
119
120 class NLA_MT_edit(bpy.types.Menu):
121     bl_label = "Edit"
122
123     def draw(self, context):
124         layout = self.layout
125
126         scene = context.scene
127
128         layout.column()
129         layout.menu("NLA_MT_edit_transform", text="Transform")
130
131         layout.operator_menu_enum("nla.snap", "type", text="Snap")
132
133         layout.separator()
134         layout.operator("nla.duplicate")
135         layout.operator("nla.split")
136         layout.operator("nla.delete")
137
138         layout.separator()
139         layout.operator("nla.mute_toggle")
140
141         layout.separator()
142         layout.operator("nla.apply_scale")
143         layout.operator("nla.clear_scale")
144         layout.operator("nla.action_sync_length").active = False
145
146         layout.separator()
147         layout.operator("nla.swap")
148         layout.operator("nla.move_up")
149         layout.operator("nla.move_down")
150
151         # TODO: this really belongs more in a "channel" (or better, "track") menu
152         layout.separator()
153         layout.operator_menu_enum("anim.channels_move", "direction", text="Track Ordering...")
154
155         layout.separator()
156         # TODO: names of these tools for 'tweakmode' need changing?
157         if scene.is_nla_tweakmode:
158             layout.operator("nla.tweakmode_exit", text="Stop Tweaking Strip Actions")
159         else:
160             layout.operator("nla.tweakmode_enter", text="Start Tweaking Strip Actions")
161
162
163 class NLA_MT_add(bpy.types.Menu):
164     bl_label = "Add"
165
166     def draw(self, context):
167         layout = self.layout
168
169         layout.column()
170         layout.operator("nla.actionclip_add")
171         layout.operator("nla.transition_add")
172
173         layout.separator()
174         layout.operator("nla.meta_add")
175         layout.operator("nla.meta_remove")
176
177         layout.separator()
178         layout.operator("nla.tracks_add")
179         layout.operator("nla.tracks_add", text="Add Tracks Above Selected").above_selected = True
180
181
182 class NLA_MT_edit_transform(bpy.types.Menu):
183     bl_label = "Transform"
184
185     def draw(self, context):
186         layout = self.layout
187
188         layout.column()
189         layout.operator("transform.translate", text="Grab/Move")
190         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
191         layout.operator("transform.transform", text="Scale").mode= 'TIME_SCALE'
192
193 if __name__ == "__main__":  # only for live edit.
194     bpy.utils.register_module(__name__)