summaryrefslogtreecommitdiff
path: root/src/bookmarks.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-11-23 11:45:43 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-11-23 11:45:43 +0200
commit54f142bb093765e19fcee30cc5ffe9c63b67abd6 (patch)
tree6b754c0cf450d10f34dfdcb10be61365d3964da8 /src/bookmarks.c
parentf9346b83551f95f9e32f963c0574540f2805eb23 (diff)
Select folder when adding/editing bookmarks
Most recently used folder is persistently stored in bookmarks.ini. IssueID #358
Diffstat (limited to 'src/bookmarks.c')
-rw-r--r--src/bookmarks.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 1a260f3a..d4b20162 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -96,7 +96,8 @@ struct Impl_Bookmarks {
96 iMutex * mtx; 96 iMutex * mtx;
97 int idEnum; 97 int idEnum;
98 iHash bookmarks; /* bookmark ID is the hash key */ 98 iHash bookmarks; /* bookmark ID is the hash key */
99 iPtrArray remoteRequests; 99 uint32_t recentFolderId; /* recently interacted with */
100 iPtrArray remoteRequests;
100}; 101};
101 102
102iDefineTypeConstruction(Bookmarks) 103iDefineTypeConstruction(Bookmarks)
@@ -105,6 +106,7 @@ void init_Bookmarks(iBookmarks *d) {
105 d->mtx = new_Mutex(); 106 d->mtx = new_Mutex();
106 d->idEnum = 0; 107 d->idEnum = 0;
107 init_Hash(&d->bookmarks); 108 init_Hash(&d->bookmarks);
109 d->recentFolderId = 0;
108 init_PtrArray(&d->remoteRequests); 110 init_PtrArray(&d->remoteRequests);
109} 111}
110 112
@@ -232,6 +234,9 @@ static void handleKeyValue_BookmarkLoader_(void *context, const iString *table,
232 bm->order = tv->value.int64; 234 bm->order = tv->value.int64;
233 } 235 }
234 } 236 }
237 else if (!cmp_String(key, "recentfolder") && tv->type == int64_TomlType) {
238 d->bookmarks->recentFolderId = tv->value.int64;
239 }
235} 240}
236 241
237static void init_BookmarkLoader(iBookmarkLoader *d, iBookmarks *bookmarks) { 242static void init_BookmarkLoader(iBookmarkLoader *d, iBookmarks *bookmarks) {
@@ -289,8 +294,10 @@ void save_Bookmarks(const iBookmarks *d, const char *dirPath) {
289 lock_Mutex(d->mtx); 294 lock_Mutex(d->mtx);
290 iRegExp *remotePattern = iClob(new_RegExp("\\bremote\\b", caseSensitive_RegExpOption)); 295 iRegExp *remotePattern = iClob(new_RegExp("\\bremote\\b", caseSensitive_RegExpOption));
291 iFile *f = newCStr_File(concatPath_CStr(dirPath, fileName_Bookmarks_)); 296 iFile *f = newCStr_File(concatPath_CStr(dirPath, fileName_Bookmarks_));
292 if (open_File(f, writeOnly_FileMode | text_FileMode)) { 297 if (open_File(f, writeOnly_FileMode | text_FileMode)) {
293 iString *str = collectNew_String(); 298 iString *str = collectNew_String();
299 format_String(str, "recentfolder = %u\n\n", d->recentFolderId);
300 writeData_File(f, cstr_String(str), size_String(str));
294 iConstForEach(Hash, i, &d->bookmarks) { 301 iConstForEach(Hash, i, &d->bookmarks) {
295 const iBookmark *bm = (const iBookmark *) i.value; 302 const iBookmark *bm = (const iBookmark *) i.value;
296 iRegExpMatch m; 303 iRegExpMatch m;
@@ -299,6 +306,7 @@ void save_Bookmarks(const iBookmarks *d, const char *dirPath) {
299 /* Remote bookmarks are not saved. */ 306 /* Remote bookmarks are not saved. */
300 continue; 307 continue;
301 } 308 }
309 iBeginCollect();
302 format_String(str, 310 format_String(str,
303 "[%d]\n" 311 "[%d]\n"
304 "url = \"%s\"\n" 312 "url = \"%s\"\n"
@@ -321,7 +329,8 @@ void save_Bookmarks(const iBookmarks *d, const char *dirPath) {
321 } 329 }
322 appendCStr_String(str, "\n"); 330 appendCStr_String(str, "\n");
323 writeData_File(f, cstr_String(str), size_String(str)); 331 writeData_File(f, cstr_String(str), size_String(str));
324 } 332 iEndCollect();
333 }
325 } 334 }
326 iRelease(f); 335 iRelease(f);
327 unlock_Mutex(d->mtx); 336 unlock_Mutex(d->mtx);
@@ -399,6 +408,16 @@ iBool updateBookmarkIcon_Bookmarks(iBookmarks *d, const iString *url, iChar icon
399 return changed; 408 return changed;
400} 409}
401 410
411void setRecentFolder_Bookmarks(iBookmarks *d, uint32_t folderId) {
412 iBookmark *bm = get_Bookmarks(d, folderId);
413 if (isFolder_Bookmark(bm)) {
414 d->recentFolderId = folderId;
415 }
416 else {
417 d->recentFolderId = 0;
418 }
419}
420
402iChar siteIcon_Bookmarks(const iBookmarks *d, const iString *url) { 421iChar siteIcon_Bookmarks(const iBookmarks *d, const iString *url) {
403 if (isEmpty_String(url)) { 422 if (isEmpty_String(url)) {
404 return 0; 423 return 0;
@@ -466,6 +485,10 @@ uint32_t findUrl_Bookmarks(const iBookmarks *d, const iString *url) {
466 return id_Bookmark(constFront_PtrArray(found)); 485 return id_Bookmark(constFront_PtrArray(found));
467} 486}
468 487
488uint32_t recentFolder_Bookmarks(const iBookmarks *d) {
489 return d->recentFolderId;
490}
491
469const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp, 492const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp,
470 iBookmarksFilterFunc filter, void *context) { 493 iBookmarksFilterFunc filter, void *context) {
471 lock_Mutex(d->mtx); 494 lock_Mutex(d->mtx);