Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-02-26 13:34:45 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-02-26 13:34:45 +0300
commit661b01825f811e949feae5ade8170efe09a716c2 (patch)
treed7e3d25d3d3c5e6f139e8ebcfdd17462bec666d0
parent4cf3977a742af1075301854f2291c8e12b1e537d (diff)
Fix for recent commit removing slashes
The slashed were used for comparing bookmarks to the current directory. Add trailing slashes in 'fsmenu_insert_entry', which avoids having to duplicate strings just to add a slash before passing to this function.
-rw-r--r--source/blender/editors/space_file/fsmenu.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index 1fbc07c7a5d..daa3495b1c4 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -380,6 +380,12 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
int icon,
FSMenuInsert flag)
{
+ const uint path_len = strlen(path);
+ BLI_assert(path_len > 0);
+ if (path_len == 0) {
+ return;
+ }
+ const bool has_trailing_slash = (path[path_len - 1] == SEP);
FSMenuEntry *fsm_prev;
FSMenuEntry *fsm_iter;
FSMenuEntry *fsm_head;
@@ -389,8 +395,9 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
for (fsm_iter = fsm_head; fsm_iter; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) {
if (fsm_iter->path) {
- const int cmp_ret = BLI_path_cmp(path, fsm_iter->path);
- if (cmp_ret == 0) {
+ /* Compare, with/without the trailing slash in 'path'. */
+ const int cmp_ret = BLI_path_ncmp(path, fsm_iter->path, path_len);
+ if (cmp_ret == 0 && STREQ(fsm_iter->path + path_len, has_trailing_slash ? "" : SEP_STR)) {
if (flag & FS_INSERT_FIRST) {
if (fsm_iter != fsm_head) {
fsm_prev->next = fsm_iter->next;
@@ -415,7 +422,14 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
}
fsm_iter = MEM_mallocN(sizeof(*fsm_iter), "fsme");
- fsm_iter->path = BLI_strdup(path);
+ if (has_trailing_slash) {
+ fsm_iter->path = BLI_strdup(path);
+ }
+ else {
+ fsm_iter->path = BLI_strdupn(path, path_len + 1);
+ fsm_iter->path[path_len] = SEP;
+ fsm_iter->path[path_len + 1] = '\0';
+ }
fsm_iter->save = (flag & FS_INSERT_SAVE) != 0;
/* If entry is also in another list, use that icon and maybe name. */
@@ -608,7 +622,6 @@ static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
if (SHGetKnownFolderPath(rfid, 0, NULL, &pPath) == S_OK) {
BLI_strncpy_wchar_as_utf8(line, pPath, FILE_MAXDIR);
CoTaskMemFree(pPath);
- BLI_add_slash(line);
fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, name, icon, flag);
}
}
@@ -745,9 +758,6 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
CFRelease(localKey);
}
- /* Add end slash for consistency with other platforms */
- BLI_add_slash(defPath);
-
fsmenu_insert_entry(
fsmenu, FS_CATEGORY_SYSTEM, defPath, name[0] ? name : NULL, icon, FS_INSERT_SORTED);
}
@@ -786,9 +796,6 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
/* Exclude "all my files" as it makes no sense in blender fileselector */
/* Exclude "airdrop" if wlan not active as it would show "" ) */
if (!strstr(line, "myDocuments.cannedSearch") && (*line != '\0')) {
- /* Add end slash for consistency with other platforms */
- BLI_add_slash(line);
-
fsmenu_insert_entry(
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_FILE_FOLDER, FS_INSERT_LAST);
}