2.5 file browser
* remove '.' and '..' from file browser list. sigh! * removed delete buttons from automatically added bookmarks (Desktop and Documents) Note: please check on non-Windows platforms
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user