2.5 file browser
authorAndrea Weikert <elubie@gmx.net>
Mon, 29 Jun 2009 23:21:11 +0000 (23:21 +0000)
committerAndrea Weikert <elubie@gmx.net>
Mon, 29 Jun 2009 23:21:11 +0000 (23:21 +0000)
* remove '.' and '..' from file browser list. sigh!
* removed delete buttons from automatically added bookmarks (Desktop and Documents)
Note: please check on non-Windows platforms

source/blender/blenlib/intern/storage.c
source/blender/editors/space_file/file_ops.c
source/blender/editors/space_file/file_panels.c
source/blender/editors/space_file/fsmenu.c
source/blender/editors/space_file/fsmenu.h

index 0ae17a13e438e7b4d16678cd4fd821ece3dc5b42..3204d5f74e19847fdff625564cf6ee421876eda3 100644 (file)
@@ -218,7 +218,7 @@ void BLI_builddir(char *dirname, char *relname)
 {
        struct dirent *fname;
        struct dirlink *dlink;
-       int rellen, newnum = 0, seen_ = 0, seen__ = 0;
+       int rellen, newnum = 0, ignore;
        char buf[256];
        DIR *dir;
 
@@ -238,21 +238,17 @@ void BLI_builddir(char *dirname, char *relname)
        if ( (dir = (DIR *)opendir(".")) ){
                while ((fname = (struct dirent*) readdir(dir)) != NULL) {
                        
-                       if(hide_dot && fname->d_name[0]=='.' && fname->d_name[1]!='.' && fname->d_name[1]!=0);
+                       if(hide_dot && fname->d_name[0]=='.' && fname->d_name[1]!='.' && fname->d_name[1]!=0) {
+                       }
+                       else if ( ( (fname->d_name[0] == '.') && (fname->d_name[1] == 0) ) ||
+                                         ( (fname->d_name[0] == '.') && (fname->d_name[1] == '.') && (fname->d_name[2] == 0)) ) {
+                               /* ignore '.' and '..' */
+                       }
                        else {
-                               
                                dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
                                if (dlink){
                                        strcpy(buf+rellen,fname->d_name);
-       
                                        dlink->name = BLI_strdup(buf);
-       
-                                       if (dlink->name[0] == '.') {
-                                               if (dlink->name[1] == 0) seen_ = 1;
-                                               else if (dlink->name[1] == '.') {
-                                                       if (dlink->name[2] == 0) seen__ = 1;
-                                               }
-                                       }
                                        BLI_addhead(dirbase,dlink);
                                        newnum++;
                                }
@@ -260,30 +256,6 @@ void BLI_builddir(char *dirname, char *relname)
                }
                
                if (newnum){
-#ifndef WIN32          
-                       if (seen_ == 0) {       /* Cachefs PATCH */
-                               dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
-                               strcpy(buf+rellen,"./.");
-                               dlink->name = BLI_strdup(buf);
-                               BLI_addhead(dirbase,dlink);
-                               newnum++;
-                       }
-                       if (seen__ == 0) {      /* MAC PATCH */
-                               dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
-                               strcpy(buf+rellen,"./..");
-                               dlink->name = BLI_strdup(buf);
-                               BLI_addhead(dirbase,dlink);
-                               newnum++;
-                       }
-#else // WIN32
-                       if (seen_ == 0) {       /* should only happen for root paths like "C:\" */
-                               dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
-                               strcpy(buf+rellen,".");
-                               dlink->name = BLI_strdup(buf);
-                               BLI_addhead(dirbase,dlink);
-                               newnum++;
-                       }
-#endif                 
 
                        if (files) files=(struct direntry *)realloc(files,(totnum+newnum) * sizeof(struct direntry));
                        else files=(struct direntry *)malloc(newnum * sizeof(struct direntry));
index dd20c8e822454f6a44afe819784d0f27f9098303..3e24f360e40e2ebde9dcc2c7099fec406c247d9a 100644 (file)
@@ -137,22 +137,15 @@ static void file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short v
                params->active_file = last_file;
 
                if(file && S_ISDIR(file->type)) {
-                       /* the path is too long and we are not going up! */
-                       if (strcmp(file->relname, ".") &&
-                               strcmp(file->relname, "..") &&
-                               strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) 
+                       /* the path is too long! */
+                       if (strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) 
                        {
                                // XXX error("Path too long, cannot enter this directory");
                        } else {
-                               if (strcmp(file->relname, "..")==0) {
-                                       /* avoids /../../ */
-                                       BLI_parent_dir(params->dir);
-                               } else {
-                                       strcat(params->dir, file->relname);
-                                       strcat(params->dir,"/");
-                                       params->file[0] = '\0';
-                                       BLI_cleanup_dir(G.sce, params->dir);
-                               }
+                               strcat(params->dir, file->relname);
+                               strcat(params->dir,"/");
+                               params->file[0] = '\0';
+                               BLI_cleanup_dir(G.sce, params->dir);
                                filelist_setdir(sfile->files, params->dir);
                                filelist_free(sfile->files);
                                params->active_file = -1;
index b370624d312a8520a6dde0c5c2487885d783f2f1..560c509ddcb20c5c7157674ca0478d77e75bca9d 100644 (file)
@@ -44,7 +44,7 @@ static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory cat
                uiLayout* layout = uiLayoutRow(pa->layout, UI_LAYOUT_ALIGN_LEFT);
                char *fname = fsmenu_get_entry(fsmenu, category, i);
                uiItemStringO(layout, fname, icon, "FILE_OT_select_bookmark", "dir", fname);
-               if (allow_delete)
+               if (allow_delete && fsmenu_can_save(fsmenu, category, i) )
                        uiItemIntO(layout, "", ICON_X, "FILE_OT_delete_bookmark", "index", i);
        }
        uiBlockEndAlign(block);
index 59e8dcf82e609bc9ecad27d4ad33b7b9e8c4b4e9..a87ad4c4fd8091ce02bb56ac281d5ce560e1bfd7 100644 (file)
@@ -65,7 +65,6 @@ struct _FSMenuEntry {
 
        char *path;
        short save;
-       short xs, ys;
 };
 
 typedef struct FSMenu
@@ -74,9 +73,6 @@ typedef struct FSMenu
        FSMenuEntry *fsmenu_bookmarks;
        FSMenuEntry *fsmenu_recent;
 
-       FSMenuCategory selected_category;
-       int selected_entry;
-
 } FSMenu;
 
 static FSMenu *g_fsmenu = NULL;
@@ -89,17 +85,6 @@ struct FSMenu* fsmenu_get(void)
        return g_fsmenu;
 }
 
-void fsmenu_select_entry(struct FSMenu* fsmenu, FSMenuCategory category, int index)
-{
-       fsmenu->selected_category = category;
-       fsmenu->selected_entry = index;
-}
-
-int    fsmenu_is_selected(struct FSMenu* fsmenu, FSMenuCategory category, int index)
-{
-       return (category==fsmenu->selected_category) && (index==fsmenu->selected_entry);
-}
-
 static FSMenuEntry *fsmenu_get_category(struct FSMenu* fsmenu, FSMenuCategory category)
 {
        FSMenuEntry *fsms = NULL;
@@ -154,36 +139,16 @@ char *fsmenu_get_entry(struct FSMenu* fsmenu, FSMenuCategory category, int idx)
        return fsme?fsme->path:NULL;
 }
 
-void fsmenu_set_pos(struct FSMenu* fsmenu, FSMenuCategory category, int idx, short xs, short ys)
+short fsmenu_can_save (struct FSMenu* fsmenu, FSMenuCategory category, int idx)
 {
        FSMenuEntry *fsme;
 
        for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next)
                idx--;
 
-       if (fsme) {
-               fsme->xs = xs;
-               fsme->ys = ys;
-       }
+       return fsme?fsme->save:0;
 }
 
-int    fsmenu_get_pos (struct FSMenu* fsmenu, FSMenuCategory category, int idx, short* xs, short* ys)
-{
-       FSMenuEntry *fsme;
-
-       for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next)
-               idx--;
-
-       if (fsme) {
-               *xs = fsme->xs;
-               *ys = fsme->ys;
-               return 1;
-       }
-
-       return 0;
-}
-
-
 void fsmenu_insert_entry(struct FSMenu* fsmenu, FSMenuCategory category, char *path, int sorted, short save)
 {
        FSMenuEntry *prev;
index c51c45b7dc41f1cd23678cebd89c125ed6594102..2cab622d52367e370653ab357df10b0cec7fdf22 100644 (file)
@@ -52,22 +52,15 @@ int         fsmenu_get_nentries             (struct FSMenu* fsmenu, FSMenuCategory category);
         */
 char*  fsmenu_get_entry                (struct FSMenu* fsmenu, FSMenuCategory category, int index);
 
-void   fsmenu_select_entry             (struct FSMenu* fsmenu, FSMenuCategory category, int index);
-
-int            fsmenu_is_selected              (struct FSMenu* fsmenu, FSMenuCategory category, int index);
-
-       /** Sets the position of the  fsmenu entry at @a index */
-void   fsmenu_set_pos                  (struct FSMenu* fsmenu, FSMenuCategory category, int index, short xs, short ys);
-
-       /** Returns the position of the  fsmenu entry at @a index. return value is 1 if successful, 0 otherwise */
-int            fsmenu_get_pos                  (struct FSMenu* fsmenu, FSMenuCategory category, int index, short* xs, short* ys);
-
        /** Inserts a new fsmenu entry with the given @a path.
         * Duplicate entries are not added.
         * @param sorted Should entry be inserted in sorted order?
         */
 void   fsmenu_insert_entry             (struct FSMenu* fsmenu, FSMenuCategory category, char *path, int sorted, short save);
 
+       /** Return whether the entry was created by the user and can be saved and deleted */
+short   fsmenu_can_save                        (struct FSMenu* fsmenu, FSMenuCategory category, int index);
+
        /** Removes the fsmenu entry at the given @a index. */
 void   fsmenu_remove_entry             (struct FSMenu* fsmenu, FSMenuCategory category, int index);