summaryrefslogtreecommitdiff
path: root/src/bookmarks.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-11 18:54:59 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-19 11:15:30 +0300
commit65ae29b56803c1ba779ab9b0a6b09333482ee13a (patch)
treeb46703ee24ad816d6f2837ee1b013f5164d2fec3 /src/bookmarks.c
parent6770449bef6c04c7e6d10a26755fdd77c8b6947c (diff)
Preferences: Add bookmarks to bottom/top
IssueID #358 # Conflicts: # res/lang/de.bin # res/lang/en.bin # res/lang/eo.bin # res/lang/es.bin # res/lang/es_MX.bin # res/lang/fi.bin # res/lang/fr.bin # res/lang/gl.bin # res/lang/ia.bin # res/lang/ie.bin # res/lang/isv.bin # res/lang/pl.bin # res/lang/ru.bin # res/lang/sk.bin # res/lang/sr.bin # res/lang/tok.bin # res/lang/zh_Hans.bin # res/lang/zh_Hant.bin
Diffstat (limited to 'src/bookmarks.c')
-rw-r--r--src/bookmarks.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 67c6a25f..1a260f3a 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -327,11 +327,18 @@ void save_Bookmarks(const iBookmarks *d, const char *dirPath) {
327 unlock_Mutex(d->mtx); 327 unlock_Mutex(d->mtx);
328} 328}
329 329
330static int maxOrder_Bookmarks_(const iBookmarks *d) { 330static iRangei orderRange_Bookmarks_(const iBookmarks *d) {
331 int ord = 0; 331 iRangei ord = { 0, 0 };
332 iConstForEach(Hash, i, &d->bookmarks) { 332 iConstForEach(Hash, i, &d->bookmarks) {
333 const iBookmark *bm = (const iBookmark *) i.value; 333 const iBookmark *bm = (const iBookmark *) i.value;
334 ord = iMax(ord, bm->order); 334 if (isEmpty_Range(&ord)) {
335 ord.start = bm->order;
336 ord.end = bm->order + 1;
337 }
338 else {
339 ord.start = iMin(ord.start, bm->order);
340 ord.end = iMax(ord.end, bm->order + 1);
341 }
335 } 342 }
336 return ord; 343 return ord;
337} 344}
@@ -349,7 +356,13 @@ uint32_t add_Bookmarks(iBookmarks *d, const iString *url, const iString *title,
349 } 356 }
350 bm->icon = icon; 357 bm->icon = icon;
351 initCurrent_Time(&bm->when); 358 initCurrent_Time(&bm->when);
352 bm->order = maxOrder_Bookmarks_(d) + 1; /* Last in lists. */ 359 const iRangei ord = orderRange_Bookmarks_(d);
360 if (prefs_App()->addBookmarksToBottom) {
361 bm->order = ord.end; /* Last in lists. */
362 }
363 else {
364 bm->order = ord.start - 1; /* First in lists. */
365 }
353 insert_Bookmarks_(d, bm); 366 insert_Bookmarks_(d, bm);
354 unlock_Mutex(d->mtx); 367 unlock_Mutex(d->mtx);
355 return id_Bookmark(bm); 368 return id_Bookmark(bm);