From ce8f6a67cb6c6fd7491d9f5ace7e9eda39a9f90c Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 24 Dec 2021 09:27:35 +0200 Subject: macOS: Fixed selecting scope for new identity The selected item was not found from a native popup menu. --- src/app.c | 23 +++++++---------------- src/ui/util.c | 26 ++++++++++++++++++++++++++ src/ui/util.h | 1 + 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/app.c b/src/app.c index bfac84d9..2135ec7c 100644 --- a/src/app.c +++ b/src/app.c @@ -2035,9 +2035,8 @@ static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { } if (equal_Command(cmd, "ident.scope")) { iLabelWidget *scope = findChild_Widget(dlg, "ident.scope"); - setText_LabelWidget(scope, - text_LabelWidget(child_Widget( - findChild_Widget(as_Widget(scope), "menu"), arg_Command(cmd)))); + updateDropdownSelection_LabelWidget(scope, format_CStr(" arg:%d", arg_Command(cmd))); + updateSize_LabelWidget(scope); arrange_Widget(findWidget_App("ident")); return iTrue; } @@ -2104,19 +2103,11 @@ static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { organization, country); /* Use in the chosen scope. */ { - const iLabelWidget *scope = findChild_Widget(dlg, "ident.scope"); - const iString * selLabel = text_LabelWidget(scope); - int selScope = 0; - iConstForEach(ObjectList, - i, - children_Widget(findChild_Widget(constAs_Widget(scope), "menu"))) { - if (isInstance_Object(i.object, &Class_LabelWidget)) { - const iLabelWidget *item = i.object; - if (equal_String(text_LabelWidget(item), selLabel)) { - break; - } - selScope++; - } + int selScope = 2; + const char *scopeCmd = + selectedDropdownCommand_LabelWidget(findChild_Widget(dlg, "ident.scope")); + if (startsWith_CStr(scopeCmd, "ident.scope arg:")) { + selScope = arg_Command(scopeCmd); } const iString *docUrl = url_DocumentWidget(document_Root(dlg->root)); iString *useUrl = NULL; diff --git a/src/ui/util.c b/src/ui/util.c index efcb8b9f..912e1d37 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -1298,6 +1298,32 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s } } +const char *selectedDropdownCommand_LabelWidget(const iLabelWidget *dropButton) { + if (!dropButton) { + return ""; + } + iWidget *menu = findChild_Widget(constAs_Widget(dropButton), "menu"); + if (flags_Widget(menu) & nativeMenu_WidgetFlag) { + iConstForEach(Array, i, userData_Object(menu)) { + const iMenuItem *item = i.value; + if (item->label && startsWithCase_CStr(item->label, "###")) { + return item->command ? item->command : ""; + } + } + } + else { + iForEach(ObjectList, i, children_Widget(menu)) { + if (isInstance_Object(i.object, &Class_LabelWidget)) { + iLabelWidget *item = i.object; + if (flags_Widget(i.object) & selected_WidgetFlag) { + return cstr_String(command_LabelWidget(item)); + } + } + } + } + return ""; +} + /*-----------------------------------------------------------------------------------------------*/ static iBool isTabPage_Widget_(const iWidget *tabs, const iWidget *page) { diff --git a/src/ui/util.h b/src/ui/util.h index 81fb1cbd..d13d751b 100644 --- a/src/ui/util.h +++ b/src/ui/util.h @@ -261,6 +261,7 @@ int checkContextMenu_Widget (iWidget *, const SDL_Event *ev) iLabelWidget * makeMenuButton_LabelWidget (const char *label, const iMenuItem *items, size_t n); void updateDropdownSelection_LabelWidget (iLabelWidget *dropButton, const char *selectedCommand); +const char * selectedDropdownCommand_LabelWidget (const iLabelWidget *dropButton); /*-----------------------------------------------------------------------------------------------*/ -- cgit v1.2.3