summaryrefslogtreecommitdiff
path: root/src/ui/sidebarwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r--src/ui/sidebarwidget.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index aaa6e9e9..4d229c59 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -1095,21 +1095,24 @@ static iBool handleSidebarCommand_SidebarWidget_(iSidebarWidget *d, const char *
1095 return iFalse; 1095 return iFalse;
1096} 1096}
1097 1097
1098static void bookmarkMoved_SidebarWidget_(iSidebarWidget *d, size_t index, size_t beforeIndex) { 1098static void bookmarkMoved_SidebarWidget_(iSidebarWidget *d, size_t index, size_t dstIndex,
1099 iBool isBefore) {
1099 const iSidebarItem *movingItem = item_ListWidget(d->list, index); 1100 const iSidebarItem *movingItem = item_ListWidget(d->list, index);
1100 const iBool isLast = (beforeIndex == numItems_ListWidget(d->list)); 1101 const iBool isLast = (dstIndex == numItems_ListWidget(d->list));
1101 const iSidebarItem *dstItem = item_ListWidget(d->list, 1102 const iSidebarItem *dstItem = item_ListWidget(d->list,
1102 isLast ? numItems_ListWidget(d->list) - 1 1103 isLast ? numItems_ListWidget(d->list) - 1
1103 : beforeIndex); 1104 : dstIndex);
1105 if (isLast && isBefore) isBefore = iFalse;
1104 const iBookmark *dst = get_Bookmarks(bookmarks_App(), dstItem->id); 1106 const iBookmark *dst = get_Bookmarks(bookmarks_App(), dstItem->id);
1105 if (hasParent_Bookmark(dst, movingItem->id)) { 1107 if (hasParent_Bookmark(dst, movingItem->id) || hasTag_Bookmark(dst, remote_BookmarkTag)) {
1108 /* Can't move a folder inside itself, and remote bookmarks cannot be reordered. */
1106 return; 1109 return;
1107 } 1110 }
1108 reorder_Bookmarks(bookmarks_App(), movingItem->id, dst->order + (isLast ? 1 : 0)); 1111 reorder_Bookmarks(bookmarks_App(), movingItem->id, dst->order + (isBefore ? 0 : 1));
1109 get_Bookmarks(bookmarks_App(), movingItem->id)->parentId = dst->parentId; 1112 get_Bookmarks(bookmarks_App(), movingItem->id)->parentId = dst->parentId;
1110 updateItems_SidebarWidget_(d); 1113 updateItems_SidebarWidget_(d);
1111 /* Don't confuse the user: keep the dragged item in hover state. */ 1114 /* Don't confuse the user: keep the dragged item in hover state. */
1112 setHoverItem_ListWidget(d->list, index < beforeIndex ? beforeIndex - 1 : beforeIndex); 1115 setHoverItem_ListWidget(d->list, dstIndex + (isBefore ? 0 : 1) + (index < dstIndex ? -1 : 0));
1113 postCommandf_App("bookmarks.changed nosidebar:%p", d); /* skip this sidebar since we updated already */ 1116 postCommandf_App("bookmarks.changed nosidebar:%p", d); /* skip this sidebar since we updated already */
1114} 1117}
1115 1118
@@ -1243,17 +1246,19 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1243 } 1246 }
1244 else if (isCommand_Widget(w, ev, "list.dragged")) { 1247 else if (isCommand_Widget(w, ev, "list.dragged")) {
1245 iAssert(d->mode == bookmarks_SidebarMode); 1248 iAssert(d->mode == bookmarks_SidebarMode);
1246 if (hasLabel_Command(cmd, "before")) { 1249 if (hasLabel_Command(cmd, "onto")) {
1247 bookmarkMoved_SidebarWidget_(d,
1248 argU32Label_Command(cmd, "arg"),
1249 argU32Label_Command(cmd, "before"));
1250 }
1251 else {
1252 /* Dragged onto a folder. */ 1250 /* Dragged onto a folder. */
1253 bookmarkMovedOntoFolder_SidebarWidget_(d, 1251 bookmarkMovedOntoFolder_SidebarWidget_(d,
1254 argU32Label_Command(cmd, "arg"), 1252 argU32Label_Command(cmd, "arg"),
1255 argU32Label_Command(cmd, "onto")); 1253 argU32Label_Command(cmd, "onto"));
1256 } 1254 }
1255 else {
1256 const iBool isBefore = hasLabel_Command(cmd, "before");
1257 bookmarkMoved_SidebarWidget_(d,
1258 argU32Label_Command(cmd, "arg"),
1259 argU32Label_Command(cmd, isBefore ? "before" : "after"),
1260 isBefore);
1261 }
1257 return iTrue; 1262 return iTrue;
1258 } 1263 }
1259 else if (isCommand_Widget(w, ev, "menu.closed")) { 1264 else if (isCommand_Widget(w, ev, "menu.closed")) {