Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2008 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00032 #include <string.h> 00033 #include <stdio.h> 00034 00035 00036 #include "RNA_access.h" 00037 00038 #include "MEM_guardedalloc.h" 00039 00040 #include "BIF_gl.h" 00041 00042 #include "BLO_readfile.h" 00043 00044 #include "BLI_blenlib.h" 00045 #include "BLI_math.h" 00046 #include "BLI_rand.h" 00047 #include "BLI_utildefines.h" 00048 00049 #include "BKE_context.h" 00050 #include "BKE_screen.h" 00051 00052 #include "ED_space_api.h" 00053 #include "ED_screen.h" 00054 #include "ED_fileselect.h" 00055 00056 #include "IMB_imbuf_types.h" 00057 #include "IMB_thumbs.h" 00058 00059 #include "WM_api.h" 00060 #include "WM_types.h" 00061 00062 #include "UI_resources.h" 00063 #include "UI_view2d.h" 00064 00065 00066 #include "file_intern.h" // own include 00067 #include "fsmenu.h" 00068 #include "filelist.h" 00069 00070 /* ******************** default callbacks for file space ***************** */ 00071 00072 static SpaceLink *file_new(const bContext *UNUSED(C)) 00073 { 00074 ARegion *ar; 00075 SpaceFile *sfile; 00076 00077 sfile= MEM_callocN(sizeof(SpaceFile), "initfile"); 00078 sfile->spacetype= SPACE_FILE; 00079 00080 /* header */ 00081 ar= MEM_callocN(sizeof(ARegion), "header for file"); 00082 BLI_addtail(&sfile->regionbase, ar); 00083 ar->regiontype= RGN_TYPE_HEADER; 00084 ar->alignment= RGN_ALIGN_TOP; 00085 00086 /* channel list region */ 00087 ar= MEM_callocN(sizeof(ARegion), "channel area for file"); 00088 BLI_addtail(&sfile->regionbase, ar); 00089 ar->regiontype= RGN_TYPE_CHANNELS; 00090 ar->alignment= RGN_ALIGN_LEFT; 00091 00092 /* ui list region */ 00093 ar= MEM_callocN(sizeof(ARegion), "ui area for file"); 00094 BLI_addtail(&sfile->regionbase, ar); 00095 ar->regiontype= RGN_TYPE_UI; 00096 ar->alignment= RGN_ALIGN_TOP; 00097 00098 /* main area */ 00099 ar= MEM_callocN(sizeof(ARegion), "main area for file"); 00100 BLI_addtail(&sfile->regionbase, ar); 00101 ar->regiontype= RGN_TYPE_WINDOW; 00102 ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM); 00103 ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y); 00104 ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT); 00105 ar->v2d.keeptot= V2D_KEEPTOT_STRICT; 00106 ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f; 00107 00108 return (SpaceLink *)sfile; 00109 } 00110 00111 /* not spacelink itself */ 00112 static void file_free(SpaceLink *sl) 00113 { 00114 SpaceFile *sfile= (SpaceFile *) sl; 00115 00116 if(sfile->files) { 00117 // XXXXX would need to do thumbnails_stop here, but no context available 00118 filelist_freelib(sfile->files); 00119 filelist_free(sfile->files); 00120 MEM_freeN(sfile->files); 00121 sfile->files= NULL; 00122 } 00123 00124 if(sfile->folders_prev) { 00125 folderlist_free(sfile->folders_prev); 00126 MEM_freeN(sfile->folders_prev); 00127 sfile->folders_prev= NULL; 00128 } 00129 00130 if(sfile->folders_next) { 00131 folderlist_free(sfile->folders_next); 00132 MEM_freeN(sfile->folders_next); 00133 sfile->folders_next= NULL; 00134 } 00135 00136 if (sfile->params) { 00137 MEM_freeN(sfile->params); 00138 sfile->params= NULL; 00139 } 00140 00141 if (sfile->layout) { 00142 MEM_freeN(sfile->layout); 00143 sfile->layout = NULL; 00144 } 00145 } 00146 00147 00148 /* spacetype; init callback, area size changes, screen set, etc */ 00149 static void file_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa) 00150 { 00151 SpaceFile *sfile= (SpaceFile*)sa->spacedata.first; 00152 //printf("file_init\n"); 00153 00154 if(sfile->layout) sfile->layout->dirty= TRUE; 00155 } 00156 00157 00158 static SpaceLink *file_duplicate(SpaceLink *sl) 00159 { 00160 SpaceFile *sfileo= (SpaceFile*)sl; 00161 SpaceFile *sfilen= MEM_dupallocN(sl); 00162 00163 /* clear or remove stuff from old */ 00164 sfilen->op = NULL; /* file window doesn't own operators */ 00165 00166 if (sfileo->params) { 00167 sfilen->files = filelist_new(sfileo->params->type); 00168 sfilen->params= MEM_dupallocN(sfileo->params); 00169 filelist_setdir(sfilen->files, sfilen->params->dir); 00170 } 00171 00172 if(sfileo->folders_prev) 00173 sfilen->folders_prev = folderlist_duplicate(sfileo->folders_prev); 00174 00175 if(sfileo->folders_next) 00176 sfilen->folders_next = folderlist_duplicate(sfileo->folders_next); 00177 00178 if (sfileo->layout) { 00179 sfilen->layout= MEM_dupallocN(sfileo->layout); 00180 } 00181 return (SpaceLink *)sfilen; 00182 } 00183 00184 static void file_refresh(const bContext *C, ScrArea *UNUSED(sa)) 00185 { 00186 SpaceFile *sfile= CTX_wm_space_file(C); 00187 FileSelectParams *params = ED_fileselect_get_params(sfile); 00188 00189 if (!sfile->folders_prev) 00190 sfile->folders_prev = folderlist_new(); 00191 if (!sfile->files) { 00192 sfile->files = filelist_new(params->type); 00193 filelist_setdir(sfile->files, params->dir); 00194 params->active_file = -1; // added this so it opens nicer (ton) 00195 } 00196 filelist_hidedot(sfile->files, params->flag & FILE_HIDE_DOT); 00197 filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0); 00198 filelist_setfilter_types(sfile->files, params->filter_glob); 00199 if (filelist_empty(sfile->files)) 00200 { 00201 thumbnails_stop(sfile->files, C); 00202 filelist_readdir(sfile->files); 00203 if(params->sort!=FILE_SORT_NONE) { 00204 filelist_sort(sfile->files, params->sort); 00205 } 00206 BLI_strncpy(params->dir, filelist_dir(sfile->files), FILE_MAX); 00207 if(params->display == FILE_IMGDISPLAY) { 00208 thumbnails_start(sfile->files, C); 00209 } 00210 } else { 00211 if(params->sort!=FILE_SORT_NONE) { 00212 thumbnails_stop(sfile->files, C); 00213 filelist_sort(sfile->files, params->sort); 00214 if(params->display == FILE_IMGDISPLAY) { 00215 thumbnails_start(sfile->files, C); 00216 } 00217 } else { 00218 if(params->display == FILE_IMGDISPLAY) { 00219 if (!thumbnails_running(sfile->files,C)) { 00220 thumbnails_start(sfile->files, C); 00221 } 00222 } else { 00223 /* stop any running thumbnail jobs if we're not 00224 displaying them - speedup for NFS */ 00225 thumbnails_stop(sfile->files, C); 00226 } 00227 filelist_filter(sfile->files); 00228 } 00229 } 00230 00231 if (params->renamefile[0] != '\0') { 00232 int idx = filelist_find(sfile->files, params->renamefile); 00233 if (idx >= 0) { 00234 struct direntry *file= filelist_file(sfile->files, idx); 00235 if (file) { 00236 file->selflag |= EDITING_FILE; 00237 } 00238 } 00239 BLI_strncpy(sfile->params->renameedit, sfile->params->renamefile, sizeof(sfile->params->renameedit)); 00240 params->renamefile[0] = '\0'; 00241 } 00242 if (sfile->layout) sfile->layout->dirty= TRUE; 00243 00244 } 00245 00246 static void file_listener(ScrArea *sa, wmNotifier *wmn) 00247 { 00248 /* SpaceFile* sfile = (SpaceFile*)sa->spacedata.first; */ 00249 00250 /* context changes */ 00251 switch(wmn->category) { 00252 case NC_SPACE: 00253 switch (wmn->data) { 00254 case ND_SPACE_FILE_LIST: 00255 ED_area_tag_refresh(sa); 00256 ED_area_tag_redraw(sa); 00257 break; 00258 case ND_SPACE_FILE_PARAMS: 00259 ED_area_tag_refresh(sa); 00260 ED_area_tag_redraw(sa); 00261 break; 00262 } 00263 break; 00264 } 00265 } 00266 00267 /* add handlers, stuff you only do once or on area/region changes */ 00268 static void file_main_area_init(wmWindowManager *wm, ARegion *ar) 00269 { 00270 wmKeyMap *keymap; 00271 00272 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy); 00273 00274 /* own keymaps */ 00275 keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0); 00276 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00277 00278 keymap= WM_keymap_find(wm->defaultconf, "File Browser Main", SPACE_FILE, 0); 00279 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00280 00281 00282 } 00283 00284 static void file_main_area_listener(ARegion *ar, wmNotifier *wmn) 00285 { 00286 /* context changes */ 00287 switch(wmn->category) { 00288 case NC_SPACE: 00289 switch (wmn->data) { 00290 case ND_SPACE_FILE_LIST: 00291 ED_region_tag_redraw(ar); 00292 break; 00293 case ND_SPACE_FILE_PARAMS: 00294 ED_region_tag_redraw(ar); 00295 break; 00296 } 00297 break; 00298 } 00299 } 00300 00301 static void file_main_area_draw(const bContext *C, ARegion *ar) 00302 { 00303 /* draw entirely, view changes should be handled here */ 00304 SpaceFile *sfile= CTX_wm_space_file(C); 00305 FileSelectParams *params = ED_fileselect_get_params(sfile); 00306 FileLayout *layout=NULL; 00307 00308 View2D *v2d= &ar->v2d; 00309 View2DScrollers *scrollers; 00310 float col[3]; 00311 00312 /* Needed, because filelist is not initialized on loading */ 00313 if (!sfile->files || filelist_empty(sfile->files)) 00314 file_refresh(C, NULL); 00315 00316 layout = ED_fileselect_get_layout(sfile, ar); 00317 00318 /* clear and setup matrix */ 00319 UI_GetThemeColor3fv(TH_BACK, col); 00320 glClearColor(col[0], col[1], col[2], 0.0); 00321 glClear(GL_COLOR_BUFFER_BIT); 00322 00323 /* Allow dynamically sliders to be set, saves notifiers etc. */ 00324 if (layout && (layout->flag == FILE_LAYOUT_VER)) { 00325 v2d->scroll = V2D_SCROLL_RIGHT; 00326 v2d->keepofs &= ~V2D_LOCKOFS_Y; 00327 v2d->keepofs |= V2D_LOCKOFS_X; 00328 } 00329 else { 00330 v2d->scroll = V2D_SCROLL_BOTTOM; 00331 v2d->keepofs &= ~V2D_LOCKOFS_X; 00332 v2d->keepofs |= V2D_LOCKOFS_Y; 00333 00334 /* XXX this happens on scaling down Screen (like from startup.blend) */ 00335 /* view2d has no type specific for filewindow case, which doesnt scroll vertically */ 00336 if(v2d->cur.ymax < 0) { 00337 v2d->cur.ymin -= v2d->cur.ymax; 00338 v2d->cur.ymax= 0; 00339 } 00340 } 00341 /* v2d has initialized flag, so this call will only set the mask correct */ 00342 UI_view2d_region_reinit(v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy); 00343 00344 /* sets tile/border settings in sfile */ 00345 file_calc_previews(C, ar); 00346 00347 /* set view */ 00348 UI_view2d_view_ortho(v2d); 00349 00350 /* on first read, find active file */ 00351 if (params->active_file == -1) { 00352 wmEvent *event= CTX_wm_window(C)->eventstate; 00353 file_hilight_set(sfile, ar, event->x, event->y); 00354 } 00355 00356 file_draw_list(C, ar); 00357 00358 /* reset view matrix */ 00359 UI_view2d_view_restore(C); 00360 00361 /* scrollers */ 00362 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); 00363 UI_view2d_scrollers_draw(C, v2d, scrollers); 00364 UI_view2d_scrollers_free(scrollers); 00365 00366 } 00367 00368 static void file_operatortypes(void) 00369 { 00370 WM_operatortype_append(FILE_OT_select); 00371 WM_operatortype_append(FILE_OT_select_all_toggle); 00372 WM_operatortype_append(FILE_OT_select_border); 00373 WM_operatortype_append(FILE_OT_select_bookmark); 00374 WM_operatortype_append(FILE_OT_highlight); 00375 WM_operatortype_append(FILE_OT_execute); 00376 WM_operatortype_append(FILE_OT_cancel); 00377 WM_operatortype_append(FILE_OT_parent); 00378 WM_operatortype_append(FILE_OT_previous); 00379 WM_operatortype_append(FILE_OT_next); 00380 WM_operatortype_append(FILE_OT_refresh); 00381 WM_operatortype_append(FILE_OT_bookmark_toggle); 00382 WM_operatortype_append(FILE_OT_bookmark_add); 00383 WM_operatortype_append(FILE_OT_delete_bookmark); 00384 WM_operatortype_append(FILE_OT_hidedot); 00385 WM_operatortype_append(FILE_OT_filenum); 00386 WM_operatortype_append(FILE_OT_directory_new); 00387 WM_operatortype_append(FILE_OT_delete); 00388 WM_operatortype_append(FILE_OT_rename); 00389 WM_operatortype_append(FILE_OT_smoothscroll); 00390 WM_operatortype_append(FILE_OT_directory); 00391 } 00392 00393 /* NOTE: do not add .blend file reading on this level */ 00394 static void file_keymap(struct wmKeyConfig *keyconf) 00395 { 00396 wmKeyMapItem *kmi; 00397 /* keys for all areas */ 00398 wmKeyMap *keymap= WM_keymap_find(keyconf, "File Browser", SPACE_FILE, 0); 00399 WM_keymap_add_item(keymap, "FILE_OT_bookmark_toggle", NKEY, KM_PRESS, 0, 0); 00400 WM_keymap_add_item(keymap, "FILE_OT_parent", PKEY, KM_PRESS, 0, 0); 00401 WM_keymap_add_item(keymap, "FILE_OT_bookmark_add", BKEY, KM_PRESS, KM_CTRL, 0); 00402 WM_keymap_add_item(keymap, "FILE_OT_hidedot", HKEY, KM_PRESS, 0, 0); 00403 WM_keymap_add_item(keymap, "FILE_OT_previous", BACKSPACEKEY, KM_PRESS, 0, 0); 00404 WM_keymap_add_item(keymap, "FILE_OT_next", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0); 00405 WM_keymap_add_item(keymap, "FILE_OT_directory_new", IKEY, KM_PRESS, 0, 0); /* XXX needs button */ 00406 WM_keymap_add_item(keymap, "FILE_OT_delete", XKEY, KM_PRESS, 0, 0); 00407 WM_keymap_add_item(keymap, "FILE_OT_delete", DELKEY, KM_PRESS, 0, 0); 00408 WM_keymap_verify_item(keymap, "FILE_OT_smoothscroll", TIMER1, KM_ANY, KM_ANY, 0); 00409 00410 /* keys for main area */ 00411 keymap= WM_keymap_find(keyconf, "File Browser Main", SPACE_FILE, 0); 00412 kmi= WM_keymap_add_item(keymap, "FILE_OT_execute", LEFTMOUSE, KM_DBL_CLICK, 0, 0); 00413 RNA_boolean_set(kmi->ptr, "need_active", TRUE); 00414 WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, 0, 0); 00415 kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_SHIFT, 0); 00416 RNA_boolean_set(kmi->ptr, "extend", TRUE); 00417 kmi = WM_keymap_add_item(keymap, "FILE_OT_select", LEFTMOUSE, KM_CLICK, KM_ALT, 0); 00418 RNA_boolean_set(kmi->ptr, "extend", TRUE); 00419 RNA_boolean_set(kmi->ptr, "fill", TRUE); 00420 WM_keymap_add_item(keymap, "FILE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); 00421 WM_keymap_add_item(keymap, "FILE_OT_refresh", PADPERIOD, KM_PRESS, 0, 0); 00422 WM_keymap_add_item(keymap, "FILE_OT_select_border", BKEY, KM_PRESS, 0, 0); 00423 WM_keymap_add_item(keymap, "FILE_OT_select_border", EVT_TWEAK_L, KM_ANY, 0, 0); 00424 WM_keymap_add_item(keymap, "FILE_OT_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); 00425 WM_keymap_add_item(keymap, "FILE_OT_highlight", MOUSEMOVE, KM_ANY, KM_ANY, 0); 00426 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0); 00427 RNA_int_set(kmi->ptr, "increment", 1); 00428 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0); 00429 RNA_int_set(kmi->ptr, "increment", 10); 00430 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); 00431 RNA_int_set(kmi->ptr, "increment", 100); 00432 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0,0); 00433 RNA_int_set(kmi->ptr, "increment", -1); 00434 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT, 0); 00435 RNA_int_set(kmi->ptr, "increment", -10); 00436 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL, 0); 00437 RNA_int_set(kmi->ptr, "increment",-100); 00438 00439 00440 /* keys for button area (top) */ 00441 keymap= WM_keymap_find(keyconf, "File Browser Buttons", SPACE_FILE, 0); 00442 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, 0, 0); 00443 RNA_int_set(kmi->ptr, "increment", 1); 00444 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0); 00445 RNA_int_set(kmi->ptr, "increment", 10); 00446 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); 00447 RNA_int_set(kmi->ptr, "increment", 100); 00448 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, 0, 0); 00449 RNA_int_set(kmi->ptr, "increment", -1); 00450 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_SHIFT,0); 00451 RNA_int_set(kmi->ptr, "increment", -10); 00452 kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL,0); 00453 RNA_int_set(kmi->ptr, "increment",-100); 00454 } 00455 00456 00457 static void file_channel_area_init(wmWindowManager *wm, ARegion *ar) 00458 { 00459 wmKeyMap *keymap; 00460 00461 ED_region_panels_init(wm, ar); 00462 00463 /* own keymaps */ 00464 keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0); 00465 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00466 } 00467 00468 static void file_channel_area_draw(const bContext *C, ARegion *ar) 00469 { 00470 ED_region_panels(C, ar, 1, NULL, -1); 00471 } 00472 00473 static void file_channel_area_listener(ARegion *UNUSED(ar), wmNotifier *wmn) 00474 { 00475 /* context changes */ 00476 switch(wmn->category) { 00477 00478 } 00479 } 00480 00481 /* add handlers, stuff you only do once or on area/region changes */ 00482 static void file_header_area_init(wmWindowManager *wm, ARegion *ar) 00483 { 00484 wmKeyMap *keymap; 00485 00486 ED_region_header_init(ar); 00487 00488 keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0); 00489 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00490 } 00491 00492 static void file_header_area_draw(const bContext *C, ARegion *ar) 00493 { 00494 ED_region_header(C, ar); 00495 } 00496 00497 /* add handlers, stuff you only do once or on area/region changes */ 00498 static void file_ui_area_init(wmWindowManager *wm, ARegion *ar) 00499 { 00500 wmKeyMap *keymap; 00501 00502 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); 00503 00504 /* own keymap */ 00505 keymap= WM_keymap_find(wm->defaultconf, "File Browser", SPACE_FILE, 0); 00506 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00507 00508 keymap= WM_keymap_find(wm->defaultconf, "File Browser Buttons", SPACE_FILE, 0); 00509 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00510 } 00511 00512 static void file_ui_area_draw(const bContext *C, ARegion *ar) 00513 { 00514 float col[3]; 00515 /* clear */ 00516 UI_GetThemeColor3fv(TH_PANEL, col); 00517 glClearColor(col[0], col[1], col[2], 0.0); 00518 glClear(GL_COLOR_BUFFER_BIT); 00519 00520 /* scrolling here is just annoying, disable it */ 00521 ar->v2d.cur.ymax= ar->v2d.cur.ymax - ar->v2d.cur.ymin; 00522 ar->v2d.cur.ymin= 0; 00523 00524 /* set view2d view matrix for scrolling (without scrollers) */ 00525 UI_view2d_view_ortho(&ar->v2d); 00526 00527 00528 file_draw_buttons(C, ar); 00529 00530 UI_view2d_view_restore(C); 00531 } 00532 00533 static void file_ui_area_listener(ARegion *ar, wmNotifier *wmn) 00534 { 00535 /* context changes */ 00536 switch(wmn->category) { 00537 case NC_SPACE: 00538 switch (wmn->data) { 00539 case ND_SPACE_FILE_LIST: 00540 ED_region_tag_redraw(ar); 00541 break; 00542 } 00543 break; 00544 } 00545 } 00546 00547 /* only called once, from space/spacetypes.c */ 00548 void ED_spacetype_file(void) 00549 { 00550 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype file"); 00551 ARegionType *art; 00552 00553 st->spaceid= SPACE_FILE; 00554 strncpy(st->name, "File", BKE_ST_MAXNAME); 00555 00556 st->new= file_new; 00557 st->free= file_free; 00558 st->init= file_init; 00559 st->duplicate= file_duplicate; 00560 st->refresh= file_refresh; 00561 st->listener= file_listener; 00562 st->operatortypes= file_operatortypes; 00563 st->keymap= file_keymap; 00564 00565 /* regions: main window */ 00566 art= MEM_callocN(sizeof(ARegionType), "spacetype file region"); 00567 art->regionid = RGN_TYPE_WINDOW; 00568 art->init= file_main_area_init; 00569 art->draw= file_main_area_draw; 00570 art->listener= file_main_area_listener; 00571 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; 00572 BLI_addhead(&st->regiontypes, art); 00573 00574 /* regions: header */ 00575 art= MEM_callocN(sizeof(ARegionType), "spacetype file region"); 00576 art->regionid = RGN_TYPE_HEADER; 00577 art->prefsizey= HEADERY; 00578 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER; 00579 art->init= file_header_area_init; 00580 art->draw= file_header_area_draw; 00581 // art->listener= file_header_area_listener; 00582 BLI_addhead(&st->regiontypes, art); 00583 00584 /* regions: ui */ 00585 art= MEM_callocN(sizeof(ARegionType), "spacetype file region"); 00586 art->regionid = RGN_TYPE_UI; 00587 art->prefsizey= 60; 00588 art->keymapflag= ED_KEYMAP_UI; 00589 art->listener= file_ui_area_listener; 00590 art->init= file_ui_area_init; 00591 art->draw= file_ui_area_draw; 00592 BLI_addhead(&st->regiontypes, art); 00593 00594 /* regions: channels (directories) */ 00595 art= MEM_callocN(sizeof(ARegionType), "spacetype file region"); 00596 art->regionid = RGN_TYPE_CHANNELS; 00597 art->prefsizex= 240; 00598 art->keymapflag= ED_KEYMAP_UI; 00599 art->listener= file_channel_area_listener; 00600 art->init= file_channel_area_init; 00601 art->draw= file_channel_area_draw; 00602 BLI_addhead(&st->regiontypes, art); 00603 file_panels_register(art); 00604 00605 BKE_spacetype_register(st); 00606 00607 } 00608 00609 void ED_file_init(void) 00610 { 00611 char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL); 00612 00613 fsmenu_read_system(fsmenu_get()); 00614 00615 if (cfgdir) { 00616 char name[FILE_MAX]; 00617 BLI_make_file_string("/", name, cfgdir, BLENDER_BOOKMARK_FILE); 00618 fsmenu_read_bookmarks(fsmenu_get(), name); 00619 } 00620 00621 filelist_init_icons(); 00622 IMB_thumb_makedirs(); 00623 } 00624 00625 void ED_file_exit(void) 00626 { 00627 fsmenu_free(fsmenu_get()); 00628 filelist_free_icons(); 00629 }