diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-09-11 23:33:13 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-09-11 23:33:13 +0300 |
commit | 26041f9357b02868e94545c2425b17d8da07f25b (patch) | |
tree | f50a7858c72a458fb9dbe19fd744650b0ebcd299 /source/blender/editors/space_file/fsmenu.c | |
parent | a79c519e5d24bdc926d422d64f3bb4567293a738 (diff) |
File Bookmarks: use volume label on Windows, and set name of recent entries
from system/user bookmarks' name if possible.
Volume label on Windows was request from T46083, makes Blender more in line
with 'common' filebrowsing on this OS.
And now, we automatically set name of recent entries from the bookmarks, if path
can be found there, more consistent too from user PoV.
Diffstat (limited to 'source/blender/editors/space_file/fsmenu.c')
-rw-r--r-- | source/blender/editors/space_file/fsmenu.c | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index fdf7b458865..2142368f758 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -292,6 +292,30 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c fsm_iter = MEM_mallocN(sizeof(*fsm_iter), "fsme"); fsm_iter->path = BLI_strdup(path); fsm_iter->save = (flag & FS_INSERT_SAVE) != 0; + + if ((category == FS_CATEGORY_RECENT) && (!name || !name[0])) { + /* Special handling when adding new recent entry - check if dir exists in some other categories, + * and try to use name from there if so. */ + FSMenuCategory cats[] = {FS_CATEGORY_SYSTEM, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_CATEGORY_BOOKMARKS}; + int i = ARRAY_SIZE(cats); + + while (i--) { + FSMenuEntry *tfsm = ED_fsmenu_get_category(fsmenu, cats[i]); + + for (; tfsm; tfsm = tfsm->next) { + if (STREQ(tfsm->path, fsm_iter->path)) { + if (tfsm->name && tfsm->name[0]) { + name = tfsm->name; + } + break; + } + } + if (tfsm) { + break; + } + } + } + if (name && name[0]) { BLI_strncpy(fsm_iter->name, name, sizeof(fsm_iter->name)); } @@ -439,19 +463,36 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) { wchar_t wline[FILE_MAXDIR]; __int64 tmp; - char tmps[4]; + char tmps[4], *name; int i; - + tmp = GetLogicalDrives(); - + for (i = 0; i < 26; i++) { if ((tmp >> i) & 1) { tmps[0] = 'A' + i; tmps[1] = ':'; tmps[2] = '\\'; - tmps[3] = 0; - - fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, NULL, FS_INSERT_SORTED); + tmps[3] = '\0'; + name = NULL; + + /* Flee from horrible win querying hover floppy drives! */ + if (i > 1) { + /* Try to get volume label as well... */ + BLI_strncpy_wchar_from_utf8(wline, tmps, 4); + if (GetVolumeInformationW(wline, wline + 4, FILE_MAXDIR - 4, NULL, NULL, NULL, NULL, 0)) { + size_t label_len; + + BLI_strncpy_wchar_as_utf8(line, wline + 4, FILE_MAXDIR - 4); + + label_len = MIN2(strlen(line), FILE_MAXDIR - 6); + BLI_snprintf(line + label_len, 6, " (%.2s)", tmps); + + name = line; + } + } + + fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, name, FS_INSERT_SORTED); } } |