From d58ecc5cb293a7e5248beae95727d1301d1c907b Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 30 Nov 2021 15:34:38 +0200 Subject: SidebarWidget: Crash when switching Feeds mode Updating items immediately destroys the action widgets. # Conflicts: # src/ui/sidebarwidget.c --- src/ui/sidebarwidget.c | 23 ++++++++++++++++++----- src/ui/util.c | 7 +++++++ src/ui/widget.c | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 3d663afd..2219eba9 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -264,10 +264,12 @@ static iBool isBookmarkFolded_SidebarWidget_(const iSidebarWidget *d, const iBoo return iFalse; } -static void updateItems_SidebarWidget_(iSidebarWidget *d) { +static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepActions) { clear_ListWidget(d->list); releaseChildren_Widget(d->blank); + if (!keepActions) { releaseChildren_Widget(d->actions); + } d->actions->rect.size.y = 0; destroy_Widget(d->menu); destroy_Widget(d->modeMenu); @@ -348,7 +350,8 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { break; } } - /* Actions. */ { + /* Actions. */ + if (!keepActions) { addActionButton_SidebarWidget_( d, check_Icon " ${sidebar.action.feeds.markallread}", "feeds.markallread", expand_WidgetFlag | tight_WidgetFlag); @@ -362,6 +365,8 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { iWidget *dropButton = addChild_Widget( d->actions, iClob(makeMenuButton_LabelWidget(items[d->feedsMode].label, items, 2))); + setId_Widget(dropButton, "feeds.modebutton"); + checkIcon_LabelWidget((iLabelWidget *) dropButton); setFixedSize_Widget( dropButton, init_I2(iMaxi(20 * gap_UI, measure_Text( @@ -371,6 +376,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { 6 * gap_UI), -1)); } + else { + updateDropdownSelection_LabelWidget(findChild_Widget(d->actions, "feeds.modebutton"), + format_CStr(" arg:%d", d->feedsMode)); + } d->menu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ { openTab_Icon " ${feeds.entry.newtab}", 0, 0, "feed.entry.opentab" }, @@ -653,6 +662,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { updateMouseHover_ListWidget(d->list); } +static void updateItems_SidebarWidget_(iSidebarWidget *d) { + updateItemsWithFlags_SidebarWidget_(d, iFalse); +} + static size_t findItem_SidebarWidget_(const iSidebarWidget *d, int id) { /* Note that this is O(n), so only meant for infrequent use. */ for (size_t i = 0; i < numItems_ListWidget(d->list); i++) { @@ -1315,9 +1328,9 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) } return iTrue; } - else if (isCommand_Widget(w, ev, "menu.closed")) { +// else if (isCommand_Widget(w, ev, "menu.closed")) { // invalidateItem_ListWidget(d->list, d->contextIndex); - } +// } else if (isCommand_Widget(w, ev, "bookmark.open")) { const iSidebarItem *item = d->contextItem; if (d->mode == bookmarks_SidebarMode && item) { @@ -1474,7 +1487,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) } else if (equalWidget_Command(cmd, w, "feeds.mode")) { d->feedsMode = arg_Command(cmd); - updateItems_SidebarWidget_(d); + updateItemsWithFlags_SidebarWidget_(d, iTrue); return iTrue; } else if (equal_Command(cmd, "feeds.markallread") && d->mode == feeds_SidebarMode) { diff --git a/src/ui/util.c b/src/ui/util.c index 84de4b74..fe5e5393 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -1269,6 +1269,9 @@ const iString *removeMenuItemLabelPrefixes_String(const iString *d) { } void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *selectedCommand) { + if (!dropButton) { + return; + } iWidget *menu = findChild_Widget(as_Widget(dropButton), "menu"); if (flags_Widget(menu) & nativeMenu_WidgetFlag) { unselectAllNativeMenuItems_Widget(menu); @@ -1277,6 +1280,7 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s setSelected_NativeMenuItem(item, iTrue); updateText_LabelWidget( dropButton, removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label))); + checkIcon_LabelWidget(dropButton); } return; } @@ -1287,6 +1291,7 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s setFlags_Widget(as_Widget(item), selected_WidgetFlag, isSelected); if (isSelected) { updateText_LabelWidget(dropButton, sourceText_LabelWidget(item)); + checkIcon_LabelWidget(dropButton); } } } @@ -2352,6 +2357,7 @@ iWidget *makePreferences_Widget(void) { { "radio device:1 id:prefs.pinsplit", 0, 0, (const void *) pinSplitItems }, { "padding" }, { "dropdown id:prefs.uilang", 0, 0, (const void *) langItems }, + { "toggle id:prefs.time.24h" }, { NULL } }; const iMenuItem uiPanelItems[] = { @@ -2436,6 +2442,7 @@ iWidget *makePreferences_Widget(void) { const iMenuItem aboutPanelItems[] = { { format_CStr("heading text:%s", cstr_String(aboutText)) }, { "button text:" clock_Icon " ${menu.releasenotes}", 0, 0, "!open url:about:version" }, + { "padding" }, { "button text:" globe_Icon " ${menu.website}", 0, 0, "!open url:https://gmi.skyjake.fi/lagrange" }, { "button text:" envelope_Icon " @jk@skyjake.fi", 0, 0, "!open url:https://skyjake.fi/@jk" }, { "padding" }, diff --git a/src/ui/widget.c b/src/ui/widget.c index a171a6cd..cedda461 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -1528,7 +1528,7 @@ static void addToPotentiallyVisible_Widget_(const iWidget *d, iPtrArray *pvs, iR } if (isFullyContainedByOther_Rect(bounds, *fullyMasked)) { return; /* can't be seen */ - } + } pushBack_PtrArray(pvs, d); if (d->bgColor >= 0 && ~d->flags & noBackground_WidgetFlag && isFullyContainedByOther_Rect(*fullyMasked, bounds)) { -- cgit v1.2.3