diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-11 18:54:59 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-11 18:54:59 +0300 |
commit | c490862b7fb04550364ce98f98b9e4d1fcaa13b8 (patch) | |
tree | d3384f4a1623bd448a66ab34ecf7901ba20c2d83 /src/bookmarks.c | |
parent | eb357db5822822c36c395080dac22230efdc54fd (diff) |
Preferences: Add bookmarks to bottom/top
IssueID #358
Diffstat (limited to 'src/bookmarks.c')
-rw-r--r-- | src/bookmarks.c | 21 |
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 | ||
330 | static int maxOrder_Bookmarks_(const iBookmarks *d) { | 330 | static 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); |