adding image strips wasnt working, use the 'directory' component of the file selector...
[blender.git] / source / blender / editors / space_buttons / buttons_ops.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2009 Blender Foundation.
21  * All rights reserved.
22  *
23  * Contributor(s): Blender Foundation
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "MEM_guardedalloc.h"
32
33 #include "DNA_userdef_types.h"
34
35 #include "BKE_context.h"
36
37 #include "WM_api.h"
38 #include "WM_types.h"
39
40 #include "ED_screen.h"
41
42 #include "RNA_access.h"
43
44 #include "UI_interface.h"
45
46 #include "buttons_intern.h"     // own include
47
48 /********************** toolbox operator *********************/
49
50 static int toolbox_invoke(bContext *C, wmOperator *op, wmEvent *event)
51 {
52         bScreen *sc= CTX_wm_screen(C);
53         SpaceButs *sbuts= CTX_wm_space_buts(C);
54         PointerRNA ptr;
55         uiPopupMenu *pup;
56         uiLayout *layout;
57
58         RNA_pointer_create(&sc->id, &RNA_SpaceProperties, sbuts, &ptr);
59
60         pup= uiPupMenuBegin(C, "Align", 0);
61         layout= uiPupMenuLayout(pup);
62         uiItemsEnumR(layout, &ptr, "align");
63         uiPupMenuEnd(C, pup);
64
65         return OPERATOR_CANCELLED;
66 }
67
68 void BUTTONS_OT_toolbox(wmOperatorType *ot)
69 {
70         /* identifiers */
71         ot->name= "Toolbox";
72         ot->description="Display button panel toolbox";
73         ot->idname= "BUTTONS_OT_toolbox";
74         
75         /* api callbacks */
76         ot->invoke= toolbox_invoke;
77         ot->poll= ED_operator_buttons_active;
78 }
79
80 /********************** filebrowse operator *********************/
81
82 typedef struct FileBrowseOp {
83         PointerRNA ptr;
84         PropertyRNA *prop;
85 } FileBrowseOp;
86
87 static int file_browse_exec(bContext *C, wmOperator *op)
88 {
89         FileBrowseOp *fbo= op->customdata;
90         char *str;
91         
92         if (RNA_property_is_set(op->ptr, "filepath")==0 || fbo==NULL)
93                 return OPERATOR_CANCELLED;
94         
95         str= RNA_string_get_alloc(op->ptr, "filepath", 0, 0);
96         RNA_property_string_set(&fbo->ptr, fbo->prop, str);
97         RNA_property_update(C, &fbo->ptr, fbo->prop);
98         MEM_freeN(str);
99
100         MEM_freeN(op->customdata);
101         return OPERATOR_FINISHED;
102 }
103
104 static int file_browse_cancel(bContext *C, wmOperator *op)
105 {
106         MEM_freeN(op->customdata);
107         op->customdata= NULL;
108
109         return OPERATOR_CANCELLED;
110 }
111
112 static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event)
113 {
114         PointerRNA ptr;
115         PropertyRNA *prop;
116         FileBrowseOp *fbo;
117         char *str;
118
119         uiFileBrowseContextProperty(C, &ptr, &prop);
120
121         if(!prop)
122                 return OPERATOR_CANCELLED;
123         
124         fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
125         fbo->ptr= ptr;
126         fbo->prop= prop;
127         op->customdata= fbo;
128
129         str= RNA_property_string_get_alloc(&ptr, prop, 0, 0);
130         RNA_string_set(op->ptr, "filepath", str);
131         MEM_freeN(str);
132
133         if(RNA_struct_find_property(op->ptr, "relative_path"))
134                 if(!RNA_property_is_set(op->ptr, "relative_path"))
135                         RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
136
137         WM_event_add_fileselect(C, op); 
138         
139         return OPERATOR_RUNNING_MODAL;
140 }
141
142 void BUTTONS_OT_file_browse(wmOperatorType *ot)
143 {
144         /* identifiers */
145         ot->name= "Accept";
146         ot->description="Open a file browser";
147         ot->idname= "BUTTONS_OT_file_browse";
148         
149         /* api callbacks */
150         ot->invoke= file_browse_invoke;
151         ot->exec= file_browse_exec;
152         ot->cancel= file_browse_cancel;
153
154         /* properties */
155         WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH);
156 }
157