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 #include "ED_keymap_templates.h"
57
58 #include "outliner_intern.h"
59
60 /* ************************** registration **********************************/
61
62 void outliner_operatortypes(void)
63 {
64         WM_operatortype_append(OUTLINER_OT_highlight_update);
65         WM_operatortype_append(OUTLINER_OT_item_activate);
66         WM_operatortype_append(OUTLINER_OT_select_border);
67         WM_operatortype_append(OUTLINER_OT_item_openclose);
68         WM_operatortype_append(OUTLINER_OT_item_rename);
69         WM_operatortype_append(OUTLINER_OT_item_drag_drop);
70         WM_operatortype_append(OUTLINER_OT_operation);
71         WM_operatortype_append(OUTLINER_OT_scene_operation);
72         WM_operatortype_append(OUTLINER_OT_object_operation);
73         WM_operatortype_append(OUTLINER_OT_lib_operation);
74         WM_operatortype_append(OUTLINER_OT_lib_relocate);
75         WM_operatortype_append(OUTLINER_OT_id_operation);
76         WM_operatortype_append(OUTLINER_OT_id_delete);
77         WM_operatortype_append(OUTLINER_OT_id_remap);
78         WM_operatortype_append(OUTLINER_OT_data_operation);
79         WM_operatortype_append(OUTLINER_OT_animdata_operation);
80         WM_operatortype_append(OUTLINER_OT_action_set);
81         WM_operatortype_append(OUTLINER_OT_constraint_operation);
82         WM_operatortype_append(OUTLINER_OT_modifier_operation);
83
84         WM_operatortype_append(OUTLINER_OT_show_one_level);
85         WM_operatortype_append(OUTLINER_OT_show_active);
86         WM_operatortype_append(OUTLINER_OT_show_hierarchy);
87         WM_operatortype_append(OUTLINER_OT_scroll_page);
88
89         WM_operatortype_append(OUTLINER_OT_select_all);
90         WM_operatortype_append(OUTLINER_OT_expanded_toggle);
91
92         WM_operatortype_append(OUTLINER_OT_keyingset_add_selected);
93         WM_operatortype_append(OUTLINER_OT_keyingset_remove_selected);
94
95         WM_operatortype_append(OUTLINER_OT_drivers_add_selected);
96         WM_operatortype_append(OUTLINER_OT_drivers_delete_selected);
97
98         WM_operatortype_append(OUTLINER_OT_orphans_purge);
99
100         WM_operatortype_append(OUTLINER_OT_parent_drop);
101         WM_operatortype_append(OUTLINER_OT_parent_clear);
102         WM_operatortype_append(OUTLINER_OT_scene_drop);
103         WM_operatortype_append(OUTLINER_OT_material_drop);
104         WM_operatortype_append(OUTLINER_OT_collection_drop);
105
106         /* collections */
107         WM_operatortype_append(OUTLINER_OT_collection_new);
108         WM_operatortype_append(OUTLINER_OT_collection_duplicate);
109         WM_operatortype_append(OUTLINER_OT_collection_delete);
110         WM_operatortype_append(OUTLINER_OT_collection_objects_select);
111         WM_operatortype_append(OUTLINER_OT_collection_objects_deselect);
112         WM_operatortype_append(OUTLINER_OT_collection_link);
113         WM_operatortype_append(OUTLINER_OT_collection_instance);
114         WM_operatortype_append(OUTLINER_OT_collection_exclude_set);
115         WM_operatortype_append(OUTLINER_OT_collection_exclude_clear);
116         WM_operatortype_append(OUTLINER_OT_collection_holdout_set);
117         WM_operatortype_append(OUTLINER_OT_collection_holdout_clear);
118         WM_operatortype_append(OUTLINER_OT_collection_indirect_only_set);
119         WM_operatortype_append(OUTLINER_OT_collection_indirect_only_clear);
120 }
121
122 void outliner_keymap(wmKeyConfig *keyconf)
123 {
124         wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Outliner", SPACE_OUTLINER, 0);
125         wmKeyMapItem *kmi;
126
127         WM_keymap_add_item(keymap, "OUTLINER_OT_highlight_update", MOUSEMOVE, KM_ANY, KM_ANY, 0);
128
129         WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
130
131         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, 0, 0);
132         RNA_boolean_set(kmi->ptr, "recursive", false);
133         RNA_boolean_set(kmi->ptr, "extend", false);
134
135         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
136         RNA_boolean_set(kmi->ptr, "recursive", false);
137         RNA_boolean_set(kmi->ptr, "extend", true);
138
139         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_CTRL, 0);
140         RNA_boolean_set(kmi->ptr, "recursive", true);
141         RNA_boolean_set(kmi->ptr, "extend", false);
142
143         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, KM_CTRL | KM_SHIFT, 0);
144         RNA_boolean_set(kmi->ptr, "recursive", true);
145         RNA_boolean_set(kmi->ptr, "extend", true);
146
147
148         WM_keymap_add_item(keymap, "OUTLINER_OT_select_border", BKEY, KM_PRESS, 0, 0);
149
150         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, 0, 0);
151         RNA_boolean_set(kmi->ptr, "all", false);
152         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_openclose", RETKEY, KM_PRESS, KM_SHIFT, 0);
153         RNA_boolean_set(kmi->ptr, "all", true);
154
155         WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
156         WM_keymap_add_item(keymap, "OUTLINER_OT_operation", RIGHTMOUSE, KM_PRESS, 0, 0);
157
158         WM_keymap_add_item(keymap, "OUTLINER_OT_item_drag_drop", EVT_TWEAK_L, KM_ANY, 0, 0);
159
160         WM_keymap_add_item(keymap, "OUTLINER_OT_show_hierarchy", HOMEKEY, KM_PRESS, 0, 0);
161
162         WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PERIODKEY, KM_PRESS, 0, 0);
163         WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PADPERIOD, KM_PRESS, 0, 0);
164
165         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEDOWNKEY, KM_PRESS, 0, 0);
166         RNA_boolean_set(kmi->ptr, "up", false);
167         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_scroll_page", PAGEUPKEY, KM_PRESS, 0, 0);
168         RNA_boolean_set(kmi->ptr, "up", true);
169
170         WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADPLUSKEY, KM_PRESS, 0, 0); /* open */
171         kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_show_one_level", PADMINUS, KM_PRESS, 0, 0);
172         RNA_boolean_set(kmi->ptr, "open", false); /* close */
173
174         ED_keymap_template_select_all(keymap, "OUTLINER_OT_select_all");
175
176         WM_keymap_add_item(keymap, "OUTLINER_OT_expanded_toggle", AKEY, KM_PRESS, KM_SHIFT, 0);
177
178         /* keying sets - only for databrowse */
179         WM_keymap_add_item(keymap, "OUTLINER_OT_keyingset_add_selected", KKEY, KM_PRESS, 0, 0);
180         WM_keymap_add_item(keymap, "OUTLINER_OT_keyingset_remove_selected", KKEY, KM_PRESS, KM_ALT, 0);
181
182         WM_keymap_add_item(keymap, "ANIM_OT_keyframe_insert", IKEY, KM_PRESS, 0, 0);
183         WM_keymap_add_item(keymap, "ANIM_OT_keyframe_delete", IKEY, KM_PRESS, KM_ALT, 0);
184
185         /* Note: was D, Alt-D, keep these free for duplicate. */
186         WM_keymap_add_item(keymap, "OUTLINER_OT_drivers_add_selected", DKEY, KM_PRESS, KM_CTRL, 0);
187         WM_keymap_add_item(keymap, "OUTLINER_OT_drivers_delete_selected", DKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
188
189         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_new", CKEY, KM_PRESS, 0, 0);
190
191         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_delete", XKEY, KM_PRESS, 0, 0);
192         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_delete", DELKEY, KM_PRESS, 0, 0);
193
194         WM_keymap_add_item(keymap, "OBJECT_OT_move_to_collection", MKEY, KM_PRESS, 0, 0);
195         WM_keymap_add_item(keymap, "OBJECT_OT_link_to_collection", MKEY, KM_PRESS, KM_SHIFT, 0);
196
197         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_exclude_set", EKEY, KM_PRESS, 0, 0);
198         WM_keymap_add_item(keymap, "OUTLINER_OT_collection_exclude_clear", EKEY, KM_PRESS, KM_ALT, 0);
199
200         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_clear", HKEY, KM_PRESS, KM_ALT, 0);
201         RNA_boolean_set(kmi->ptr, "select", false);
202         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);
203         RNA_boolean_set(kmi->ptr, "unselected", false);
204         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, KM_SHIFT, 0);
205         RNA_boolean_set(kmi->ptr, "unselected", true);
206 }