summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c65
1 files changed, 65 insertions, 0 deletions
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);