From a5003727c59859e8e9e2650ce18532ebc5771a88 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 17 Sep 2012 02:01:09 +0000 Subject: code cleanup: replace fsmenu_insert_entry args with flags. --- source/blender/editors/space_file/file_ops.c | 4 ++-- source/blender/editors/space_file/fsmenu.c | 23 ++++++++++++----------- source/blender/editors/space_file/fsmenu.h | 7 ++++++- 3 files changed, 20 insertions(+), 14 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 040f276940d..aa423448e45 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -459,7 +459,7 @@ static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op)) if (params->dir[0] != '\0') { char name[FILE_MAX]; - fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, FS_INSERT_SAVE); BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(fsmenu, name); } @@ -771,7 +771,7 @@ int file_exec(bContext *C, wmOperator *exec_op) file_sfile_to_operator(op, sfile, filepath); if (BLI_exists(sfile->params->dir)) - fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, 0, 1); + fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, FS_INSERT_SAVE); BLI_make_file_string(G.main->name, filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(fsmenu_get(), filepath); diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index a127e2ca2bc..474ec81ad93 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -159,7 +159,7 @@ short fsmenu_can_save(struct FSMenu *fsmenu, FSMenuCategory category, int idx) return fsme ? fsme->save : 0; } -void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, int sorted, short save) +void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, FSMenuInsert flag) { FSMenuEntry *prev; FSMenuEntry *fsme; @@ -174,7 +174,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c if (cmp_ret == 0) { return; } - else if (sorted && cmp_ret < 0) { + else if ((flag & FS_INSERT_SORTED) && cmp_ret < 0) { break; } } @@ -182,7 +182,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c /* if we're bookmarking this, file should come * before the last separator, only automatically added * current dir go after the last sep. */ - if (save) { + if (flag & FS_INSERT_SAVE) { break; } } @@ -190,7 +190,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c fsme = MEM_mallocN(sizeof(*fsme), "fsme"); fsme->path = BLI_strdup(path); - fsme->save = save; + fsme->save = (flag & FS_INSERT_SAVE) != 0; if (prev) { fsme->next = prev->next; @@ -288,7 +288,7 @@ void fsmenu_read_bookmarks(struct FSMenu *fsmenu, const char *filename) if (BLI_exists(line)) #endif { - fsmenu_insert_entry(fsmenu, category, line, 0, 1); + fsmenu_insert_entry(fsmenu, category, line, FS_INSERT_SAVE); } } } @@ -477,10 +477,10 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) if (read_bookmarks && home) { BLI_snprintf(line, FILE_MAXDIR, "%s/", home); - fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, FS_INSERT_SORTED); BLI_snprintf(line, FILE_MAXDIR, "%s/Desktop/", home); if (BLI_exists(line)) { - fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, FS_INSERT_SORTED); } } @@ -505,10 +505,11 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) len = strlen(mnt->mnt_dir); if (len && mnt->mnt_dir[len - 1] != '/') { BLI_snprintf(line, FILE_MAXDIR, "%s/", mnt->mnt_dir); - fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, 1, 0); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, FS_INSERT_SORTED); + } + else { + fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, FS_INSERT_SORTED); } - else - fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, 1, 0); found = 1; } @@ -520,7 +521,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) /* fallback */ if (!found) - fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", 1, 0); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", FS_INSERT_SORTED); } } #endif diff --git a/source/blender/editors/space_file/fsmenu.h b/source/blender/editors/space_file/fsmenu.h index d7576d71933..a16aab19842 100644 --- a/source/blender/editors/space_file/fsmenu.h +++ b/source/blender/editors/space_file/fsmenu.h @@ -43,6 +43,11 @@ typedef enum FSMenuCategory { FS_CATEGORY_RECENT } FSMenuCategory; +typedef enum FSMenuInsert { + FS_INSERT_SORTED = (1 << 0), + FS_INSERT_SAVE = (1 << 1) +} FSMenuInsert; + struct FSMenu; struct FSMenu *fsmenu_get(void); @@ -59,7 +64,7 @@ char *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int index * Duplicate entries are not added. * \param sorted Should entry be inserted in sorted order? */ -void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, int sorted, short save); +void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, const FSMenuInsert flag); /** 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); -- cgit v1.2.3