Skip to content

Commit

Permalink
Editing bookmark icons
Browse files Browse the repository at this point in the history
IssueID #140
  • Loading branch information
skyjake committed Feb 23, 2021
1 parent 492d80a commit f79e673
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions res/about/version.gmi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## 1.2
* Help is opened on first run instead of the "About Lagrange" page to make it easier to discover important Gemini links like the FAQ.
* Added editable bookmark icons: use your favorite Unicode character as the symbol to represent a bookmarked site in Lagrange.
* Added search engine support: non-URL text entered in the navbar is passed onto the configured search query URL (Preferences > Network).
* Short pages are centered vertically on actual page content excluding the top banner.
* Added user preference for aligning all pages to the top of the window.
Expand Down
25 changes: 25 additions & 0 deletions src/bookmarks.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,31 @@ iBool updateBookmarkIcon_Bookmarks(iBookmarks *d, const iString *url, iChar icon
return changed;
}

iChar siteIcon_Bookmarks(const iBookmarks *d, iRangecc hostName) {
iChar icon = 0;
const size_t hostSize = size_Range(&hostName);
size_t matchingSize = iInvalidSize; /* we'll pick the shortest matching */
lock_Mutex(d->mtx);
iConstForEach(Hash, i, &d->bookmarks) {
const iBookmark *bm = (const iBookmark *) i.value;
iUrl parts;
init_Url(&parts, &bm->url);
if (!hasTag_Bookmark(bm, "usericon")) { /* TODO: Inefficient! RegExp rebuilt every time. */
continue;
}
if (size_Range(&hostName) == size_Range(&parts.host) &&
iCmpStrNCase(hostName.start, parts.host.start, hostSize) == 0) {
const size_t n = size_String(&bm->url);
if (n < matchingSize && bm->icon) {
matchingSize = n;
icon = bm->icon;
}
}
}
unlock_Mutex(d->mtx);
return icon;
}

iBookmark *get_Bookmarks(iBookmarks *d, uint32_t id) {
return (iBookmark *) value_Hash(&d->bookmarks, id);
}
Expand Down
1 change: 1 addition & 0 deletions src/bookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ iBookmark * get_Bookmarks (iBookmarks *, uint32_t id);
void fetchRemote_Bookmarks (iBookmarks *);
void requestFinished_Bookmarks (iBookmarks *, iGmRequest *req);
iBool updateBookmarkIcon_Bookmarks(iBookmarks *, const iString *url, iChar icon);
iChar siteIcon_Bookmarks (const iBookmarks *, iRangecc hostName);

void save_Bookmarks (const iBookmarks *, const char *dirPath);
uint32_t findUrl_Bookmarks (const iBookmarks *, const iString *url); /* O(n) */
Expand Down
5 changes: 5 additions & 0 deletions src/gmdocument.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include "ui/metrics.h"
#include "ui/window.h"
#include "visited.h"
#include "bookmarks.h"
#include "app.h"

#include <the_Foundation/ptrarray.h>
Expand Down Expand Up @@ -1091,6 +1092,10 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) {
if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) {
d->siteIcon = 0x264a; /* gemini symbol */
}
const iChar userIcon = siteIcon_Bookmarks(bookmarks_App(), urlHost_String(&d->url));
if (userIcon) {
d->siteIcon = userIcon;
}
}
#if 0
for (int i = tmFirst_ColorId; i < max_ColorId; ++i) {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/documentwidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,10 @@ static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) {
const iChar siteIcon = siteIcon_GmDocument(d->doc);
if (siteIcon) {
if (!isEmpty_String(text)) {
prependCStr_String(text, " ");
prependCStr_String(text, " " restore_ColorEscape);
}
prependChar_String(text, siteIcon);
prependCStr_String(text, escape_Color(uiIcon_ColorId));
}
const int width = advanceRange_Text(default_FontId, range_String(text)).x;
if (width <= avail ||
Expand Down
10 changes: 9 additions & 1 deletion src/ui/inputwidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,13 @@ static void insertChar_InputWidget_(iInputWidget *d, iChar chr) {
resize_Array(&d->text, d->cursor + 1);
}
set_Array(&d->text, d->cursor++, &chr);
if (d->maxLen && d->cursor == d->maxLen) {
if (d->maxLen > 1 && d->cursor == d->maxLen) {
iWidget *nextFocus = findFocusable_Widget(w, forward_WidgetFocusDir);
setFocus_Widget(nextFocus == w ? NULL : nextFocus);
}
else if (d->maxLen == 1) {
d->cursor = 0;
}
}
showCursor_InputWidget_(d);
refresh_Widget(as_Widget(d));
Expand Down Expand Up @@ -675,6 +678,11 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
remove_Array(&d->text, --d->cursor);
contentsWereChanged_InputWidget_(d);
}
else if (d->cursor == 0 && d->maxLen == 1) {
pushUndo_InputWidget_(d);
clear_Array(&d->text);
contentsWereChanged_InputWidget_(d);
}
showCursor_InputWidget_(d);
refresh_Widget(w);
return iTrue;
Expand Down
6 changes: 4 additions & 2 deletions src/ui/sidebarwidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,10 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c
removeTag_Bookmark(bm, "usericon");
bm->icon = 0;
}
else if (!hasTag_Bookmark(bm, "usericon")) {
addTag_Bookmark(bm, "usericon");
else {
if (!hasTag_Bookmark(bm, "usericon")) {
addTag_Bookmark(bm, "usericon");
}
bm->icon = first_String(icon);
}
postCommand_App("bookmarks.changed");
Expand Down

0 comments on commit f79e673

Please sign in to comment.