Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_outliner / outliner_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_outliner/outliner_ops.c
28  *  \ingroup spoutliner
29  */
30
31 #include "MEM_guardedalloc.h"
32
33 #include "BLI_listbase.h"
34 #include "BLI_math.h"
35
36 #include "DNA_collection_types.h"
37
38 #include "BLT_translation.h"
39
40 #include "BKE_context.h"
41 #include "BKE_main.h"
42
43 #include "GPU_immediate.h"
44 #include "GPU_state.h"
45
46 #include "RNA_access.h"
47
48 #include "UI_interface.h"
49 #include "UI_view2d.h"
50
51 #include "WM_api.h"
52 #include "WM_types.h"
53
54 #include "ED_screen.h"
55 #include "ED_select_utils.h"
56
57 #include "outliner_intern.h"
58
59 /* ************************** registration **********************************/
60
61 void outliner_operatortypes(void)
62 {
63         WM_operatortype_append(OUTLINER_OT_highlight_update);
64         WM_operatortype_append(OUTLINER_OT_item_activate);
65         WM_operatortype_append(OUTLINER_OT_select_border);
66         WM_operatortype_append(OUTLINER_OT_item_openclose);
67         WM_operatortype_append(OUTLINER_OT_item_rename);
68         WM_operatortype_append(OUTLINER_OT_item_drag_drop);
69         WM_operatortype_append(OUTLINER_OT_operation);
70         WM_operatortype_append(OUTLINER_OT_scene_operation);
71         WM_operatortype_append(OUTLINER_OT_object_operation);
72         WM_operatortype_append(OUTLINER_OT_lib_operation);
73         WM_operatortype_append(OUTLINER_OT_lib_relocate);
74         WM_operatortype_append(OUTLINER_OT_id_operation);
75         WM_operatortype_append(OUTLINER_OT_id_delete);
76         WM_operatortype_append(OUTLINER_OT_id_remap);
77         WM_operatortype_append(OUTLINER_OT_data_operation);
78         WM_operatortype_append(OUTLINER_OT_animdata_operation);
79         WM_operatortype_append(OUTLINER_OT_action_set);
80         WM_operatortype_append(OUTLINER_OT_constraint_operation);
81         WM_operatortype_append(OUTLINER_OT_modifier_operation);
82
83         WM_operatortype_append(OUTLINER_OT_show_one_level);
84         WM_operatortype_append(OUTLINER_OT_show_active);
85         WM_operatortype_append(OUTLINER_OT_show_hierarchy);
86         WM_operatortype_append(OUTLINER_OT_scroll_page);
87
88         WM_operatortype_append(OUTLINER_OT_select_all);
89         WM_operatortype_append(OUTLINER_OT_expanded_toggle);
90
91         WM_operatortype_append(OUTLINER_OT_keyingset_add_selected);
92         WM_operatortype_append(OUTLINER_OT_keyingset_remove_selected);
93
94         WM_operatortype_append(OUTLINER_OT_drivers_add_selected);
95         WM_operatortype_append(OUTLINER_OT_drivers_delete_selected);
96
97         WM_operatortype_append(OUTLINER_OT_orphans_purge);
98
99         WM_operatortype_append(OUTLINER_OT_parent_drop);
100         WM_operatortype_append(OUTLINER_OT_parent_clear);
101         WM_operatortype_append(OUTLINER_OT_scene_drop);
102         WM_operatortype_append(OUTLINER_OT_material_drop);
103         WM_operatortype_append(OUTLINER_OT_collection_drop);
104
105         /* collections */
106         WM_operatortype_append(OUTLINER_OT_collection_new);
107         WM_operatortype_append(OUTLINER_OT_collection_duplicate);
108         WM_operatortype_append(OUTLINER_OT_collection_delete);
109         WM_operatortype_append(OUTLINER_OT_collection_objects_select);
110         WM_operatortype_append(OUTLINER_OT_collection_objects_deselect);
111         WM_operatortype_append(OUTLINER_OT_collection_link);
112         WM_operatortype_append(OUTLINER_OT_collection_instance);
113         WM_operatortype_append(OUTLINER_OT_collection_exclude_set);
114         WM_operatortype_append(OUTLINER_OT_collection_exclude_clear);
115         WM_operatortype_append(OUTLINER_OT_collection_holdout_set);
116         WM_operatortype_append(OUTLINER_OT_collection_holdout_clear);
117         WM_operatortype_append(OUTLINER_OT_collection_indirect_only_set);
118         WM_operatortype_append(OUTLINER_OT_collection_indirect_only_clear);
119 }
120
121 void outliner_keymap(wmKeyConfig *keyconf)
122 {
123         wmKeyMap *keymap = WM_keymap_find(keyconf, "Outliner", SPACE_OUTLINER, 0);
124         wmKeyMapItem *kmi;
125
126         WM_keymap_add_item(keymap, "OUTLINER_OT_highlight_update", MOUSEMOVE, KM_ANY, KM_ANY, 0);
127
128         WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
129
130         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, 0, 0);
131         RNA_boolean_set(kmi->ptr, "recursive", false);
132         RNA_boolean_set(kmi->ptr, "extend", false);
133
134         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
135         RNA_boolean_set(kmi->ptr, "recursive", false);
136         RNA_boolean_set(kmi->ptr, "extend", true);
137
138         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_CTRL, 0);
139         RNA_boolean_set(kmi->ptr, "recursive", true);
140         RNA_boolean_set(kmi->ptr, "extend", false);
141
142         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_CTRL | KM_SHIFT, 0);
143         RNA_boolean_set(kmi->ptr, "recursive", true);
144         RNA_boolean_set(kmi->ptr, "extend", true);
145
146
147         WM_keymap_add_item(keymap, "OUTLINER_OT_select_border", BKEY, KM_PRESS, 0, 0);
148
149         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, 0, 0);
150         RNA_boolean_set(kmi->ptr, "all", false);
151         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, KM_SHIFT, 0);
152         RNA_boolean_set(kmi->ptr, "all", true);
153
154         WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
155         WM_keymap_add_item(keymap, "OUTLINER_OT_operation", RIGHTMOUSE, KM_PRESS, 0, 0);
156
157         WM_keymap_add_item(keymap, "OUTLINER_OT_item_drag_drop", EVT_TWEAK_L, KM_ANY, 0, 0);
158
159         WM_keymap_add_item(keymap, "OUTLINER_OT_show_hierarchy", HOMEKEY, KM_PRESS, 0, 0);
160
161         WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PERIODKEY, KM_PRESS, 0, 0);
162         WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PADPERIOD, KM_PRESS, 0, 0);
163
164         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEDOWNKEY, KM_PRESS, 0, 0);
165         RNA_boolean_set(kmi->ptr, "up", false);
166         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEUPKEY, KM_PRESS, 0, 0);
167         RNA_boolean_set(kmi->ptr, "up", true);
168
169         WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADPLUSKEY, KM_PRESS, 0, 0); /* open */
170         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADMINUS, KM_PRESS, 0, 0);
171         RNA_boolean_set(kmi->ptr, "open", false); /* close */
172
173         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_select_all", AKEY, KM_PRESS, 0, 0);
174         RNA_enum_set(kmi->ptr, "action", SEL_SELECT);
175         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_select_all", AKEY, KM_PRESS, KM_ALT, 0);
176         RNA_enum_set(kmi->ptr, "action", SEL_DESELECT);
177         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
178         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
179
180         WM_keymap_add_item(keymap, "OUTLINER_OT_expanded_toggle", AKEY, KM_PRESS, KM_SHIFT, 0);
181
182         /* keying sets - only for databrowse */
183         WM_keymap_add_item(keymap, "OUTLINER_OT_keyingset_add_selected", KKEY, KM_PRESS, 0, 0);
184         WM_keymap_add_item(keymap, "OUTLINER_OT_keyingset_remove_selected", KKEY, KM_PRESS, KM_ALT, 0);
185
186         WM_keymap_add_item(keymap, "ANIM_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
187         WM_keymap_add_item(keymap, "ANIM_OT_keyframe_delete", IKEY, KM_PRESS, KM_ALT, 0);
188
189         /* Note: was D, Alt-D, keep these free for duplicate. */
190         WM_keymap_add_item(keymap, "OUTLINER_OT_drivers_add_selected", DKEY, KM_PRESS, KM_CTRL, 0);
191         WM_keymap_add_item(keymap, "OUTLINER_OT_drivers_delete_selected", DKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
192
193         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_new", CKEY, KM_PRESS, 0, 0);
194
195         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_delete", XKEY, KM_PRESS, 0, 0);
196         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_delete", DELKEY, KM_PRESS, 0, 0);
197
198         WM_keymap_add_item(keymap, "OBJECT_OT_move_to_collection", MKEY, KM_PRESS, 0, 0);
199         WM_keymap_add_item(keymap, "OBJECT_OT_link_to_collection", MKEY, KM_PRESS, KM_SHIFT, 0);
200
201         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_exclude_set", EKEY, KM_PRESS, 0, 0);
202         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_exclude_clear", EKEY, KM_PRESS, KM_ALT, 0);
203
204         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_clear", HKEY, KM_PRESS, KM_ALT, 0);
205         RNA_boolean_set(kmi->ptr, "select", false);
206         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);
207         RNA_boolean_set(kmi->ptr, "unselected", false);
208         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, KM_SHIFT, 0);
209         RNA_boolean_set(kmi->ptr, "unselected", true);
210 }