Lagrange [work/v1.17]

Fixed issues with dropdown menus

=> 4ab8242aa1801ddd0e720ddbea41aa43190bdc87

diff --git a/res/about/version.gmi b/res/about/version.gmi
index b7d3104e..e6c94c94 100644
--- a/res/about/version.gmi
+++ b/res/about/version.gmi
@@ -6,6 +6,10 @@
 ```
 # Release notes
 
+## 1.17.3
+* Fixed issues with dropdown menus when the menu appears as a popup window.
+* Fixed clearing the pinned identity of a bookmark.
+
 ## 1.17.2
 * Tabs opened in background are immediately added to the URL history.
 * Mouse wheel direction switches back to vertical when a wide block has been scrolled all the way.
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index 261c6798..00237f6f 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -101,7 +101,7 @@ static iBool checkModifiers_(int have, int req) {
 
 static void trigger_LabelWidget_(const iLabelWidget *d) {
     const iWidget *w = constAs_Widget(d);
-    postCommand_Widget(&d->widget, "%s", cstr_String(&d->command));
+    postCommand_Widget(w, "%s", cstr_String(&d->command));
     if (flags_Widget(w) & radio_WidgetFlag) {
         iForEach(ObjectList, i, children_Widget(w->parent)) {
             setFlags_Widget(i.object, selected_WidgetFlag, d == i.object);
@@ -109,7 +109,7 @@ static void trigger_LabelWidget_(const iLabelWidget *d) {
     }
     /* Triggering a menu item will always close all popup menus. */
     if (d->flags.menuCanceling) {
-        postCommand_Widget(&d->widget, "menu.cancel");
+        postCommand_Root(NULL, "menu.cancel");
     }
 }
 
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 2cb9c6c6..31ddb78c 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -1202,7 +1202,7 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c
         if (bm) {
             set_String(&bm->identity, string_Command(cmd, "fp"));
             updateDropdownSelection_LabelWidget(findChild_Widget(editor, "bmed.setident"),
-                                                cstr_String(&bm->identity));
+                                                format_CStr(" fp:%s", cstr_String(&bm->identity)));
         }
         return iTrue;
     }
@@ -1740,7 +1740,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
                     setToggle_Widget(remoteSourceTag, bm->flags & remoteSource_BookmarkFlag);
                     setToggle_Widget(linkSplitTag, bm->flags & linkSplit_BookmarkFlag);
                     updateDropdownSelection_LabelWidget(findChild_Widget(dlg, "bmed.setident"),
-                                                        format_CStr("bmed.setident fp:%s",
+                                                        format_CStr(" fp:%s",
                                                                     cstr_String(&bm->identity)));
                 }
                 setBookmarkEditorParentFolder_Widget(dlg, bm ? bm->parentId : 0);
diff --git a/src/ui/util.c b/src/ui/util.c
index 29ef6093..b4b1c009 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1190,7 +1190,7 @@ void setNativeMenuItems_Widget(iWidget *menu, const iMenuItem *items, size_t n)
 #endif
 }
 
-iWidget *parentMenu_Widget(iWidget *menuItem) {
+iWidget *parentMenu_Widget(const iWidget *menuItem) {
     if (parent_Widget(menuItem)) {
         if (!cmp_String(id_Widget(parent_Widget(menuItem)), "menu")) {
             return parent_Widget(menuItem);
@@ -1829,11 +1829,34 @@ static const iString *replaceNewlinesWithDash_(const iString *str) {
     return collect_String(mod);
 }
 
+iWidget *dropdownMenu_Widget(iWidget *dropButton) {
+    if (!dropButton) {
+        return NULL;
+    }
+    iWidget *menu = findChild_Widget(dropButton, "menu");
+    if (!menu) {
+        if (dropButton->flags2 & childMenuOpenedAsPopup_WidgetFlag2) {
+            /* The menu has been migrated temporarily into a popup window. We need to locate
+               the right popup. */
+            iConstForEach(PtrArray, p, popupWindows_App()) {
+                const iWindow *win = p.ptr;
+                iWidget *winRoot = win->roots[0]->widget;
+                if (userData_Object(winRoot) == dropButton) {
+                    iAssert(!cmp_String(id_Widget(winRoot), "menu"));
+                    return winRoot;
+                }
+            }
+        }
+    }
+    iAssert(menu);
+    return menu;
+}
+
 void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *selectedCommand) {
     if (!dropButton) {
         return;
     }
-    iWidget *menu = findChild_Widget(as_Widget(dropButton), "menu");
+    iWidget *menu = dropdownMenu_Widget(as_Widget(dropButton));
     if (flags_Widget(menu) & nativeMenu_WidgetFlag) {
         unselectAllNativeMenuItems_Widget(menu);
         iMenuItem *item = findNativeMenuItem_Widget(menu, selectedCommand);
@@ -1850,6 +1873,7 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s
     iForEach(ObjectList, i, children_Widget(menu)) {
         if (isInstance_Object(i.object, &Class_LabelWidget)) {
             iLabelWidget *item = i.object;
+            printf("update: [%s] sel=%s?\n", cstr_String(command_LabelWidget(item)), selectedCommand); fflush(stdout);
             const iBool isSelected = endsWith_String(command_LabelWidget(item), selectedCommand);
             setFlags_Widget(as_Widget(item), selected_WidgetFlag, isSelected);
             if (isSelected) {
@@ -4056,7 +4080,7 @@ iWidget *makeBookmarkEditor_Widget(uint32_t folderId, iBool withDup) {
                             iClob(makeHeading_Widget(isFolder ? "${dlg.bookmark.parentfolder}"
                                                               : "${dlg.bookmark.folder}")));
             const iArray *folderItems =
-                makeBookmarkFolderActions_MenuItem("dlg.bookmark.setfolder", iFalse, folderId);
+                makeBookmarkFolderActions_MenuItem("!dlg.bookmark.setfolder", iFalse, folderId);
             iLabelWidget *folderButton;
             setId_Widget(addChildFlags_Widget(values,
                                          iClob(folderButton = makeMenuButton_LabelWidget(
@@ -4138,7 +4162,7 @@ static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, cons
         const iString *fp = string_Command(cmd, "fp");
         iLabelWidget *setident = findChild_Widget(editor, "bmed.setident");
         set_String(&as_Widget(setident)->data, fp);
-        updateDropdownSelection_LabelWidget(setident, cstr_String(fp));
+        updateDropdownSelection_LabelWidget(setident, format_CStr(" fp:%s", cstr_String(fp)));
         return iTrue;
     }
     if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "bmed.cancel")) {
diff --git a/src/ui/util.h b/src/ui/util.h
index c81e6a46..5ddc6dbb 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -322,7 +322,7 @@ void            setMenuItemLabel_Widget         (iWidget *menu, const char *comm
 void            setMenuItemLabelByIndex_Widget  (iWidget *menu, size_t index, const char *newLabel);
 void            setNativeMenuItems_Widget       (iWidget *menu, const iMenuItem *items, size_t n);
 iWidget *       findUserData_Widget             (iWidget *, void *userData);
-iWidget *       parentMenu_Widget               (iWidget *menuItem);
+iWidget *       parentMenu_Widget               (const iWidget *menuItem);
 
 int             checkContextMenu_Widget         (iWidget *, const SDL_Event *ev); /* see macro below */
 void            animateToRootVisibleTop_Widget  (iWidget *, uint32_t span);
diff --git a/src/ui/widget.c b/src/ui/widget.c
index 2b40a4d5..695878ca 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -2585,6 +2585,15 @@ void postCommand_Widget(const iAnyObject *d, const char *cmd, ...) {
     }
     if (!isGlobal) {
         iAssert(isInstance_Object(d, &Class_Widget));
+        if (type_Window(window_Widget(d)) == popup_WindowType) {
+            /* Use the original parent root for the command, so it will be handled by
+               whoever owns the popup menu. */
+            const iWidget *originalParent =
+                constAs_Widget(userData_Object(parentMenu_Widget(constAs_Widget(d))));
+            if (originalParent) {
+                d = originalParent;
+            }
+        }
         iString ptrStr;
         init_String(&ptrStr);
         /* Insert the widget pointer as the first argument so possible suffixes are unaffected. */
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.17/cdiff/4ab8242aa1801ddd0e720ddbea41aa43190bdc87
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
81.220776 milliseconds
Gemini-to-HTML Time
0.397601 milliseconds

This content has been proxied by September (ba2dc).