diff options
-rw-r--r-- | src/app.c | 25 | ||||
-rw-r--r-- | src/bookmarks.c | 7 | ||||
-rw-r--r-- | src/bookmarks.h | 2 |
3 files changed, 31 insertions, 3 deletions
@@ -912,11 +912,30 @@ iBool handleCommand_App(const char *cmd) { | |||
912 | setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gopher"), | 912 | setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gopher"), |
913 | schemeProxy_App(range_CStr("gopher"))); | 913 | schemeProxy_App(range_CStr("gopher"))); |
914 | setCommandHandler_Widget(dlg, handlePrefsCommands_); | 914 | setCommandHandler_Widget(dlg, handlePrefsCommands_); |
915 | postCommand_App("focus.set id:prefs.downloads"); | ||
916 | } | 915 | } |
917 | else if (equal_Command(cmd, "navigate.home")) { | 916 | else if (equal_Command(cmd, "navigate.home")) { |
918 | /* TODO: Look for bookmarks tagged homepage, or use the URL set in Preferences. */ | 917 | /* Look for bookmarks tagged "homepage". */ |
919 | postCommand_App("open url:about:lagrange"); | 918 | iRegExp *pattern = iClob(new_RegExp("\\bhomepage\\b", caseInsensitive_RegExpOption)); |
919 | const iPtrArray *homepages = | ||
920 | list_Bookmarks(d->bookmarks, NULL, filterTagsRegExp_Bookmarks, pattern); | ||
921 | if (isEmpty_PtrArray(homepages)) { | ||
922 | postCommand_App("open url:about:lagrange"); | ||
923 | } | ||
924 | else { | ||
925 | iStringSet *urls = iClob(new_StringSet()); | ||
926 | iConstForEach(PtrArray, i, homepages) { | ||
927 | const iBookmark *bm = i.ptr; | ||
928 | /* Try to switch to a different bookmark. */ | ||
929 | if (cmpStringCase_String(url_DocumentWidget(document_App()), &bm->url)) { | ||
930 | insert_StringSet(urls, &bm->url); | ||
931 | } | ||
932 | } | ||
933 | if (!isEmpty_StringSet(urls)) { | ||
934 | postCommandf_App( | ||
935 | "open url:%s", | ||
936 | cstr_String(constAt_StringSet(urls, iRandoms(0, size_StringSet(urls))))); | ||
937 | } | ||
938 | } | ||
920 | return iTrue; | 939 | return iTrue; |
921 | } | 940 | } |
922 | else if (equal_Command(cmd, "zoom.set")) { | 941 | else if (equal_Command(cmd, "zoom.set")) { |
diff --git a/src/bookmarks.c b/src/bookmarks.c index 8fe7d109..7e98fb27 100644 --- a/src/bookmarks.c +++ b/src/bookmarks.c | |||
@@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
26 | #include <the_Foundation/hash.h> | 26 | #include <the_Foundation/hash.h> |
27 | #include <the_Foundation/mutex.h> | 27 | #include <the_Foundation/mutex.h> |
28 | #include <the_Foundation/path.h> | 28 | #include <the_Foundation/path.h> |
29 | #include <the_Foundation/regexp.h> | ||
29 | 30 | ||
30 | void init_Bookmark(iBookmark *d) { | 31 | void init_Bookmark(iBookmark *d) { |
31 | init_String(&d->url); | 32 | init_String(&d->url); |
@@ -166,6 +167,12 @@ iBookmark *get_Bookmarks(iBookmarks *d, uint32_t id) { | |||
166 | return (iBookmark *) value_Hash(&d->bookmarks, id); | 167 | return (iBookmark *) value_Hash(&d->bookmarks, id); |
167 | } | 168 | } |
168 | 169 | ||
170 | iBool filterTagsRegExp_Bookmarks(void *regExp, const iBookmark *bm) { | ||
171 | iRegExpMatch m; | ||
172 | init_RegExpMatch(&m); | ||
173 | return matchString_RegExp(regExp, &bm->tags, &m); | ||
174 | } | ||
175 | |||
169 | const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp, | 176 | const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp, |
170 | iBookmarksFilterFunc filter, void *context) { | 177 | iBookmarksFilterFunc filter, void *context) { |
171 | lock_Mutex(d->mtx); | 178 | lock_Mutex(d->mtx); |
diff --git a/src/bookmarks.h b/src/bookmarks.h index aac83be1..4889e7b5 100644 --- a/src/bookmarks.h +++ b/src/bookmarks.h | |||
@@ -55,6 +55,8 @@ iBookmark *get_Bookmarks (iBookmarks *, uint32_t id); | |||
55 | typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *); | 55 | typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *); |
56 | typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **); | 56 | typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **); |
57 | 57 | ||
58 | iBool filterTagsRegExp_Bookmarks (void *regExp, const iBookmark *); | ||
59 | |||
58 | /** | 60 | /** |
59 | * Lists all or a subset of the bookmarks in a sorted array of Bookmark pointers. | 61 | * Lists all or a subset of the bookmarks in a sorted array of Bookmark pointers. |
60 | * | 62 | * |