From 4ab8242aa1801ddd0e720ddbea41aa43190bdc87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi
Date: Sat, 4 Nov 2023 17:25:48 +0200
Subject: [PATCH 1/1] Fixed issues with dropdown menus
When a popup menu gets detached into its own window, the command
triggered by a selected item was not being handled in the correct
root.
The identity setting commands in the bookmark dialog did not get
always updated correctly.
BubbleID #61
res/about/version.gmi | 4 ++++
src/ui/labelwidget.c | 4 ++--
src/ui/sidebarwidget.c | 4 ++--
src/ui/util.c | 32 ++++++++++++++++++++++++++++----
src/ui/util.h | 2 +-
src/ui/widget.c | 9 +++++++++
6 files changed, 46 insertions(+), 9 deletions(-)
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 @@
+## 1.17.3
+* Fixed issues with dropdown menus when the menu appears as a popup window.
+* Fixed clearing the pinned identity of a bookmark.
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);
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) {
return NULL;
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;
}
}
}
+}
void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *selectedCommand) {
if (!dropButton) {
return;
}
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. */
--
2.25.1
text/plain
This content has been proxied by September (ba2dc).