diff options
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 113 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 29 |
3 files changed, 99 insertions, 48 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 339ebe27fcd..780b99c3cae 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -505,6 +505,7 @@ void file_draw_list(const bContext *C, ARegion *ar) struct FileList* files = sfile->files; struct direntry *file; int numfiles; + int numfiles_layout; int colorid = 0; short sx, sy; int offset; @@ -543,8 +544,10 @@ void file_draw_list(const bContext *C, ARegion *ar) sx = ar->v2d.cur.xmin + layout->tile_border_x; sy = ar->v2d.cur.ymax - layout->tile_border_y; + + numfiles_layout = ED_fileselect_layout_numfiles(layout, ar); - for (i=offset; (i < numfiles); ++i) + for (i=offset; (i < numfiles) && (i<offset+numfiles_layout); ++i) { ED_fileselect_layout_tilepos(layout, i, &sx, &sy); sx += v2d->tot.xmin+2; diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 72f97898891..bd271c6fb4b 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -141,6 +141,21 @@ void ED_fileselect_reset_params(SpaceFile *sfile) sfile->params->title[0] = '\0'; } +int ED_fileselect_layout_numfiles(FileLayout* layout, struct ARegion *ar) +{ + int numfiles; + short width, height; + + if (layout->flag & FILE_LAYOUT_HOR) { + short width = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*layout->tile_border_x; + numfiles = width/layout->tile_w + 1; + } else { + short height = ar->v2d.cur.ymax - ar->v2d.cur.ymin - 2*layout->tile_border_y; + numfiles = height/layout->tile_h + 1; + } + + return layout->columns*layout->rows; +} int ED_fileselect_layout_offset(FileLayout* layout, int x, int y) { @@ -227,68 +242,78 @@ static void column_widths(struct FileList* files, struct FileLayout* layout) void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar) { - FileSelectParams* params = ED_fileselect_get_params(sfile); + FileSelectParams *params = ED_fileselect_get_params(sfile); + FileLayout *layout=0; View2D *v2d= &ar->v2d; int maxlen = 0; - int numfiles = filelist_numfiles(sfile->files); - int textheight = file_font_pointsize(); + int numfiles; + int textheight; if (sfile->layout == 0) { sfile->layout = MEM_callocN(sizeof(struct FileLayout), "file_layout"); - } + sfile->layout->dirty = 1; + } + + if (!sfile->layout->dirty) return; + + numfiles = filelist_numfiles(sfile->files); + textheight = file_font_pointsize(); + layout = sfile->layout; + if (params->display == FILE_IMGDISPLAY) { - sfile->layout->prv_w = 96; - sfile->layout->prv_h = 96; - sfile->layout->tile_border_x = 6; - sfile->layout->tile_border_y = 6; - sfile->layout->prv_border_x = 6; - sfile->layout->prv_border_y = 6; - sfile->layout->tile_w = sfile->layout->prv_w + 2*sfile->layout->prv_border_x; - sfile->layout->tile_h = sfile->layout->prv_h + 2*sfile->layout->prv_border_y + textheight; - sfile->layout->width= (v2d->cur.xmax - v2d->cur.xmin - 2*sfile->layout->tile_border_x); - sfile->layout->columns= sfile->layout->width / (sfile->layout->tile_w + 2*sfile->layout->tile_border_x); - if(sfile->layout->columns > 0) - sfile->layout->rows= numfiles/sfile->layout->columns + 1; // XXX dirty, modulo is zero + layout->prv_w = 96; + layout->prv_h = 96; + layout->tile_border_x = 6; + layout->tile_border_y = 6; + layout->prv_border_x = 6; + layout->prv_border_y = 6; + layout->tile_w = layout->prv_w + 2*layout->prv_border_x; + layout->tile_h = layout->prv_h + 2*layout->prv_border_y + textheight; + layout->width= (v2d->cur.xmax - v2d->cur.xmin - 2*layout->tile_border_x); + layout->columns= layout->width / (layout->tile_w + 2*layout->tile_border_x); + if(layout->columns > 0) + layout->rows= numfiles/layout->columns + 1; // XXX dirty, modulo is zero else { - sfile->layout->columns = 1; - sfile->layout->rows= numfiles + 1; // XXX dirty, modulo is zero + layout->columns = 1; + layout->rows= numfiles + 1; // XXX dirty, modulo is zero } - sfile->layout->height= sfile->layout->rows*(sfile->layout->tile_h+2*sfile->layout->tile_border_y) + sfile->layout->tile_border_y*2; - sfile->layout->flag = FILE_LAYOUT_VER; + layout->height= sfile->layout->rows*(layout->tile_h+2*layout->tile_border_y) + layout->tile_border_y*2; + layout->flag = FILE_LAYOUT_VER; } else { - sfile->layout->prv_w = 0; - sfile->layout->prv_h = 0; - sfile->layout->tile_border_x = 8; - sfile->layout->tile_border_y = 2; - sfile->layout->prv_border_x = 0; - sfile->layout->prv_border_y = 0; - sfile->layout->tile_h = textheight*3/2; - sfile->layout->height= v2d->cur.ymax - v2d->cur.ymin; - sfile->layout->rows = sfile->layout->height / (sfile->layout->tile_h + 2*sfile->layout->tile_border_y);; + layout->prv_w = 0; + layout->prv_h = 0; + layout->tile_border_x = 8; + layout->tile_border_y = 2; + layout->prv_border_x = 0; + layout->prv_border_y = 0; + layout->tile_h = textheight*3/2; + layout->height= v2d->cur.ymax - v2d->cur.ymin - 2*layout->tile_border_y; + layout->rows = layout->height / (layout->tile_h + 2*layout->tile_border_y); - column_widths(sfile->files, sfile->layout); + column_widths(sfile->files, layout); if (params->display == FILE_SHORTDISPLAY) { - maxlen = sfile->layout->column_widths[COLUMN_NAME] + - sfile->layout->column_widths[COLUMN_SIZE]; + maxlen = layout->column_widths[COLUMN_NAME] + + layout->column_widths[COLUMN_SIZE]; maxlen += 20+2*10; // for icon and space between columns } else { - maxlen = sfile->layout->column_widths[COLUMN_NAME] + - sfile->layout->column_widths[COLUMN_DATE] + - sfile->layout->column_widths[COLUMN_TIME] + - sfile->layout->column_widths[COLUMN_SIZE]; + maxlen = layout->column_widths[COLUMN_NAME] + + layout->column_widths[COLUMN_DATE] + + layout->column_widths[COLUMN_TIME] + + layout->column_widths[COLUMN_SIZE]; /* XXX add mode1, mode2, mode3, owner columns for non-windows platforms */ maxlen += 20+4*10; // for icon and space between columns } - sfile->layout->tile_w = maxlen + 40; - if(sfile->layout->rows > 0) - sfile->layout->columns = numfiles/sfile->layout->rows + 1; // XXX dirty, modulo is zero + layout->tile_w = maxlen + 40; + if(layout->rows > 0) + layout->columns = numfiles/layout->rows + 1; // XXX dirty, modulo is zero else { - sfile->layout->rows = 1; - sfile->layout->columns = numfiles + 1; // XXX dirty, modulo is zero + layout->rows = 1; + layout->columns = numfiles + 1; // XXX dirty, modulo is zero } - sfile->layout->width = sfile->layout->columns * (sfile->layout->tile_w + 2*sfile->layout->tile_border_x) + sfile->layout->tile_border_x*2; - sfile->layout->flag = FILE_LAYOUT_HOR; - } + layout->width = sfile->layout->columns * (layout->tile_w + 2*layout->tile_border_x) + layout->tile_border_x*2; + layout->flag = FILE_LAYOUT_HOR; + } + layout->dirty= 0; } FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar) diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 5af79eb2800..077ad65830c 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -153,6 +153,7 @@ static void file_free(SpaceLink *sl) /* spacetype; init callback, area size changes, screen set, etc */ static void file_init(struct wmWindowManager *wm, ScrArea *sa) { + printf("file_init\n"); } @@ -200,6 +201,9 @@ static void file_refresh(const bContext *C, ScrArea *sa) } filelist_setfilter(sfile->files, params->flag & FILE_FILTER ? params->filter : 0); if(params->sort!=FILE_SORT_NONE) filelist_sort(sfile->files, params->sort); + + if (sfile->layout) sfile->layout->dirty= 1; + } static void file_listener(ScrArea *sa, wmNotifier *wmn) @@ -213,11 +217,9 @@ static void file_listener(ScrArea *sa, wmNotifier *wmn) case ND_FILELIST: if (sfile->files) filelist_free(sfile->files); ED_area_tag_refresh(sa); - ED_area_tag_redraw(sa); break; case ND_PARAMS: ED_area_tag_refresh(sa); - ED_area_tag_redraw(sa); break; } break; @@ -241,6 +243,23 @@ static void file_main_area_init(wmWindowManager *wm, ARegion *ar) } +static void file_main_area_listener(ARegion *ar, wmNotifier *wmn) +{ + /* context changes */ + switch(wmn->category) { + case NC_FILE: + switch (wmn->data) { + case ND_FILELIST: + ED_region_tag_redraw(ar); + break; + case ND_PARAMS: + ED_region_tag_redraw(ar); + break; + } + break; + } +} + static void file_main_area_draw(const bContext *C, ARegion *ar) { /* draw entirely, view changes should be handled here */ @@ -252,6 +271,10 @@ static void file_main_area_draw(const bContext *C, ARegion *ar) View2DScrollers *scrollers; float col[3]; + /* Needed, because filelist is not initialized on loading */ + if (!sfile->files) + file_refresh(C, NULL); + layout = ED_fileselect_get_layout(sfile, ar); /* clear and setup matrix */ @@ -471,7 +494,7 @@ void ED_spacetype_file(void) art->regionid = RGN_TYPE_WINDOW; art->init= file_main_area_init; art->draw= file_main_area_draw; - // art->listener= file_main_area_listener; + art->listener= file_main_area_listener; art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; BLI_addhead(&st->regiontypes, art); |