summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-02-22 22:03:03 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-02-22 22:03:03 +0200
commit7f7011c021bdeed29963942e3a5dc8f3361f39c4 (patch)
tree9d9f50a5ef71ccf2ce6a14fe1f755126825be46c
parent90443011c98a6dc8340d2c84f1e538c7a98327f2 (diff)
Allow user to set any character as bookmark icon
The custom icons only appear in bookmark and feed lists, though.
-rw-r--r--res/about/help.gmi1
-rw-r--r--src/bookmarks.c2
-rw-r--r--src/ui/sidebarwidget.c14
-rw-r--r--src/ui/util.c82
4 files changed, 27 insertions, 72 deletions
diff --git a/res/about/help.gmi b/res/about/help.gmi
index 05168ecf..b845c6fb 100644
--- a/res/about/help.gmi
+++ b/res/about/help.gmi
@@ -179,6 +179,7 @@ Note that remote bookmarks are read-only: they cannot be edited or tagged. This
179* "headings" can be used together with "subscribed" to subscribe to new headings instead of Gemini feed links. 179* "headings" can be used together with "subscribed" to subscribe to new headings instead of Gemini feed links.
180* The "remotesource" tag marks the bookmark as a source of remote bookmarks. All links on the source pages are shown as remote bookmarks in the Bookmarks list. 180* The "remotesource" tag marks the bookmark as a source of remote bookmarks. All links on the source pages are shown as remote bookmarks in the Bookmarks list.
181* The "remote" tag is used for remote bookmarks. These bookmarks cannot be edited or tagged, but you can make a local duplicate to turn it into a regular bookmark. 181* The "remote" tag is used for remote bookmarks. These bookmarks cannot be edited or tagged, but you can make a local duplicate to turn it into a regular bookmark.
182* The "usericon" tag prevents a random icon to be selected for the bookmark. This tag is automatically applied when an icon character is entered in the bookmark editor.
182 183
183## 1.5 Subscribing to feeds 184## 1.5 Subscribing to feeds
184 185
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 1fc24a67..da53b645 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -237,7 +237,7 @@ iBool updateBookmarkIcon_Bookmarks(iBookmarks *d, const iString *url, iChar icon
237 const uint32_t id = findUrl_Bookmarks(d, url); 237 const uint32_t id = findUrl_Bookmarks(d, url);
238 if (id) { 238 if (id) {
239 iBookmark *bm = get_Bookmarks(d, id); 239 iBookmark *bm = get_Bookmarks(d, id);
240 if (!hasTag_Bookmark(bm, "remote")) { 240 if (!hasTag_Bookmark(bm, "remote") && !hasTag_Bookmark(bm, "usericon")) {
241 if (icon != bm->icon) { 241 if (icon != bm->icon) {
242 bm->icon = icon; 242 bm->icon = icon;
243 changed = iTrue; 243 changed = iTrue;
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 24ace92a..36aa1235 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -677,12 +677,22 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c
677 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title")); 677 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title"));
678 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url")); 678 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url"));
679 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags")); 679 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags"));
680 const iString *icon = collect_String(trimmed_String(
681 text_InputWidget(findChild_Widget(editor, "bmed.icon"))));
680 const iSidebarItem *item = hoverItem_ListWidget(d->list); 682 const iSidebarItem *item = hoverItem_ListWidget(d->list);
681 iAssert(item); /* hover item cannot have been changed */ 683 iAssert(item); /* hover item cannot have been changed */
682 iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id); 684 iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id);
683 set_String(&bm->title, title); 685 set_String(&bm->title, title);
684 set_String(&bm->url, url); 686 set_String(&bm->url, url);
685 set_String(&bm->tags, tags); 687 set_String(&bm->tags, tags);
688 if (isEmpty_String(icon)) {
689 removeTag_Bookmark(bm, "usericon");
690 bm->icon = 0;
691 }
692 else if (!hasTag_Bookmark(bm, "usericon")) {
693 addTag_Bookmark(bm, "usericon");
694 bm->icon = first_String(icon);
695 }
686 postCommand_App("bookmarks.changed"); 696 postCommand_App("bookmarks.changed");
687 } 697 }
688 setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse); 698 setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse);
@@ -830,6 +840,10 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
830 setText_InputWidget(findChild_Widget(dlg, "bmed.title"), &bm->title); 840 setText_InputWidget(findChild_Widget(dlg, "bmed.title"), &bm->title);
831 setText_InputWidget(findChild_Widget(dlg, "bmed.url"), &bm->url); 841 setText_InputWidget(findChild_Widget(dlg, "bmed.url"), &bm->url);
832 setText_InputWidget(findChild_Widget(dlg, "bmed.tags"), &bm->tags); 842 setText_InputWidget(findChild_Widget(dlg, "bmed.tags"), &bm->tags);
843 if (hasTag_Bookmark(bm, "usericon")) {
844 setText_InputWidget(findChild_Widget(dlg, "bmed.icon"),
845 collect_String(newUnicodeN_String(&bm->icon, 1)));
846 }
833 setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_); 847 setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_);
834 setFocus_Widget(findChild_Widget(dlg, "bmed.title")); 848 setFocus_Widget(findChild_Widget(dlg, "bmed.title"));
835 } 849 }
diff --git a/src/ui/util.c b/src/ui/util.c
index c2ac41fa..f8151807 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1053,21 +1053,6 @@ iWidget *makeQuestion_Widget(const char *title, const char *msg,
1053 addChildFlags_Widget(dlg, iClob(new_LabelWidget(title, NULL)), frameless_WidgetFlag); 1053 addChildFlags_Widget(dlg, iClob(new_LabelWidget(title, NULL)), frameless_WidgetFlag);
1054 addChildFlags_Widget(dlg, iClob(new_LabelWidget(msg, NULL)), frameless_WidgetFlag); 1054 addChildFlags_Widget(dlg, iClob(new_LabelWidget(msg, NULL)), frameless_WidgetFlag);
1055 addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); 1055 addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI)));
1056#if 0
1057 iWidget *div = new_Widget(); {
1058 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeHeight_WidgetFlag, iTrue);
1059 for (size_t i = 0; i < numItems; ++i) {
1060 /* The last one is the default option. */
1061 const int key = (i == count - 1 ? SDLK_RETURN : 0);
1062 iLabelWidget *btn =
1063 addChild_Widget(div, iClob(newKeyMods_LabelWidget(labels[i], key, 0, commands[i])));
1064 if (key) {
1065 setFont_LabelWidget(btn, uiLabelBold_FontId);
1066 }
1067 }
1068 }
1069 addChild_Widget(dlg, iClob(div));
1070#endif
1071 iWidget *buttons = addChild_Widget(dlg, iClob(makeDialogButtons_(items, numItems))); 1056 iWidget *buttons = addChild_Widget(dlg, iClob(makeDialogButtons_(items, numItems)));
1072 addChild_Widget(get_Window()->root, iClob(dlg)); 1057 addChild_Widget(get_Window()->root, iClob(dlg));
1073 arrange_Widget(dlg); /* BUG: This extra arrange shouldn't be needed but the dialog won't 1058 arrange_Widget(dlg); /* BUG: This extra arrange shouldn't be needed but the dialog won't
@@ -1331,16 +1316,6 @@ iWidget *makePreferences_Widget(void) {
1331 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gopher")); 1316 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.gopher"));
1332 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.http")); 1317 expandInputFieldWidth_(findChild_Widget(tabs, "prefs.proxy.http"));
1333 } 1318 }
1334#if 0
1335 iWidget *div = new_Widget(); {
1336 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1337 setFont_LabelWidget(
1338 addChild_Widget(
1339 div, iClob(newKeyMods_LabelWidget("Dismiss", SDLK_ESCAPE, 0, "prefs.dismiss"))),
1340 uiLabelBold_FontId);
1341 }
1342 addChild_Widget(dlg, iClob(div));
1343#endif
1344 addChild_Widget(dlg, 1319 addChild_Widget(dlg,
1345 iClob(makeDialogButtons_( 1320 iClob(makeDialogButtons_(
1346 (iMenuItem[]){ { "Dismiss", SDLK_ESCAPE, 0, "prefs.dismiss" } }, 1))); 1321 (iMenuItem[]){ { "Dismiss", SDLK_ESCAPE, 0, "prefs.dismiss" } }, 1)));
@@ -1363,7 +1338,7 @@ iWidget *makeBookmarkEditor_Widget(void) {
1363 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 1338 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
1364 iWidget *values = addChildFlags_Widget( 1339 iWidget *values = addChildFlags_Widget(
1365 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 1340 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
1366 iInputWidget *inputs[3]; 1341 iInputWidget *inputs[4];
1367 addChild_Widget(headings, iClob(makeHeading_Widget("Title:"))); 1342 addChild_Widget(headings, iClob(makeHeading_Widget("Title:")));
1368 setId_Widget(addChild_Widget(values, iClob(inputs[0] = new_InputWidget(0))), "bmed.title"); 1343 setId_Widget(addChild_Widget(values, iClob(inputs[0] = new_InputWidget(0))), "bmed.title");
1369 addChild_Widget(headings, iClob(makeHeading_Widget("URL:"))); 1344 addChild_Widget(headings, iClob(makeHeading_Widget("URL:")));
@@ -1371,22 +1346,12 @@ iWidget *makeBookmarkEditor_Widget(void) {
1371 setUrlContent_InputWidget(inputs[1], iTrue); 1346 setUrlContent_InputWidget(inputs[1], iTrue);
1372 addChild_Widget(headings, iClob(makeHeading_Widget("Tags:"))); 1347 addChild_Widget(headings, iClob(makeHeading_Widget("Tags:")));
1373 setId_Widget(addChild_Widget(values, iClob(inputs[2] = new_InputWidget(0))), "bmed.tags"); 1348 setId_Widget(addChild_Widget(values, iClob(inputs[2] = new_InputWidget(0))), "bmed.tags");
1349 addChild_Widget(headings, iClob(makeHeading_Widget("Icon:")));
1350 setId_Widget(addChild_Widget(values, iClob(inputs[3] = new_InputWidget(1))), "bmed.icon");
1374 arrange_Widget(dlg); 1351 arrange_Widget(dlg);
1375 for (int i = 0; i < 3; ++i) { 1352 for (int i = 0; i < 3; ++i) {
1376 as_Widget(inputs[i])->rect.size.x = 100 * gap_UI - headings->rect.size.x; 1353 as_Widget(inputs[i])->rect.size.x = 100 * gap_UI - headings->rect.size.x;
1377 } 1354 }
1378#if 0
1379 iWidget *div = new_Widget(); {
1380 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1381 addChild_Widget(div, iClob(newKeyMods_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel")));
1382 iLabelWidget *accept = addChild_Widget(
1383 div,
1384 iClob(newKeyMods_LabelWidget(
1385 uiTextCaution_ColorEscape "Save Bookmark", SDLK_RETURN, KMOD_PRIMARY, "bmed.accept")));
1386 setFont_LabelWidget(accept, uiLabelBold_FontId);
1387 }
1388 addChild_Widget(dlg, iClob(div));
1389#endif
1390 addChild_Widget( 1355 addChild_Widget(
1391 dlg, 1356 dlg,
1392 iClob(makeDialogButtons_((iMenuItem[]){ { "Cancel", 0, 0, NULL }, 1357 iClob(makeDialogButtons_((iMenuItem[]){ { "Cancel", 0, 0, NULL },
@@ -1411,11 +1376,14 @@ static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, cons
1411 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title")); 1376 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title"));
1412 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url")); 1377 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url"));
1413 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags")); 1378 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags"));
1414 add_Bookmarks(bookmarks_App(), 1379 const iString *icon = collect_String(trimmed_String(text_LabelWidget(findChild_Widget(editor, "bmed.icon"))));
1415 url, 1380 const uint32_t id = add_Bookmarks(bookmarks_App(), url, title, tags, first_String(icon));
1416 title, 1381 if (!isEmpty_String(icon)) {
1417 tags, 1382 iBookmark *bm = get_Bookmarks(bookmarks_App(), id);
1418 first_String(text_LabelWidget(findChild_Widget(editor, "bmed.icon")))); 1383 if (!hasTag_Bookmark(bm, "usericon")) {
1384 addTag_Bookmark(bm, "usericon");
1385 }
1386 }
1419 postCommand_App("bookmarks.changed"); 1387 postCommand_App("bookmarks.changed");
1420 } 1388 }
1421 destroy_Widget(editor); 1389 destroy_Widget(editor);
@@ -1518,22 +1486,6 @@ iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) {
1518 addRadioButton_(types, "feedcfg.type.headings", "New Headings", "feedcfg.type arg:1"); 1486 addRadioButton_(types, "feedcfg.type.headings", "New Headings", "feedcfg.type arg:1");
1519 } 1487 }
1520 addChildFlags_Widget(values, iClob(types), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); 1488 addChildFlags_Widget(values, iClob(types), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
1521#if 0
1522 iWidget *div = new_Widget(); {
1523 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1524 addChild_Widget(div, iClob(newKeyMods_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel")));
1525 setId_Widget(addChild_Widget(div,
1526 iClob(newKeyMods_LabelWidget(
1527 bookmarkId ? uiTextCaution_ColorEscape "Save Settings"
1528 : uiTextCaution_ColorEscape "Subscribe",
1529 SDLK_RETURN,
1530 KMOD_PRIMARY,
1531 format_CStr("feedcfg.accept bmid:%d", bookmarkId)))),
1532 "feedcfg.save");
1533 setFont_LabelWidget(findChild_Widget(div, "feedcfg.save"), uiLabelBold_FontId);
1534 }
1535 addChild_Widget(dlg, iClob(div));
1536#endif
1537 iWidget *buttons = 1489 iWidget *buttons =
1538 addChild_Widget(dlg, 1490 addChild_Widget(dlg,
1539 iClob(makeDialogButtons_( 1491 iClob(makeDialogButtons_(
@@ -1616,18 +1568,6 @@ iWidget *makeIdentityCreation_Widget(void) {
1616 for (size_t i = 0; i < iElemCount(inputs); ++i) { 1568 for (size_t i = 0; i < iElemCount(inputs); ++i) {
1617 as_Widget(inputs[i])->rect.size.x = 100 * gap_UI - headings->rect.size.x; 1569 as_Widget(inputs[i])->rect.size.x = 100 * gap_UI - headings->rect.size.x;
1618 } 1570 }
1619#if 0
1620 iWidget *div = new_Widget(); {
1621 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1622 addChild_Widget(div, iClob(newKeyMods_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel")));
1623 iLabelWidget *accept = addChild_Widget(
1624 div,
1625 iClob(newKeyMods_LabelWidget(
1626 uiTextAction_ColorEscape "Create Identity", SDLK_RETURN, KMOD_PRIMARY, "ident.accept")));
1627 setFont_LabelWidget(accept, uiLabelBold_FontId);
1628 }
1629 addChild_Widget(dlg, iClob(div));
1630#endif
1631 addChild_Widget( 1571 addChild_Widget(
1632 dlg, 1572 dlg,
1633 iClob(makeDialogButtons_((iMenuItem[]){ { "Cancel", 0, 0, NULL }, 1573 iClob(makeDialogButtons_((iMenuItem[]){ { "Cancel", 0, 0, NULL },