2.5 filebrowser
authorAndrea Weikert <elubie@gmx.net>
Mon, 9 Mar 2009 21:17:19 +0000 (21:17 +0000)
committerAndrea Weikert <elubie@gmx.net>
Mon, 9 Mar 2009 21:17:19 +0000 (21:17 +0000)
Some UI tweaks and fixes
* fixed some overlapping buttons (Matt, feel free to change button arrangement if you like), the Bookmark (B) button should probably be removed eventually from the current place and the fsmenu button as well, now that we have the directories on the left panel.
* fixed initialisation of params->display
(aligorith: thanks for fixing, I did reset the #defines, since it was just missing the correct value in the initialisation)
* fixed bug when area became too small (crash)
* fixed bug (last file missing in long display)
* fixed selection when mouse outside tiles.

source/blender/editors/include/ED_fileselect.h
source/blender/editors/space_file/file_draw.c
source/blender/editors/space_file/filesel.c
source/blender/windowmanager/intern/wm_event_system.c

index b598175e22ef081f09a9e0ce940de59b4802207f..bb5ced664289f5ec25fe325c214f70f30b6a0723 100644 (file)
 
 struct SpaceFile;
 
-// XXX for Elubie:
-//     defining FILE_LONGDISPLAY as 0 for now, since that seems to be the default case
-//     for drawing the files (so that scrollbars will draw correct). 
-//     Dunno if these values are saved in files, so hopefully this is ok.
-//     Revert this change if there's a more correct way to do this
-// Aligorith (09Mar2009)
-#define FILE_LONGDISPLAY       0
 #define FILE_SHORTDISPLAY      1
-//#define FILE_LONGDISPLAY     2
+#define FILE_LONGDISPLAY       2
 #define FILE_IMGDISPLAY                3
 
 typedef struct FileSelectParams {
index c22815882870c7650e23bf3d120fbb41c3121670..d6b9a325a1a48c7601ca21ea34695b284434d205 100644 (file)
@@ -113,9 +113,9 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
        char name[20];
        char *menu;
        float slen;
-       float parentbut_width = 20;
-       float bookmarkbut_width = 0.0f;
-       float file_start_width = 0.0f;
+       float button_width = 20.0f;
+       float fsmenubut_width = 0.0f;
+       float bookmarkbut_width = button_width;
 
        int filebuty1, filebuty2;
 
@@ -150,11 +150,11 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
        menu= fsmenu_build_menu();
 
        if (menu[0]&& (params->type != FILE_MAIN)) {
-               bookmarkbut_width = file_start_width;
+               fsmenubut_width = button_width;
        }
 
-       uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"",      xmin+file_start_width+bookmarkbut_width+2, filebuty1, xmax-xmin-loadbutton-file_start_width, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
-       uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"",       xmin+file_start_width+bookmarkbut_width+2, filebuty2, xmax-xmin-loadbutton-file_start_width, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
+       uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"",      xmin+bookmarkbut_width+2, filebuty1, xmax-xmin-loadbutton-bookmarkbut_width-4, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
+       uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"",       xmin+fsmenubut_width+2, filebuty2, xmax-xmin-loadbutton-fsmenubut_width-4, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
        
        if(loadbutton) {
                uiSetCurFont(block, UI_HELV);
@@ -166,8 +166,8 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
           disallow external directory browsing for databrowse */
 
        if(menu[0] && (params->type != FILE_MAIN))      { 
-               uiDefButS(block, MENU, 0 /* B_FS_DIR_MENU */, menu, xmin, filebuty1, parentbut_width, 21, &params->menu, 0, 0, 0, 0, "");
-               uiDefBut(block, BUT, 0 /* B_FS_BOOKMARK */, "B", xmin+22, filebuty1, bookmarkbut_width, 21, 0, 0, 0, 0, 0, "Bookmark current directory");
+               uiDefButS(block, MENU, 0 /* B_FS_DIR_MENU */, menu, xmin, filebuty2, fsmenubut_width, 21, &params->menu, 0, 0, 0, 0, "");
+               uiDefBut(block, BUT, 0 /* B_FS_BOOKMARK */, "B", xmin, filebuty1, bookmarkbut_width, 21, 0, 0, 0, 0, 0, "Bookmark current directory");
        }
 
        MEM_freeN(menu);
@@ -506,31 +506,37 @@ void file_draw_list(const bContext *C, ARegion *ar)
                if (params->display != FILE_SHOWSHORT) {
 #if 0 // XXX TODO: add this for non-windows systems
                        /* rwx rwx rwx */
-                       x += 20; glRasterPos2i(x, y); 
-                       BMF_DrawString(G.font, files->mode1); 
-               
-                       x += 30; glRasterPos2i(x, y); 
-                       BMF_DrawString(G.font, files->mode2); 
-               
-                       x += 30; glRasterPos2i(x, y); 
-                       BMF_DrawString(G.font, files->mode3); 
-               
-                       /* owner time date */
-                       x += 30; glRasterPos2i(x, y); 
-                       BMF_DrawString(G.font, files->owner); 
+                       spos += 20;
+                       sw = UI_GetStringWidth(G.font, file->mode1, 0);
+                       file_draw_string(spos, sy, file->mode1, sw, layout->tile_h); 
+                       
+                       spos += 30;
+                       sw = UI_GetStringWidth(G.font, file->mode2, 0);
+                       file_draw_string(spos, sy, file->mode2, sw, layout->tile_h);
+
+                       spos += 30;
+                       sw = UI_GetStringWidth(G.font, file->mode3, 0);
+                       file_draw_string(spos, sy, file->mode3, sw, layout->tile_h);
+                       
+                       spos += 30;
+                       sw = UI_GetStringWidth(G.font, file->owner, 0);
+                       file_draw_string(spos, sy, file->owner, sw, layout->tile_h);
 #endif
-                       spos += 60;
-                       sw = UI_GetStringWidth(G.font, file->time, 0);
-                       file_draw_string(spos, sy, file->time, sw, layout->tile_h); 
-                       spos += sw;
+
                        spos += 50;
                        sw = UI_GetStringWidth(G.font, file->date, 0);
                        file_draw_string(spos, sy, file->date, sw, layout->tile_h);
 
+                       spos += 100;
+                       sw = UI_GetStringWidth(G.font, file->time, 0);
+                       file_draw_string(spos, sy, file->time, sw, layout->tile_h); 
+                       
+                       sw = UI_GetStringWidth(G.font, file->size, 0);
+                       spos += 200-sw;
+                       file_draw_string(spos, sy, file->size, sw, layout->tile_h);
+               } else {
+                       file_draw_string(sx + layout->tile_w - 2*layout->tile_border_x - sw - 4, sy, file->size, layout->tile_w - layout->tile_border_x - sw - 5, layout->tile_h);
                }
-
-               file_draw_string(sx + layout->tile_w - 2*layout->tile_border_x - sw - 4, sy, file->size, layout->tile_w - layout->tile_border_x - sw - 5, layout->tile_h);
-
        }
 }
 
index ae4bc9e639cd4e9ee06489660d8a64e8543274ba..32e2e50a3cdef00be2c101aa9dd286acad17250c 100644 (file)
@@ -144,6 +144,9 @@ int ED_fileselect_layout_offset(FileLayout* layout, int x, int y)
        offsetx = (x)/(layout->tile_w + 2*layout->tile_border_x);
        offsety = (y)/(layout->tile_h + 2*layout->tile_border_y);
        
+       if (offsetx > layout->columns-1) offsetx = layout->columns-1 ;
+       if (offsety > layout->rows-1) offsety = layout->rows-1 ;
+
        if (layout->flag & FILE_LAYOUT_HOR) 
                active_file = layout->rows*offsetx + offsety;
        else
@@ -189,10 +192,12 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar)
                sfile->layout->tile_h = sfile->layout->prv_h + 2*sfile->layout->prv_border_y + U.fontsize;
                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)
+               if(sfile->layout->columns > 0)
                        sfile->layout->rows= numfiles/sfile->layout->columns + 1; // XXX dirty, modulo is zero
-               else
+               else {
+                       sfile->layout->columns = 1;
                        sfile->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;
        } else if (params->display == FILE_SHORTDISPLAY) {
@@ -211,8 +216,10 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar)
                sfile->layout->tile_w = maxlen + 100;
                if(sfile->layout->rows > 0)
                        sfile->layout->columns = numfiles/sfile->layout->rows + 1; // XXX dirty, modulo is zero
-               else
+               else {
+                       sfile->layout->rows = 1;
                        sfile->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;
        } else {
@@ -225,7 +232,7 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar)
                sfile->layout->tile_w = v2d->cur.xmax - v2d->cur.xmin - 2*sfile->layout->tile_border_x;
                sfile->layout->tile_h = U.fontsize*3/2;
                sfile->layout->width= (v2d->cur.xmax - v2d->cur.xmin + 2*sfile->layout->tile_border_x);
-               sfile->layout->rows= numfiles;
+               sfile->layout->rows= numfiles+1;
                sfile->layout->columns= 1;
                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;
index 8c06be7a37ea42bca8d8a58b02a8b8e96b5d222f..2b08f5a894376e170a2e75a33653a84b78cba79a 100644 (file)
@@ -776,7 +776,7 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa
                                sfile= (SpaceFile*)CTX_wm_space_data(C);
                                sfile->op= handler->op;
                                
-                               ED_fileselect_set_params(sfile, filetype, handler->op->type->name, path, 0, 0, 0);
+                               ED_fileselect_set_params(sfile, filetype, handler->op->type->name, path, 0, FILE_SHORTDISPLAY, 0);
                                MEM_freeN(path);
                                
                                action= WM_HANDLER_BREAK;