summaryrefslogtreecommitdiff
path: root/src/ui
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/ui
parentf9346b83551f95f9e32f963c0574540f2805eb23 (diff)
Select folder when adding/editing bookmarks
Most recently used folder is persistently stored in bookmarks.ini. IssueID #358
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/sidebarwidget.c12
-rw-r--r--src/ui/util.c65
-rw-r--r--src/ui/util.h1
3 files changed, 77 insertions, 1 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 3abfd498..5d627dda 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -893,6 +893,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si
893 if (isEmpty_String(&item->url)) /* a folder */ { 893 if (isEmpty_String(&item->url)) /* a folder */ {
894 if (contains_IntSet(d->closedFolders, item->id)) { 894 if (contains_IntSet(d->closedFolders, item->id)) {
895 remove_IntSet(d->closedFolders, item->id); 895 remove_IntSet(d->closedFolders, item->id);
896 setRecentFolder_Bookmarks(bookmarks_App(), item->id);
896 } 897 }
897 else { 898 else {
898 insert_IntSet(d->closedFolders, item->id); 899 insert_IntSet(d->closedFolders, item->id);
@@ -990,6 +991,10 @@ void setWidth_SidebarWidget(iSidebarWidget *d, float widthAsGaps) {
990} 991}
991 992
992iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *cmd) { 993iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *cmd) {
994 if (equal_Command(cmd, "dlg.bookmark.setfolder")) {
995 setBookmarkEditorFolder_Widget(editor, arg_Command(cmd));
996 return iTrue;
997 }
993 if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) { 998 if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) {
994 iAssert(startsWith_String(id_Widget(editor), "bmed.")); 999 iAssert(startsWith_String(id_Widget(editor), "bmed."));
995 iSidebarWidget *d = findWidget_App(cstr_String(id_Widget(editor)) + 5); /* bmed.sidebar */ 1000 iSidebarWidget *d = findWidget_App(cstr_String(id_Widget(editor)) + 5); /* bmed.sidebar */
@@ -1020,7 +1025,11 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c
1020 isSelected_Widget(findChild_Widget(editor, "bmed.tag.remote"))); 1025 isSelected_Widget(findChild_Widget(editor, "bmed.tag.remote")));
1021 addOrRemoveTag_Bookmark(bm, linkSplit_BookmarkTag, 1026 addOrRemoveTag_Bookmark(bm, linkSplit_BookmarkTag,
1022 isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))); 1027 isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit")));
1023 } 1028 }
1029 const iBookmark *folder = userData_Object(findChild_Widget(editor, "bmed.folder"));
1030 if (!folder || !hasParent_Bookmark(folder, id_Bookmark(bm))) {
1031 bm->parentId = folder ? id_Bookmark(folder) : 0;
1032 }
1024 postCommand_App("bookmarks.changed"); 1033 postCommand_App("bookmarks.changed");
1025 } 1034 }
1026 setupSheetTransition_Mobile(editor, iFalse); 1035 setupSheetTransition_Mobile(editor, iFalse);
@@ -1327,6 +1336,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1327 setFlags_Widget(notNeeded[i], disabled_WidgetFlag, iTrue); 1336 setFlags_Widget(notNeeded[i], disabled_WidgetFlag, iTrue);
1328 } 1337 }
1329 } 1338 }
1339 setBookmarkEditorFolder_Widget(dlg, bm ? bm->parentId : 0);
1330 setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_); 1340 setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_);
1331 setFocus_Widget(findChild_Widget(dlg, "bmed.title")); 1341 setFocus_Widget(findChild_Widget(dlg, "bmed.title"));
1332 } 1342 }
diff --git a/src/ui/util.c b/src/ui/util.c
index 0a9dde0c..ba6a2538 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -2181,6 +2181,14 @@ size_t findWidestLabel_MenuItem(const iMenuItem *items, size_t num) {
2181 return widestPos; 2181 return widestPos;
2182} 2182}
2183 2183
2184const char *widestLabel_MenuItemArray(const iArray *items) {
2185 size_t index = findWidestLabel_MenuItem(constData_Array(items), size_Array(items));
2186 if (index == iInvalidPos) {
2187 return "";
2188 }
2189 return constValue_Array(items, index, iMenuItem).label;
2190}
2191
2184iChar removeIconPrefix_String(iString *d) { 2192iChar removeIconPrefix_String(iString *d) {
2185 if (isEmpty_String(d)) { 2193 if (isEmpty_String(d)) {
2186 return 0; 2194 return 0;
@@ -2772,6 +2780,35 @@ iWidget *makePreferences_Widget(void) {
2772 return dlg; 2780 return dlg;
2773} 2781}
2774 2782
2783static iBool isBookmarkFolder_(void *context, const iBookmark *bm) {
2784 iUnused(context);
2785 return isFolder_Bookmark(bm);
2786}
2787
2788static const iArray *makeBookmarkFolderItems_(void) {
2789 iArray *folders = new_Array(sizeof(iMenuItem));
2790 pushBack_Array(folders, &(iMenuItem){ "\u2014", 0, 0, "dlg.bookmark.setfolder arg:0" });
2791 iConstForEach(
2792 PtrArray,
2793 i,
2794 list_Bookmarks(bookmarks_App(), cmpTree_Bookmark, isBookmarkFolder_, NULL)) {
2795 const iBookmark *bm = i.ptr;
2796 iString *title = collect_String(copy_String(&bm->title));
2797 for (const iBookmark *j = bm; j && j->parentId; ) {
2798 j = get_Bookmarks(bookmarks_App(), j->parentId);
2799 prependCStr_String(title, " > ");
2800 prepend_String(title, &j->title);
2801 }
2802 pushBack_Array(
2803 folders,
2804 &(iMenuItem){ cstr_String(title),
2805 0,
2806 0,
2807 format_CStr("dlg.bookmark.setfolder arg:%u", id_Bookmark(bm)) });
2808 }
2809 return collect_Array(folders);
2810}
2811
2775iWidget *makeBookmarkEditor_Widget(void) { 2812iWidget *makeBookmarkEditor_Widget(void) {
2776 const iMenuItem actions[] = { 2813 const iMenuItem actions[] = {
2777 { "${cancel}" }, 2814 { "${cancel}" },
@@ -2808,6 +2845,19 @@ iWidget *makeBookmarkEditor_Widget(void) {
2808 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.title}", "bmed.title", iClob(inputs[0] = new_InputWidget(0))); 2845 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.title}", "bmed.title", iClob(inputs[0] = new_InputWidget(0)));
2809 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.url}", "bmed.url", iClob(inputs[1] = new_InputWidget(0))); 2846 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.url}", "bmed.url", iClob(inputs[1] = new_InputWidget(0)));
2810 setUrlContent_InputWidget(inputs[1], iTrue); 2847 setUrlContent_InputWidget(inputs[1], iTrue);
2848 /* Folder to add to. */ {
2849 addChild_Widget(headings, iClob(makeHeading_Widget("${dlg.bookmark.folder}")));
2850 const iArray *folderItems = makeBookmarkFolderItems_();
2851 iLabelWidget *folderButton;
2852 setId_Widget(addChildFlags_Widget(values,
2853 iClob(folderButton = makeMenuButton_LabelWidget(
2854 widestLabel_MenuItemArray(folderItems),
2855 constData_Array(folderItems),
2856 size_Array(folderItems))), alignLeft_WidgetFlag),
2857 "bmed.folder");
2858 updateDropdownSelection_LabelWidget(
2859 folderButton, format_CStr(" arg:%u", recentFolder_Bookmarks(bookmarks_App())));
2860 }
2811 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.tags}", "bmed.tags", iClob(inputs[2] = new_InputWidget(0))); 2861 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.tags}", "bmed.tags", iClob(inputs[2] = new_InputWidget(0)));
2812 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.icon}", "bmed.icon", iClob(inputs[3] = new_InputWidget(1))); 2862 addDialogInputWithHeading_(headings, values, "${dlg.bookmark.icon}", "bmed.icon", iClob(inputs[3] = new_InputWidget(1)));
2813 /* Buttons for special tags. */ 2863 /* Buttons for special tags. */
@@ -2830,12 +2880,23 @@ iWidget *makeBookmarkEditor_Widget(void) {
2830 return dlg; 2880 return dlg;
2831} 2881}
2832 2882
2883void setBookmarkEditorFolder_Widget(iWidget *editor, uint32_t folderId) {
2884 iLabelWidget *button = findChild_Widget(editor, "bmed.folder");
2885 updateDropdownSelection_LabelWidget(button, format_CStr(" arg:%u", folderId));
2886 setUserData_Object(button, get_Bookmarks(bookmarks_App(), folderId));
2887}
2888
2833static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, const char *cmd) { 2889static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, const char *cmd) {
2890 if (equal_Command(cmd, "dlg.bookmark.setfolder")) {
2891 setBookmarkEditorFolder_Widget(editor, arg_Command(cmd));
2892 return iTrue;
2893 }
2834 if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) { 2894 if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) {
2835 if (equal_Command(cmd, "bmed.accept")) { 2895 if (equal_Command(cmd, "bmed.accept")) {
2836 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title")); 2896 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title"));
2837 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url")); 2897 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url"));
2838 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags")); 2898 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags"));
2899 const iBookmark *folder = userData_Object(findChild_Widget(editor, "bmed.folder"));
2839 const iString *icon = collect_String(trimmed_String(text_InputWidget(findChild_Widget(editor, "bmed.icon")))); 2900 const iString *icon = collect_String(trimmed_String(text_InputWidget(findChild_Widget(editor, "bmed.icon"))));
2840 const uint32_t id = add_Bookmarks(bookmarks_App(), url, title, tags, first_String(icon)); 2901 const uint32_t id = add_Bookmarks(bookmarks_App(), url, title, tags, first_String(icon));
2841 iBookmark * bm = get_Bookmarks(bookmarks_App(), id); 2902 iBookmark * bm = get_Bookmarks(bookmarks_App(), id);
@@ -2851,6 +2912,10 @@ static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, cons
2851 if (isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))) { 2912 if (isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))) {
2852 addTag_Bookmark(bm, linkSplit_BookmarkTag); 2913 addTag_Bookmark(bm, linkSplit_BookmarkTag);
2853 } 2914 }
2915 bm->parentId = folder ? id_Bookmark(folder) : 0;
2916 if (bm->parentId) {
2917 setRecentFolder_Bookmarks(bookmarks_App(), bm->parentId);
2918 }
2854 postCommandf_App("bookmarks.changed added:%zu", id); 2919 postCommandf_App("bookmarks.changed added:%zu", id);
2855 } 2920 }
2856 setupSheetTransition_Mobile(editor, iFalse); 2921 setupSheetTransition_Mobile(editor, iFalse);
diff --git a/src/ui/util.h b/src/ui/util.h
index 52b3a692..81fb1cbd 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -311,6 +311,7 @@ iWidget * makePreferences_Widget (void);
311void updatePreferencesLayout_Widget (iWidget *prefs); 311void updatePreferencesLayout_Widget (iWidget *prefs);
312 312
313iWidget * makeBookmarkEditor_Widget (void); 313iWidget * makeBookmarkEditor_Widget (void);
314void setBookmarkEditorFolder_Widget(iWidget *editor, uint32_t folderId);
314iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon); 315iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon);
315iWidget * makeIdentityCreation_Widget (void); 316iWidget * makeIdentityCreation_Widget (void);
316iWidget * makeFeedSettings_Widget (uint32_t bookmarkId); 317iWidget * makeFeedSettings_Widget (uint32_t bookmarkId);