style cleanup: follow style guide for formatting of if/for/while loops, and else...
[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         }
211         else {
212                 if (params->sort!=FILE_SORT_NONE) {
213                         thumbnails_stop(sfile->files, C);
214                         filelist_sort(sfile->files, params->sort);
215                         if (params->display == FILE_IMGDISPLAY) {
216                                 thumbnails_start(sfile->files, C);
217                         }
218                 }
219                 else {
220                         if (params->display == FILE_IMGDISPLAY) {
221                                 if (!thumbnails_running(sfile->files,C)) {
222                                         thumbnails_start(sfile->files, C);
223                                 }
224                         }
225                         else {
226                                 /* stop any running thumbnail jobs if we're not 
227                                  * displaying them - speedup for NFS */
228                                 thumbnails_stop(sfile->files, C);
229                         }
230                         filelist_filter(sfile->files);
231                 }
232         }
233         
234         if (params->renamefile[0] != '\0') {
235                 int idx = filelist_find(sfile->files, params->renamefile);
236                 if (idx >= 0) {
237                         struct direntry *file= filelist_file(sfile->files, idx);
238                         if (file) {
239                                 file->selflag |= EDITING_FILE;
240                         }
241                 }
242                 BLI_strncpy(sfile->params->renameedit, sfile->params->renamefile, sizeof(sfile->params->renameedit));
243                 params->renamefile[0] = '\0';
244         }
245         if (sfile->layout) sfile->layout->dirty= TRUE;
246
247 }
248
249 static void file_listener(ScrArea *sa, wmNotifier *wmn)
250 {
251         /* SpaceFile* sfile = (SpaceFile*)sa->spacedata.first; */
252
253         /* context changes */
254         switch(wmn->category) {
255                 case NC_SPACE:
256                         switch (wmn->data) {
257                                 case ND_SPACE_FILE_LIST:
258                                         ED_area_tag_refresh(sa);
259                                         ED_area_tag_redraw(sa);
260                                         break;
261                                 case ND_SPACE_FILE_PARAMS:
262                                         ED_area_tag_refresh(sa);
263                                         ED_area_tag_redraw(sa);
264                                         break;
265                         }
266                         break;
267         }
268 }
269
270 /* add handlers, stuff you only do once or on area/region changes */
271 static void file_main_area_init(wmWindowManager *wm, ARegion *ar)
272 {
273         wmKeyMap *keymap;
274         
275         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
276         
277         /* own keymaps */
278         keymap = WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0);
279         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
280
281         keymap = WM_keymap_find(wm->defaultconf, "File Browser Main", SPACE_FILE, 0);
282         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
283                                                            
284
285 }
286
287 static void file_main_area_listener(ARegion *ar, wmNotifier *wmn)
288 {
289         /* context changes */
290         switch(wmn->category) {
291                 case NC_SPACE:
292                         switch (wmn->data) {
293                                 case ND_SPACE_FILE_LIST:
294                                         ED_region_tag_redraw(ar);
295                                         break;
296                                 case ND_SPACE_FILE_PARAMS:
297                                         ED_region_tag_redraw(ar);
298                                         break;
299                         }
300                         break;
301         }
302 }
303
304 static void file_main_area_draw(const bContext *C, ARegion *ar)
305 {
306         /* draw entirely, view changes should be handled here */
307         SpaceFile *sfile= CTX_wm_space_file(C);
308         FileSelectParams *params = ED_fileselect_get_params(sfile);
309         FileLayout *layout=NULL;
310
311         View2D *v2d= &ar->v2d;
312         View2DScrollers *scrollers;
313         float col[3];
314
315         /* Needed, because filelist is not initialized on loading */
316         if (!sfile->files || filelist_empty(sfile->files))
317                 file_refresh(C, NULL);
318
319         layout = ED_fileselect_get_layout(sfile, ar);
320
321         /* clear and setup matrix */
322         UI_GetThemeColor3fv(TH_BACK, col);
323         glClearColor(col[0], col[1], col[2], 0.0);
324         glClear(GL_COLOR_BUFFER_BIT);
325         
326         /* Allow dynamically sliders to be set, saves notifiers etc. */
327         if (layout && (layout->flag == FILE_LAYOUT_VER)) {
328                 v2d->scroll = V2D_SCROLL_RIGHT;
329                 v2d->keepofs &= ~V2D_LOCKOFS_Y;
330                 v2d->keepofs |= V2D_LOCKOFS_X;
331         }
332         else {
333                 v2d->scroll = V2D_SCROLL_BOTTOM;
334                 v2d->keepofs &= ~V2D_LOCKOFS_X;
335                 v2d->keepofs |= V2D_LOCKOFS_Y;
336                 
337                 /* XXX this happens on scaling down Screen (like from startup.blend) */
338                 /* view2d has no type specific for filewindow case, which doesnt scroll vertically */
339                 if (v2d->cur.ymax < 0) {
340                         v2d->cur.ymin -= v2d->cur.ymax;
341                         v2d->cur.ymax = 0;
342                 }
343         }
344         /* v2d has initialized flag, so this call will only set the mask correct */
345         UI_view2d_region_reinit(v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
346
347         /* sets tile/border settings in sfile */
348         file_calc_previews(C, ar);
349
350         /* set view */
351         UI_view2d_view_ortho(v2d);
352         
353         /* on first read, find active file */
354         if (params->active_file == -1) {
355                 wmEvent *event= CTX_wm_window(C)->eventstate;
356                 file_hilight_set(sfile, ar, event->x, event->y);
357         }
358         
359         file_draw_list(C, ar);
360         
361         /* reset view matrix */
362         UI_view2d_view_restore(C);
363         
364         /* scrollers */
365         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
366         UI_view2d_scrollers_draw(C, v2d, scrollers);
367         UI_view2d_scrollers_free(scrollers);
368
369 }
370
371 static void file_operatortypes(void)
372 {
373         WM_operatortype_append(FILE_OT_select);
374         WM_operatortype_append(FILE_OT_select_all_toggle);
375         WM_operatortype_append(FILE_OT_select_border);
376         WM_operatortype_append(FILE_OT_select_bookmark);
377         WM_operatortype_append(FILE_OT_highlight);
378         WM_operatortype_append(FILE_OT_execute);
379         WM_operatortype_append(FILE_OT_cancel);
380         WM_operatortype_append(FILE_OT_parent);
381         WM_operatortype_append(FILE_OT_previous);
382         WM_operatortype_append(FILE_OT_next);
383         WM_operatortype_append(FILE_OT_refresh);
384         WM_operatortype_append(FILE_OT_bookmark_toggle);
385         WM_operatortype_append(FILE_OT_bookmark_add);
386         WM_operatortype_append(FILE_OT_delete_bookmark);
387         WM_operatortype_append(FILE_OT_hidedot);
388         WM_operatortype_append(FILE_OT_filenum);
389         WM_operatortype_append(FILE_OT_directory_new);
390         WM_operatortype_append(FILE_OT_delete);
391         WM_operatortype_append(FILE_OT_rename);
392         WM_operatortype_append(FILE_OT_smoothscroll);
393         WM_operatortype_append(FILE_OT_directory);
394 }
395
396 /* NOTE: do not add .blend file reading on this level */
397 static void file_keymap(struct wmKeyConfig *keyconf)
398 {
399         wmKeyMapItem *kmi;
400         /* keys for all areas */
401         wmKeyMap *keymap = WM_keymap_find(keyconf, "File Browser", SPACE_FILE, 0);
402         WM_keymap_add_item(keymap, "FILE_OT_bookmark_toggle", NKEY, KM_PRESS, 0, 0);
403         WM_keymap_add_item(keymap, "FILE_OT_parent", PKEY, KM_PRESS, 0, 0);
404         WM_keymap_add_item(keymap, "FILE_OT_bookmark_add", BKEY, KM_PRESS, KM_CTRL, 0);
405         WM_keymap_add_item(keymap, "FILE_OT_hidedot", HKEY, KM_PRESS, 0, 0);
406         WM_keymap_add_item(keymap, "FILE_OT_previous", BACKSPACEKEY, KM_PRESS, 0, 0);
407         WM_keymap_add_item(keymap, "FILE_OT_next", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0);
408         WM_keymap_add_item(keymap, "FILE_OT_directory_new", IKEY, KM_PRESS, 0, 0);  /* XXX needs button */
409         WM_keymap_add_item(keymap, "FILE_OT_delete", XKEY, KM_PRESS, 0, 0);
410         WM_keymap_add_item(keymap, "FILE_OT_delete", DELKEY, KM_PRESS, 0, 0);
411         WM_keymap_verify_item(keymap, "FILE_OT_smoothscroll", TIMER1, KM_ANY, KM_ANY, 0);
412
413         /* keys for main area */
414         keymap = WM_keymap_find(keyconf, "File Browser Main", SPACE_FILE, 0);
415         kmi = WM_keymap_add_item(keymap, "FILE_OT_execute", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
416         RNA_boolean_set(kmi->ptr, "need_active", TRUE);
417         WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, 0, 0);
418         kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0);
419         RNA_boolean_set(kmi->ptr, "extend", TRUE);
420         kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0);
421         RNA_boolean_set(kmi->ptr, "extend", TRUE);
422         RNA_boolean_set(kmi->ptr, "fill", TRUE);
423         WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
424         WM_keymap_add_item(keymap, "FILE_OT_refresh", PADPERIOD, KM_PRESS, 0, 0);
425         WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0);
426         WM_keymap_add_item(keymap, "FILE_OT_select_border", EVT_TWEAK_L, KM_ANY, 0, 0);
427         WM_keymap_add_item(keymap, "FILE_OT_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
428         WM_keymap_add_item(keymap, "FILE_OT_highlight", MOUSEMOVE, KM_ANY, KM_ANY, 0);
429         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0);
430         RNA_int_set(kmi->ptr, "increment", 1);
431         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0);
432         RNA_int_set(kmi->ptr, "increment", 10);
433         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
434         RNA_int_set(kmi->ptr, "increment", 100);
435         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0,0);
436         RNA_int_set(kmi->ptr, "increment", -1);
437         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT, 0);
438         RNA_int_set(kmi->ptr, "increment", -10);
439         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL, 0);
440         RNA_int_set(kmi->ptr, "increment",-100);
441         
442         
443         /* keys for button area (top) */
444         keymap = WM_keymap_find(keyconf, "File Browser Buttons", SPACE_FILE, 0);
445         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0);
446         RNA_int_set(kmi->ptr, "increment", 1);
447         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0);
448         RNA_int_set(kmi->ptr, "increment", 10);
449         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
450         RNA_int_set(kmi->ptr, "increment", 100);
451         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0, 0);
452         RNA_int_set(kmi->ptr, "increment", -1);
453         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT,0);
454         RNA_int_set(kmi->ptr, "increment", -10);
455         kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL,0);
456         RNA_int_set(kmi->ptr, "increment",-100);
457 }
458
459
460 static void file_channel_area_init(wmWindowManager *wm, ARegion *ar)
461 {
462         wmKeyMap *keymap;
463
464         ED_region_panels_init(wm, ar);
465
466         /* own keymaps */
467         keymap = WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0);        
468         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
469 }
470
471 static void file_channel_area_draw(const bContext *C, ARegion *ar)
472 {
473         ED_region_panels(C, ar, 1, NULL, -1);
474 }
475
476 static void file_channel_area_listener(ARegion *UNUSED(ar), wmNotifier *wmn)
477 {
478         /* context changes */
479         switch(wmn->category) {
480                 
481         }
482 }
483
484 /* add handlers, stuff you only do once or on area/region changes */
485 static void file_header_area_init(wmWindowManager *wm, ARegion *ar)
486 {
487         wmKeyMap *keymap;
488         
489         ED_region_header_init(ar);
490         
491         keymap = WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0);        
492         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
493 }
494
495 static void file_header_area_draw(const bContext *C, ARegion *ar)
496 {
497         ED_region_header(C, ar);
498 }
499
500 /* add handlers, stuff you only do once or on area/region changes */
501 static void file_ui_area_init(wmWindowManager *wm, ARegion *ar)
502 {
503         wmKeyMap *keymap;
504
505         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
506
507         /* own keymap */
508         keymap = WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0);
509         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
510
511         keymap = WM_keymap_find(wm->defaultconf, "File Browser Buttons", SPACE_FILE, 0);
512         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
513 }
514
515 static void file_ui_area_draw(const bContext *C, ARegion *ar)
516 {
517         float col[3];
518         /* clear */
519         UI_GetThemeColor3fv(TH_PANEL, col);
520         glClearColor(col[0], col[1], col[2], 0.0);
521         glClear(GL_COLOR_BUFFER_BIT);
522
523         /* scrolling here is just annoying, disable it */
524         ar->v2d.cur.ymax = ar->v2d.cur.ymax - ar->v2d.cur.ymin;
525         ar->v2d.cur.ymin = 0;
526
527         /* set view2d view matrix for scrolling (without scrollers) */
528         UI_view2d_view_ortho(&ar->v2d);
529
530
531         file_draw_buttons(C, ar);
532
533         UI_view2d_view_restore(C);
534 }
535
536 static void file_ui_area_listener(ARegion *ar, wmNotifier *wmn)
537 {
538         /* context changes */
539         switch(wmn->category) {
540                 case NC_SPACE:
541                         switch (wmn->data) {
542                                 case ND_SPACE_FILE_LIST:
543                                         ED_region_tag_redraw(ar);
544                                         break;
545                         }
546                         break;
547         }
548 }
549
550 /* only called once, from space/spacetypes.c */
551 void ED_spacetype_file(void)
552 {
553         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype file");
554         ARegionType *art;
555         
556         st->spaceid= SPACE_FILE;
557         strncpy(st->name, "File", BKE_ST_MAXNAME);
558         
559         st->new= file_new;
560         st->free= file_free;
561         st->init= file_init;
562         st->duplicate= file_duplicate;
563         st->refresh= file_refresh;
564         st->listener= file_listener;
565         st->operatortypes= file_operatortypes;
566         st->keymap= file_keymap;
567         
568         /* regions: main window */
569         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
570         art->regionid = RGN_TYPE_WINDOW;
571         art->init= file_main_area_init;
572         art->draw= file_main_area_draw;
573         art->listener= file_main_area_listener;
574         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
575         BLI_addhead(&st->regiontypes, art);
576         
577         /* regions: header */
578         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
579         art->regionid = RGN_TYPE_HEADER;
580         art->prefsizey= HEADERY;
581         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
582         art->init= file_header_area_init;
583         art->draw= file_header_area_draw;
584         // art->listener= file_header_area_listener;
585         BLI_addhead(&st->regiontypes, art);
586         
587         /* regions: ui */
588         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
589         art->regionid = RGN_TYPE_UI;
590         art->prefsizey= 60;
591         art->keymapflag= ED_KEYMAP_UI;
592         art->listener= file_ui_area_listener;
593         art->init= file_ui_area_init;
594         art->draw= file_ui_area_draw;
595         BLI_addhead(&st->regiontypes, art);
596
597         /* regions: channels (directories) */
598         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
599         art->regionid = RGN_TYPE_CHANNELS;
600         art->prefsizex= 240;
601         art->keymapflag= ED_KEYMAP_UI;
602         art->listener= file_channel_area_listener;
603         art->init= file_channel_area_init;
604         art->draw= file_channel_area_draw;
605         BLI_addhead(&st->regiontypes, art);
606         file_panels_register(art);
607
608         BKE_spacetype_register(st);
609
610 }
611
612 void ED_file_init(void)
613 {
614         char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
615         
616         fsmenu_read_system(fsmenu_get());
617
618         if (cfgdir) {
619                 char name[FILE_MAX];
620                 BLI_make_file_string("/", name, cfgdir, BLENDER_BOOKMARK_FILE);
621                 fsmenu_read_bookmarks(fsmenu_get(), name);
622         }
623         
624         filelist_init_icons();
625         IMB_thumb_makedirs();
626 }
627
628 void ED_file_exit(void)
629 {
630         fsmenu_free(fsmenu_get());
631         filelist_free_icons();
632 }