Step 3 for the initial commits for 2.5: removing src/ and python,
[blender-staging.git] / source / blender / windowmanager / intern / wm_operators.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2007 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30
31 #include "DNA_windowmanager_types.h"
32
33 #include "MEM_guardedalloc.h"
34
35 #include "BLI_blenlib.h"
36
37 #include "BKE_blender.h"
38 #include "BKE_global.h"
39 #include "BKE_library.h"
40 #include "BKE_main.h"
41
42 #include "BIF_toolbox.h"
43
44 #include "WM_api.h"
45 #include "WM_types.h"
46 #include "wm_window.h"
47 #include "wm_event_system.h"
48
49 static ListBase global_ops= {NULL, NULL};
50
51 /* ************ operator API, exported ********** */
52
53 wmOperatorType *WM_operatortype_find(const char *idname)
54 {
55         wmOperatorType *ot;
56         
57         for(ot= global_ops.first; ot; ot= ot->next) {
58                 if(strncmp(ot->idname, idname, OP_MAX_TYPENAME)==0)
59                    return ot;
60         }
61         return NULL;
62 }
63
64 /* ************ default ops, exported *********** */
65
66 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
67 {
68 //      if(okee(op->type->name)) {
69 //              return op->type->exec(C, op);
70 //      }
71         return 0;
72 }
73 int WM_operator_winactive(bContext *C)
74 {
75         if(C->window==NULL) return 0;
76         return 1;
77 }
78
79 /* ************ window / screen operator definitions ************** */
80
81 static void WM_OT_window_duplicate(wmOperatorType *ot)
82 {
83         ot->name= "Duplicate Window";
84         ot->idname= "WM_OT_window_duplicate";
85         
86         ot->interactive= NULL; //WM_operator_confirm;
87         ot->exec= wm_window_duplicate_op;
88         ot->poll= WM_operator_winactive;
89 }
90
91 static void WM_OT_save_homefile(wmOperatorType *ot)
92 {
93         ot->name= "Save User Settings";
94         ot->idname= "WM_OT_save_homefile";
95         
96         ot->interactive= NULL; //WM_operator_confirm;
97         ot->exec= WM_write_homefile;
98         ot->poll= WM_operator_winactive;
99         
100         ot->flag= OPTYPE_REGISTER;
101 }
102
103
104
105 #define ADD_OPTYPE(opfunc)      ot= MEM_callocN(sizeof(wmOperatorType), "operatortype"); \
106                                                         opfunc(ot);  \
107                                                         BLI_addtail(&global_ops, ot)
108
109
110 /* called on initialize WM_exit() */
111 void wm_operatortype_free(void)
112 {
113         BLI_freelistN(&global_ops);
114 }
115
116 /* called on initialize WM_init() */
117 void wm_operatortype_init(void)
118 {
119         wmOperatorType *ot;
120         
121         ADD_OPTYPE(WM_OT_window_duplicate);
122         ADD_OPTYPE(WM_OT_save_homefile);
123 }
124
125