style cleanup, brackets in else/if, some indentation.
[blender.git] / source / blender / editors / space_file / space_file.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_file/space_file.c
28  *  \ingroup spfile
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35
36 #include "RNA_access.h"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BIF_gl.h"
41
42 #include "BLO_readfile.h"
43
44 #include "BLI_blenlib.h"
45 #include "BLI_math.h"
46 #include "BLI_rand.h"
47 #include "BLI_utildefines.h"
48
49 #include "BKE_context.h"
50 #include "BKE_screen.h"
51
52 #include "ED_space_api.h"
53 #include "ED_screen.h"
54 #include "ED_fileselect.h"
55
56 #include "IMB_imbuf_types.h"
57 #include "IMB_thumbs.h"
58
59 #include "WM_api.h"
60 #include "WM_types.h"
61
62 #include "UI_resources.h"
63 #include "UI_view2d.h"
64
65
66 #include "file_intern.h"        // own include
67 #include "fsmenu.h"
68 #include "filelist.h"
69
70 /* ******************** default callbacks for file space ***************** */
71
72 static SpaceLink *file_new(const bContext *UNUSED(C))
73 {
74         ARegion *ar;
75         SpaceFile *sfile;
76         
77         sfile= MEM_callocN(sizeof(SpaceFile), "initfile");
78         sfile->spacetype= SPACE_FILE;
79
80         /* header */
81         ar= MEM_callocN(sizeof(ARegion), "header for file");
82         BLI_addtail(&sfile->regionbase, ar);
83         ar->regiontype= RGN_TYPE_HEADER;
84         ar->alignment= RGN_ALIGN_TOP;
85
86         /* channel list region */
87         ar= MEM_callocN(sizeof(ARegion), "channel area for file");
88         BLI_addtail(&sfile->regionbase, ar);
89         ar->regiontype= RGN_TYPE_CHANNELS;
90         ar->alignment= RGN_ALIGN_LEFT;  
91
92         /* ui list region */
93         ar= MEM_callocN(sizeof(ARegion), "ui area for file");
94         BLI_addtail(&sfile->regionbase, ar);
95         ar->regiontype= RGN_TYPE_UI;
96         ar->alignment= RGN_ALIGN_TOP;
97
98         /* main area */
99         ar= MEM_callocN(sizeof(ARegion), "main area for file");
100         BLI_addtail(&sfile->regionbase, ar);
101         ar->regiontype= RGN_TYPE_WINDOW;
102         ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
103         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
104         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
105         ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
106         ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
107
108         return (SpaceLink *)sfile;
109 }
110
111 /* not spacelink itself */
112 static void file_free(SpaceLink *sl)
113 {       
114         SpaceFile *sfile= (SpaceFile *) sl;
115         
116         if(sfile->files) {
117                 // XXXXX would need to do thumbnails_stop here, but no context available
118                 filelist_freelib(sfile->files);
119                 filelist_free(sfile->files);
120                 MEM_freeN(sfile->files);
121                 sfile->files= NULL;
122         }
123
124         if(sfile->folders_prev) {
125                 folderlist_free(sfile->folders_prev);
126                 MEM_freeN(sfile->folders_prev);
127                 sfile->folders_prev= NULL;
128         }
129
130         if(sfile->folders_next) {
131                 folderlist_free(sfile->folders_next);
132                 MEM_freeN(sfile->folders_next);
133                 sfile->folders_next= NULL;
134         }
135
136         if (sfile->params) {
137                 MEM_freeN(sfile->params);
138                 sfile->params= NULL;
139         }
140
141         if (sfile->layout) {
142                 MEM_freeN(sfile->layout);
143                 sfile->layout = NULL;
144         }
145 }
146
147
148 /* spacetype; init callback, area size changes, screen set, etc */
149 static void file_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
150 {
151         SpaceFile *sfile= (SpaceFile*)sa->spacedata.first;
152         //printf("file_init\n");
153
154         if(sfile->layout) sfile->layout->dirty= TRUE;
155 }
156
157
158 static SpaceLink *file_duplicate(SpaceLink *sl)
159 {
160         SpaceFile *sfileo= (SpaceFile*)sl;
161         SpaceFile *sfilen= MEM_dupallocN(sl);
162         
163         /* clear or remove stuff from old */
164         sfilen->op = NULL; /* file window doesn't own operators */
165
166         if (sfileo->params) {
167                 sfilen->files = filelist_new(sfileo->params->type);
168                 sfilen->params= MEM_dupallocN(sfileo->params);
169                 filelist_setdir(sfilen->files, sfilen->params->dir);
170         }
171
172         if(sfileo->folders_prev)
173                 sfilen->folders_prev = folderlist_duplicate(sfileo->folders_prev);
174
175         if(sfileo->folders_next)
176                 sfilen->folders_next = folderlist_duplicate(sfileo->folders_next);
177         
178         if (sfileo->layout) {
179                 sfilen->layout= MEM_dupallocN(sfileo->layout);
180         }
181         return (SpaceLink *)sfilen;
182 }
183
184 static void file_refresh(const bContext *C, ScrArea *UNUSED(sa))
185 {
186         SpaceFile *sfile= CTX_wm_space_file(C);
187         FileSelectParams *params = ED_fileselect_get_params(sfile);
188
189         if (!sfile->folders_prev)
190                 sfile->folders_prev = folderlist_new();
191         if (!sfile->files) {
192                 sfile->files = filelist_new(params->type);
193                 filelist_setdir(sfile->files, params->dir);
194                 params->active_file = -1; // added this so it opens nicer (ton)
195         }
196         filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT);
197         filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0);      
198         filelist_setfilter_types(sfile->files, params->filter_glob);
199
200         if (filelist_empty(sfile->files)) {
201                 thumbnails_stop(sfile->files, C);
202                 filelist_readdir(sfile->files);
203                 if(params->sort!=FILE_SORT_NONE) {
204                         filelist_sort(sfile->files, params->sort);
205                 }
206                 BLI_strncpy(params->dir, filelist_dir(sfile->files), FILE_MAX);
207                 if(params->display == FILE_IMGDISPLAY) {
208                         thumbnails_start(sfile->files, C);
209                 }
210         } else {
211                 if(params->sort!=FILE_SORT_NONE) {
212                         thumbnails_stop(sfile->files, C);
213                         filelist_sort(sfile->files, params->sort);
214                         if(params->display == FILE_IMGDISPLAY) {
215                                 thumbnails_start(sfile->files, C);
216                         }
217                 } else {
218                         if(params->display == FILE_IMGDISPLAY) {
219                                 if (!thumbnails_running(sfile->files,C)) {
220                                         thumbnails_start(sfile->files, C);
221                                 }
222                         } else {
223                                 /* stop any running thumbnail jobs if we're not 
224                                  * displaying them - speedup for NFS */
225                                 thumbnails_stop(sfile->files, C);
226                         }
227                         filelist_filter(sfile->files);
228                 }
229         }
230         
231         if (params->renamefile[0] != '\0') {
232                 int idx = filelist_find(sfile->files, params->renamefile);
233                 if (idx >= 0) {
234                         struct direntry *file= filelist_file(sfile->files, idx);
235                         if (file) {
236                                 file->selflag |= EDITING_FILE;
237                         }
238                 }
239                 BLI_strncpy(sfile->params->renameedit, sfile->params->renamefile, sizeof(sfile->params->renameedit));
240                 params->renamefile[0] = '\0';
241         }
242         if (sfile->layout) sfile->layout->dirty= TRUE;
243
244 }
245
246 static void file_listener(ScrArea *sa, wmNotifier *wmn)
247 {
248         /* SpaceFile* sfile = (SpaceFile*)sa->spacedata.first; */
249
250         /* context changes */
251         switch(wmn->category) {
252                 case NC_SPACE:
253                         switch (wmn->data) {
254                                 case ND_SPACE_FILE_LIST:
255                                         ED_area_tag_refresh(sa);
256                                         ED_area_tag_redraw(sa);
257                                         break;
258                                 case ND_SPACE_FILE_PARAMS:
259                                         ED_area_tag_refresh(sa);
260                                         ED_area_tag_redraw(sa);
261                                         break;
262                         }
263                         break;
264         }
265 }
266
267 /* add handlers, stuff you only do once or on area/region changes */
268 static void file_main_area_init(wmWindowManager *wm, ARegion *ar)
269 {
270         wmKeyMap *keymap;
271         
272         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
273         
274         /* own keymaps */
275         keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0);
276         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
277
278         keymap= WM_keymap_find(wm->defaultconf, "File Browser Main", SPACE_FILE, 0);
279         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
280                                                            
281
282 }
283
284 static void file_main_area_listener(ARegion *ar, wmNotifier *wmn)
285 {
286         /* context changes */
287         switch(wmn->category) {
288                 case NC_SPACE:
289                         switch (wmn->data) {
290                                 case ND_SPACE_FILE_LIST:
291                                         ED_region_tag_redraw(ar);
292                                         break;
293                                 case ND_SPACE_FILE_PARAMS:
294                                         ED_region_tag_redraw(ar);
295                                         break;
296                         }
297                         break;
298         }
299 }
300
301 static void file_main_area_draw(const bContext *C, ARegion *ar)
302 {
303         /* draw entirely, view changes should be handled here */
304         SpaceFile *sfile= CTX_wm_space_file(C);
305         FileSelectParams *params = ED_fileselect_get_params(sfile);
306         FileLayout *layout=NULL;
307
308         View2D *v2d= &ar->v2d;
309         View2DScrollers *scrollers;
310         float col[3];
311
312         /* Needed, because filelist is not initialized on loading */
313         if (!sfile->files || filelist_empty(sfile->files))
314                 file_refresh(C, NULL);
315
316         layout = ED_fileselect_get_layout(sfile, ar);
317
318         /* clear and setup matrix */
319         UI_GetThemeColor3fv(TH_BACK, col);
320         glClearColor(col[0], col[1], col[2], 0.0);
321         glClear(GL_COLOR_BUFFER_BIT);
322         
323         /* Allow dynamically sliders to be set, saves notifiers etc. */
324         if (layout && (layout->flag == FILE_LAYOUT_VER)) {
325                 v2d->scroll = V2D_SCROLL_RIGHT;
326                 v2d->keepofs &= ~V2D_LOCKOFS_Y;
327                 v2d->keepofs |= V2D_LOCKOFS_X;
328         }
329         else {
330                 v2d->scroll = V2D_SCROLL_BOTTOM;
331                 v2d->keepofs &= ~V2D_LOCKOFS_X;
332                 v2d->keepofs |= V2D_LOCKOFS_Y;
333                 
334                 /* XXX this happens on scaling down Screen (like from startup.blend) */
335                 /* view2d has no type specific for filewindow case, which doesnt scroll vertically */
336                 if(v2d->cur.ymax < 0) {
337                         v2d->cur.ymin -= v2d->cur.ymax;
338                         v2d->cur.ymax= 0;
339                 }
340         }
341         /* v2d has initialized flag, so this call will only set the mask correct */
342         UI_view2d_region_reinit(v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
343
344         /* sets tile/border settings in sfile */
345         file_calc_previews(C, ar);
346
347         /* set view */
348         UI_view2d_view_ortho(v2d);
349         
350         /* on first read, find active file */
351         if (params->active_file == -1) {
352                 wmEvent *event= CTX_wm_window(C)->eventstate;
353                 file_hilight_set(sfile, ar, event->x, event->y);
354         }
355         
356         file_draw_list(C, ar);
357         
358         /* reset view matrix */
359         UI_view2d_view_restore(C);
360         
361         /* scrollers */
362         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
363         UI_view2d_scrollers_draw(C, v2d, scrollers);
364         UI_view2d_scrollers_free(scrollers);
365
366 }
367
368 static void file_operatortypes(void)
369 {
370         WM_operatortype_append(FILE_OT_select);
371         WM_operatortype_append(FILE_OT_select_all_toggle);
372         WM_operatortype_append(FILE_OT_select_border);
373         WM_operatortype_append(FILE_OT_select_bookmark);
374         WM_operatortype_append(FILE_OT_highlight);
375         WM_operatortype_append(FILE_OT_execute);
376         WM_operatortype_append(FILE_OT_cancel);
377         WM_operatortype_append(FILE_OT_parent);
378         WM_operatortype_append(FILE_OT_previous);
379         WM_operatortype_append(FILE_OT_next);
380         WM_operatortype_append(FILE_OT_refresh);
381         WM_operatortype_append(FILE_OT_bookmark_toggle);
382         WM_operatortype_append(FILE_OT_bookmark_add);
383         WM_operatortype_append(FILE_OT_delete_bookmark);
384         WM_operatortype_append(FILE_OT_hidedot);
385         WM_operatortype_append(FILE_OT_filenum);
386         WM_operatortype_append(FILE_OT_directory_new);
387         WM_operatortype_append(FILE_OT_delete);
388         WM_operatortype_append(FILE_OT_rename);
389         WM_operatortype_append(FILE_OT_smoothscroll);
390         WM_operatortype_append(FILE_OT_directory);
391 }
392
393 /* NOTE: do not add .blend file reading on this level */
394 static void file_keymap(struct wmKeyConfig *keyconf)
395 {
396         wmKeyMapItem *kmi;
397         /* keys for all areas */
398         wmKeyMap *keymap= WM_keymap_find(keyconf, "File Browser", SPACE_FILE, 0);
399         WM_keymap_add_item(keymap, "FILE_OT_bookmark_toggle", NKEY, KM_PRESS, 0, 0);
400         WM_keymap_add_item(keymap, "FILE_OT_parent", PKEY, KM_PRESS, 0, 0);
401         WM_keymap_add_item(keymap, "FILE_OT_bookmark_add", BKEY, KM_PRESS, KM_CTRL, 0);
402         WM_keymap_add_item(keymap, "FILE_OT_hidedot", HKEY, KM_PRESS, 0, 0);
403         WM_keymap_add_item(keymap, "FILE_OT_previous", BACKSPACEKEY, KM_PRESS, 0, 0);
404         WM_keymap_add_item(keymap, "FILE_OT_next", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0);
405         WM_keymap_add_item(keymap, "FILE_OT_directory_new", IKEY, KM_PRESS, 0, 0);  /* XXX needs button */
406         WM_keymap_add_item(keymap, "FILE_OT_delete", XKEY, KM_PRESS, 0, 0);
407         WM_keymap_add_item(keymap, "FILE_OT_delete", DELKEY, KM_PRESS, 0, 0);
408         WM_keymap_verify_item(keymap, "FILE_OT_smoothscroll", TIMER1, KM_ANY, KM_ANY, 0);
409
410         /* keys for main area */
411         keymap= WM_keymap_find(keyconf, "File Browser Main", SPACE_FILE, 0);
412         kmi= WM_keymap_add_item(keymap, "FILE_OT_execute", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
413         RNA_boolean_set(kmi->ptr, "need_active", TRUE);
414         WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, 0, 0);
415         kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
416         RNA_boolean_set(kmi->ptr, "extend", TRUE);
417         kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0);
418         RNA_boolean_set(kmi->ptr, "extend", TRUE);
419         RNA_boolean_set(kmi->ptr, "fill", TRUE);
420         WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
421         WM_keymap_add_item(keymap, "FILE_OT_refresh", PADPERIOD, KM_PRESS, 0, 0);
422         WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0);
423         WM_keymap_add_item(keymap, "FILE_OT_select_border", EVT_TWEAK_L, KM_ANY, 0, 0);
424         WM_keymap_add_item(keymap, "FILE_OT_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
425         WM_keymap_add_item(keymap, "FILE_OT_highlight", MOUSEMOVE, KM_ANY, KM_ANY, 0);
426         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0);
427         RNA_int_set(kmi->ptr, "increment", 1);
428         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0);
429         RNA_int_set(kmi->ptr, "increment", 10);
430         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
431         RNA_int_set(kmi->ptr, "increment", 100);
432         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0,0);
433         RNA_int_set(kmi->ptr, "increment", -1);
434         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT, 0);
435         RNA_int_set(kmi->ptr, "increment", -10);
436         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL, 0);
437         RNA_int_set(kmi->ptr, "increment",-100);
438         
439         
440         /* keys for button area (top) */
441         keymap= WM_keymap_find(keyconf, "File Browser Buttons", SPACE_FILE, 0);
442         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0);
443         RNA_int_set(kmi->ptr, "increment", 1);
444         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0);
445         RNA_int_set(kmi->ptr, "increment", 10);
446         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
447         RNA_int_set(kmi->ptr, "increment", 100);
448         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0, 0);
449         RNA_int_set(kmi->ptr, "increment", -1);
450         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT,0);
451         RNA_int_set(kmi->ptr, "increment", -10);
452         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL,0);
453         RNA_int_set(kmi->ptr, "increment",-100);
454 }
455
456
457 static void file_channel_area_init(wmWindowManager *wm, ARegion *ar)
458 {
459         wmKeyMap *keymap;
460
461         ED_region_panels_init(wm, ar);
462
463         /* own keymaps */
464         keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0); 
465         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
466 }
467
468 static void file_channel_area_draw(const bContext *C, ARegion *ar)
469 {
470         ED_region_panels(C, ar, 1, NULL, -1);
471 }
472
473 static void file_channel_area_listener(ARegion *UNUSED(ar), wmNotifier *wmn)
474 {
475         /* context changes */
476         switch(wmn->category) {
477                 
478         }
479 }
480
481 /* add handlers, stuff you only do once or on area/region changes */
482 static void file_header_area_init(wmWindowManager *wm, ARegion *ar)
483 {
484         wmKeyMap *keymap;
485         
486         ED_region_header_init(ar);
487         
488         keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0); 
489         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
490 }
491
492 static void file_header_area_draw(const bContext *C, ARegion *ar)
493 {
494         ED_region_header(C, ar);
495 }
496
497 /* add handlers, stuff you only do once or on area/region changes */
498 static void file_ui_area_init(wmWindowManager *wm, ARegion *ar)
499 {
500         wmKeyMap *keymap;
501
502         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
503
504         /* own keymap */
505         keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0);
506         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
507
508         keymap= WM_keymap_find(wm->defaultconf, "File Browser Buttons", SPACE_FILE, 0);
509         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
510 }
511
512 static void file_ui_area_draw(const bContext *C, ARegion *ar)
513 {
514         float col[3];
515         /* clear */
516         UI_GetThemeColor3fv(TH_PANEL, col);
517         glClearColor(col[0], col[1], col[2], 0.0);
518         glClear(GL_COLOR_BUFFER_BIT);
519
520         /* scrolling here is just annoying, disable it */
521         ar->v2d.cur.ymax= ar->v2d.cur.ymax - ar->v2d.cur.ymin;
522         ar->v2d.cur.ymin= 0;
523
524         /* set view2d view matrix for scrolling (without scrollers) */
525         UI_view2d_view_ortho(&ar->v2d);
526
527
528         file_draw_buttons(C, ar);
529
530         UI_view2d_view_restore(C);
531 }
532
533 static void file_ui_area_listener(ARegion *ar, wmNotifier *wmn)
534 {
535         /* context changes */
536         switch(wmn->category) {
537                 case NC_SPACE:
538                         switch (wmn->data) {
539                                 case ND_SPACE_FILE_LIST:
540                                         ED_region_tag_redraw(ar);
541                                         break;
542                         }
543                         break;
544         }
545 }
546
547 /* only called once, from space/spacetypes.c */
548 void ED_spacetype_file(void)
549 {
550         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype file");
551         ARegionType *art;
552         
553         st->spaceid= SPACE_FILE;
554         strncpy(st->name, "File", BKE_ST_MAXNAME);
555         
556         st->new= file_new;
557         st->free= file_free;
558         st->init= file_init;
559         st->duplicate= file_duplicate;
560         st->refresh= file_refresh;
561         st->listener= file_listener;
562         st->operatortypes= file_operatortypes;
563         st->keymap= file_keymap;
564         
565         /* regions: main window */
566         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
567         art->regionid = RGN_TYPE_WINDOW;
568         art->init= file_main_area_init;
569         art->draw= file_main_area_draw;
570         art->listener= file_main_area_listener;
571         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
572         BLI_addhead(&st->regiontypes, art);
573         
574         /* regions: header */
575         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
576         art->regionid = RGN_TYPE_HEADER;
577         art->prefsizey= HEADERY;
578         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
579         art->init= file_header_area_init;
580         art->draw= file_header_area_draw;
581         // art->listener= file_header_area_listener;
582         BLI_addhead(&st->regiontypes, art);
583         
584         /* regions: ui */
585         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
586         art->regionid = RGN_TYPE_UI;
587         art->prefsizey= 60;
588         art->keymapflag= ED_KEYMAP_UI;
589         art->listener= file_ui_area_listener;
590         art->init= file_ui_area_init;
591         art->draw= file_ui_area_draw;
592         BLI_addhead(&st->regiontypes, art);
593
594         /* regions: channels (directories) */
595         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
596         art->regionid = RGN_TYPE_CHANNELS;
597         art->prefsizex= 240;
598         art->keymapflag= ED_KEYMAP_UI;
599         art->listener= file_channel_area_listener;
600         art->init= file_channel_area_init;
601         art->draw= file_channel_area_draw;
602         BLI_addhead(&st->regiontypes, art);
603         file_panels_register(art);
604
605         BKE_spacetype_register(st);
606
607 }
608
609 void ED_file_init(void)
610 {
611         char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
612         
613         fsmenu_read_system(fsmenu_get());
614
615         if (cfgdir) {
616                 char name[FILE_MAX];
617                 BLI_make_file_string("/", name, cfgdir, BLENDER_BOOKMARK_FILE);
618                 fsmenu_read_bookmarks(fsmenu_get(), name);
619         }
620         
621         filelist_init_icons();
622         IMB_thumb_makedirs();
623 }
624
625 void ED_file_exit(void)
626 {
627         fsmenu_free(fsmenu_get());
628         filelist_free_icons();
629 }