Fix #27849: 3D manipulator widget lost on mesh in edge mode.
[blender.git] / source / blender / editors / space_file / space_file.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) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_file/space_file.c
30  *  \ingroup spfile
31  */
32
33
34 #include <string.h>
35 #include <stdio.h>
36
37
38 #include "RNA_access.h"
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BIF_gl.h"
43
44 #include "BLO_readfile.h"
45
46 #include "BLI_blenlib.h"
47 #include "BLI_math.h"
48 #include "BLI_rand.h"
49 #include "BLI_storage_types.h"
50 #include "BLI_utildefines.h"
51
52 #include "BKE_context.h"
53 #include "BKE_screen.h"
54
55 #include "ED_space_api.h"
56 #include "ED_screen.h"
57 #include "ED_fileselect.h"
58
59 #include "IMB_imbuf_types.h"
60 #include "IMB_thumbs.h"
61
62 #include "WM_api.h"
63 #include "WM_types.h"
64
65 #include "UI_resources.h"
66 #include "UI_view2d.h"
67
68
69 #include "file_intern.h"        // own include
70 #include "fsmenu.h"
71 #include "filelist.h"
72
73 /* ******************** default callbacks for file space ***************** */
74
75 static SpaceLink *file_new(const bContext *UNUSED(C))
76 {
77         ARegion *ar;
78         SpaceFile *sfile;
79         
80         sfile= MEM_callocN(sizeof(SpaceFile), "initfile");
81         sfile->spacetype= SPACE_FILE;
82
83         /* header */
84         ar= MEM_callocN(sizeof(ARegion), "header for file");
85         BLI_addtail(&sfile->regionbase, ar);
86         ar->regiontype= RGN_TYPE_HEADER;
87         ar->alignment= RGN_ALIGN_TOP;
88
89         /* channel list region */
90         ar= MEM_callocN(sizeof(ARegion), "channel area for file");
91         BLI_addtail(&sfile->regionbase, ar);
92         ar->regiontype= RGN_TYPE_CHANNELS;
93         ar->alignment= RGN_ALIGN_LEFT;  
94
95         /* ui list region */
96         ar= MEM_callocN(sizeof(ARegion), "ui area for file");
97         BLI_addtail(&sfile->regionbase, ar);
98         ar->regiontype= RGN_TYPE_UI;
99         ar->alignment= RGN_ALIGN_TOP;
100
101         /* main area */
102         ar= MEM_callocN(sizeof(ARegion), "main area for file");
103         BLI_addtail(&sfile->regionbase, ar);
104         ar->regiontype= RGN_TYPE_WINDOW;
105         ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
106         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
107         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
108         ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
109         ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
110
111         return (SpaceLink *)sfile;
112 }
113
114 /* not spacelink itself */
115 static void file_free(SpaceLink *sl)
116 {       
117         SpaceFile *sfile= (SpaceFile *) sl;
118         
119         if(sfile->files) {
120                 // XXXXX would need to do thumbnails_stop here, but no context available
121                 filelist_freelib(sfile->files);
122                 filelist_free(sfile->files);
123                 MEM_freeN(sfile->files);
124                 sfile->files= NULL;
125         }
126
127         if(sfile->folders_prev) {
128                 folderlist_free(sfile->folders_prev);
129                 MEM_freeN(sfile->folders_prev);
130                 sfile->folders_prev= NULL;
131         }
132
133         if(sfile->folders_next) {
134                 folderlist_free(sfile->folders_next);
135                 MEM_freeN(sfile->folders_next);
136                 sfile->folders_next= NULL;
137         }
138
139         if (sfile->params) {
140                 MEM_freeN(sfile->params);
141                 sfile->params= NULL;
142         }
143
144         if (sfile->layout) {
145                 MEM_freeN(sfile->layout);
146                 sfile->layout = NULL;
147         }
148 }
149
150
151 /* spacetype; init callback, area size changes, screen set, etc */
152 static void file_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
153 {
154         SpaceFile *sfile= (SpaceFile*)sa->spacedata.first;
155         //printf("file_init\n");
156
157         if(sfile->layout) sfile->layout->dirty= 1;
158 }
159
160
161 static SpaceLink *file_duplicate(SpaceLink *sl)
162 {
163         SpaceFile *sfileo= (SpaceFile*)sl;
164         SpaceFile *sfilen= MEM_dupallocN(sl);
165         
166         /* clear or remove stuff from old */
167         sfilen->op = NULL; /* file window doesn't own operators */
168
169         if (sfileo->params) {
170                 sfilen->files = filelist_new(sfileo->params->type);
171                 sfilen->params= MEM_dupallocN(sfileo->params);
172                 filelist_setdir(sfilen->files, sfilen->params->dir);
173         }
174
175         if(sfileo->folders_prev)
176                 sfilen->folders_prev = folderlist_duplicate(sfileo->folders_prev);
177
178         if(sfileo->folders_next)
179                 sfilen->folders_next = folderlist_duplicate(sfileo->folders_next);
180         
181         if (sfileo->layout) {
182                 sfilen->layout= MEM_dupallocN(sfileo->layout);
183         }
184         return (SpaceLink *)sfilen;
185 }
186
187 static void file_refresh(const bContext *C, ScrArea *UNUSED(sa))
188 {
189         SpaceFile *sfile= CTX_wm_space_file(C);
190         FileSelectParams *params = ED_fileselect_get_params(sfile);
191
192         if (!sfile->folders_prev)
193                 sfile->folders_prev = folderlist_new();
194         if (!sfile->files) {
195                 sfile->files = filelist_new(params->type);
196                 filelist_setdir(sfile->files, params->dir);
197                 params->active_file = -1; // added this so it opens nicer (ton)
198         }
199         filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT);
200         filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0);      
201         filelist_setfilter_types(sfile->files, params->filter_glob);
202         if (filelist_empty(sfile->files))
203         {
204                 thumbnails_stop(sfile->files, C);
205                 filelist_readdir(sfile->files);
206                 if(params->sort!=FILE_SORT_NONE) {
207                         filelist_sort(sfile->files, params->sort);
208                 }
209                 BLI_strncpy(params->dir, filelist_dir(sfile->files), FILE_MAX);
210                 if(params->display == FILE_IMGDISPLAY) {
211                         thumbnails_start(sfile->files, C);
212                 }
213         } else {
214                 if(params->sort!=FILE_SORT_NONE) {
215                         thumbnails_stop(sfile->files, C);
216                         filelist_sort(sfile->files, params->sort);
217                         if(params->display == FILE_IMGDISPLAY) {
218                                 thumbnails_start(sfile->files, C);
219                         }
220                 } else {
221                         if(params->display == FILE_IMGDISPLAY) {
222                                 if (!thumbnails_running(sfile->files,C)) {
223                                         thumbnails_start(sfile->files, C);
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= 1;
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", 1);
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", 1);
420         kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0);
421         RNA_boolean_set(kmi->ptr, "extend", 1);
422         RNA_boolean_set(kmi->ptr, "fill", 1);
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         /* set view2d view matrix for scrolling (without scrollers) */
524         UI_view2d_view_ortho(&ar->v2d);
525
526         file_draw_buttons(C, ar);
527
528         UI_view2d_view_restore(C);
529 }
530
531 static void file_ui_area_listener(ARegion *ar, wmNotifier *wmn)
532 {
533         /* context changes */
534         switch(wmn->category) {
535                 case NC_SPACE:
536                         switch (wmn->data) {
537                                 case ND_SPACE_FILE_LIST:
538                                         ED_region_tag_redraw(ar);
539                                         break;
540                         }
541                         break;
542         }
543 }
544
545 /* only called once, from space/spacetypes.c */
546 void ED_spacetype_file(void)
547 {
548         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype file");
549         ARegionType *art;
550         
551         st->spaceid= SPACE_FILE;
552         strncpy(st->name, "File", BKE_ST_MAXNAME);
553         
554         st->new= file_new;
555         st->free= file_free;
556         st->init= file_init;
557         st->duplicate= file_duplicate;
558         st->refresh= file_refresh;
559         st->listener= file_listener;
560         st->operatortypes= file_operatortypes;
561         st->keymap= file_keymap;
562         
563         /* regions: main window */
564         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
565         art->regionid = RGN_TYPE_WINDOW;
566         art->init= file_main_area_init;
567         art->draw= file_main_area_draw;
568         art->listener= file_main_area_listener;
569         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
570         BLI_addhead(&st->regiontypes, art);
571         
572         /* regions: header */
573         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
574         art->regionid = RGN_TYPE_HEADER;
575         art->prefsizey= HEADERY;
576         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
577         art->init= file_header_area_init;
578         art->draw= file_header_area_draw;
579         // art->listener= file_header_area_listener;
580         BLI_addhead(&st->regiontypes, art);
581         
582         /* regions: ui */
583         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
584         art->regionid = RGN_TYPE_UI;
585         art->prefsizey= 60;
586         art->keymapflag= ED_KEYMAP_UI;
587         art->listener= file_ui_area_listener;
588         art->init= file_ui_area_init;
589         art->draw= file_ui_area_draw;
590         BLI_addhead(&st->regiontypes, art);
591
592         /* regions: channels (directories) */
593         art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
594         art->regionid = RGN_TYPE_CHANNELS;
595         art->prefsizex= 240;
596         art->keymapflag= ED_KEYMAP_UI;
597         art->listener= file_channel_area_listener;
598         art->init= file_channel_area_init;
599         art->draw= file_channel_area_draw;
600         BLI_addhead(&st->regiontypes, art);
601         file_panels_register(art);
602
603         BKE_spacetype_register(st);
604
605 }
606
607 void ED_file_init(void)
608 {
609         char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
610         
611         fsmenu_read_system(fsmenu_get());
612
613         if (cfgdir) {
614                 char name[FILE_MAX];
615                 BLI_make_file_string("/", name, cfgdir, BLENDER_BOOKMARK_FILE);
616                 fsmenu_read_bookmarks(fsmenu_get(), name);
617         }
618         
619         filelist_init_icons();
620         IMB_thumb_makedirs();
621 }
622
623 void ED_file_exit(void)
624 {
625         fsmenu_free(fsmenu_get());
626         filelist_free_icons();
627 }