summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-11-30 15:34:38 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-11-30 15:36:58 +0200
commitd58ecc5cb293a7e5248beae95727d1301d1c907b (patch)
treeb1bba3c4902bc0b583fd60a04241a97f57cf63d9 /src
parent02de94c9d94e70d2c8d5e4813c578111eba0d2b2 (diff)
SidebarWidget: Crash when switching Feeds mode
Updating items immediately destroys the action widgets. # Conflicts: # src/ui/sidebarwidget.c
Diffstat (limited to 'src')
-rw-r--r--src/ui/sidebarwidget.c23
-rw-r--r--src/ui/util.c7
-rw-r--r--src/ui/widget.c2
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
264 return iFalse; 264 return iFalse;
265} 265}
266 266
267static void updateItems_SidebarWidget_(iSidebarWidget *d) { 267static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepActions) {
268 clear_ListWidget(d->list); 268 clear_ListWidget(d->list);
269 releaseChildren_Widget(d->blank); 269 releaseChildren_Widget(d->blank);
270 if (!keepActions) {
270 releaseChildren_Widget(d->actions); 271 releaseChildren_Widget(d->actions);
272 }
271 d->actions->rect.size.y = 0; 273 d->actions->rect.size.y = 0;
272 destroy_Widget(d->menu); 274 destroy_Widget(d->menu);
273 destroy_Widget(d->modeMenu); 275 destroy_Widget(d->modeMenu);
@@ -348,7 +350,8 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
348 break; 350 break;
349 } 351 }
350 } 352 }
351 /* Actions. */ { 353 /* Actions. */
354 if (!keepActions) {
352 addActionButton_SidebarWidget_( 355 addActionButton_SidebarWidget_(
353 d, check_Icon " ${sidebar.action.feeds.markallread}", "feeds.markallread", expand_WidgetFlag | 356 d, check_Icon " ${sidebar.action.feeds.markallread}", "feeds.markallread", expand_WidgetFlag |
354 tight_WidgetFlag); 357 tight_WidgetFlag);
@@ -362,6 +365,8 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
362 iWidget *dropButton = addChild_Widget( 365 iWidget *dropButton = addChild_Widget(
363 d->actions, 366 d->actions,
364 iClob(makeMenuButton_LabelWidget(items[d->feedsMode].label, items, 2))); 367 iClob(makeMenuButton_LabelWidget(items[d->feedsMode].label, items, 2)));
368 setId_Widget(dropButton, "feeds.modebutton");
369 checkIcon_LabelWidget((iLabelWidget *) dropButton);
365 setFixedSize_Widget( 370 setFixedSize_Widget(
366 dropButton, 371 dropButton,
367 init_I2(iMaxi(20 * gap_UI, measure_Text( 372 init_I2(iMaxi(20 * gap_UI, measure_Text(
@@ -371,6 +376,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
371 6 * gap_UI), 376 6 * gap_UI),
372 -1)); 377 -1));
373 } 378 }
379 else {
380 updateDropdownSelection_LabelWidget(findChild_Widget(d->actions, "feeds.modebutton"),
381 format_CStr(" arg:%d", d->feedsMode));
382 }
374 d->menu = makeMenu_Widget( 383 d->menu = makeMenu_Widget(
375 as_Widget(d), 384 as_Widget(d),
376 (iMenuItem[]){ { openTab_Icon " ${feeds.entry.newtab}", 0, 0, "feed.entry.opentab" }, 385 (iMenuItem[]){ { openTab_Icon " ${feeds.entry.newtab}", 0, 0, "feed.entry.opentab" },
@@ -653,6 +662,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
653 updateMouseHover_ListWidget(d->list); 662 updateMouseHover_ListWidget(d->list);
654} 663}
655 664
665static void updateItems_SidebarWidget_(iSidebarWidget *d) {
666 updateItemsWithFlags_SidebarWidget_(d, iFalse);
667}
668
656static size_t findItem_SidebarWidget_(const iSidebarWidget *d, int id) { 669static size_t findItem_SidebarWidget_(const iSidebarWidget *d, int id) {
657 /* Note that this is O(n), so only meant for infrequent use. */ 670 /* Note that this is O(n), so only meant for infrequent use. */
658 for (size_t i = 0; i < numItems_ListWidget(d->list); i++) { 671 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)
1315 } 1328 }
1316 return iTrue; 1329 return iTrue;
1317 } 1330 }
1318 else if (isCommand_Widget(w, ev, "menu.closed")) { 1331// else if (isCommand_Widget(w, ev, "menu.closed")) {
1319 // invalidateItem_ListWidget(d->list, d->contextIndex); 1332 // invalidateItem_ListWidget(d->list, d->contextIndex);
1320 } 1333// }
1321 else if (isCommand_Widget(w, ev, "bookmark.open")) { 1334 else if (isCommand_Widget(w, ev, "bookmark.open")) {
1322 const iSidebarItem *item = d->contextItem; 1335 const iSidebarItem *item = d->contextItem;
1323 if (d->mode == bookmarks_SidebarMode && item) { 1336 if (d->mode == bookmarks_SidebarMode && item) {
@@ -1474,7 +1487,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1474 } 1487 }
1475 else if (equalWidget_Command(cmd, w, "feeds.mode")) { 1488 else if (equalWidget_Command(cmd, w, "feeds.mode")) {
1476 d->feedsMode = arg_Command(cmd); 1489 d->feedsMode = arg_Command(cmd);
1477 updateItems_SidebarWidget_(d); 1490 updateItemsWithFlags_SidebarWidget_(d, iTrue);
1478 return iTrue; 1491 return iTrue;
1479 } 1492 }
1480 else if (equal_Command(cmd, "feeds.markallread") && d->mode == feeds_SidebarMode) { 1493 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) {
1269} 1269}
1270 1270
1271void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *selectedCommand) { 1271void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *selectedCommand) {
1272 if (!dropButton) {
1273 return;
1274 }
1272 iWidget *menu = findChild_Widget(as_Widget(dropButton), "menu"); 1275 iWidget *menu = findChild_Widget(as_Widget(dropButton), "menu");
1273 if (flags_Widget(menu) & nativeMenu_WidgetFlag) { 1276 if (flags_Widget(menu) & nativeMenu_WidgetFlag) {
1274 unselectAllNativeMenuItems_Widget(menu); 1277 unselectAllNativeMenuItems_Widget(menu);
@@ -1277,6 +1280,7 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s
1277 setSelected_NativeMenuItem(item, iTrue); 1280 setSelected_NativeMenuItem(item, iTrue);
1278 updateText_LabelWidget( 1281 updateText_LabelWidget(
1279 dropButton, removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label))); 1282 dropButton, removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label)));
1283 checkIcon_LabelWidget(dropButton);
1280 } 1284 }
1281 return; 1285 return;
1282 } 1286 }
@@ -1287,6 +1291,7 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s
1287 setFlags_Widget(as_Widget(item), selected_WidgetFlag, isSelected); 1291 setFlags_Widget(as_Widget(item), selected_WidgetFlag, isSelected);
1288 if (isSelected) { 1292 if (isSelected) {
1289 updateText_LabelWidget(dropButton, sourceText_LabelWidget(item)); 1293 updateText_LabelWidget(dropButton, sourceText_LabelWidget(item));
1294 checkIcon_LabelWidget(dropButton);
1290 } 1295 }
1291 } 1296 }
1292 } 1297 }
@@ -2352,6 +2357,7 @@ iWidget *makePreferences_Widget(void) {
2352 { "radio device:1 id:prefs.pinsplit", 0, 0, (const void *) pinSplitItems }, 2357 { "radio device:1 id:prefs.pinsplit", 0, 0, (const void *) pinSplitItems },
2353 { "padding" }, 2358 { "padding" },
2354 { "dropdown id:prefs.uilang", 0, 0, (const void *) langItems }, 2359 { "dropdown id:prefs.uilang", 0, 0, (const void *) langItems },
2360 { "toggle id:prefs.time.24h" },
2355 { NULL } 2361 { NULL }
2356 }; 2362 };
2357 const iMenuItem uiPanelItems[] = { 2363 const iMenuItem uiPanelItems[] = {
@@ -2436,6 +2442,7 @@ iWidget *makePreferences_Widget(void) {
2436 const iMenuItem aboutPanelItems[] = { 2442 const iMenuItem aboutPanelItems[] = {
2437 { format_CStr("heading text:%s", cstr_String(aboutText)) }, 2443 { format_CStr("heading text:%s", cstr_String(aboutText)) },
2438 { "button text:" clock_Icon " ${menu.releasenotes}", 0, 0, "!open url:about:version" }, 2444 { "button text:" clock_Icon " ${menu.releasenotes}", 0, 0, "!open url:about:version" },
2445 { "padding" },
2439 { "button text:" globe_Icon " ${menu.website}", 0, 0, "!open url:https://gmi.skyjake.fi/lagrange" }, 2446 { "button text:" globe_Icon " ${menu.website}", 0, 0, "!open url:https://gmi.skyjake.fi/lagrange" },
2440 { "button text:" envelope_Icon " @jk@skyjake.fi", 0, 0, "!open url:https://skyjake.fi/@jk" }, 2447 { "button text:" envelope_Icon " @jk@skyjake.fi", 0, 0, "!open url:https://skyjake.fi/@jk" },
2441 { "padding" }, 2448 { "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
1528 } 1528 }
1529 if (isFullyContainedByOther_Rect(bounds, *fullyMasked)) { 1529 if (isFullyContainedByOther_Rect(bounds, *fullyMasked)) {
1530 return; /* can't be seen */ 1530 return; /* can't be seen */
1531 } 1531 }
1532 pushBack_PtrArray(pvs, d); 1532 pushBack_PtrArray(pvs, d);
1533 if (d->bgColor >= 0 && ~d->flags & noBackground_WidgetFlag && 1533 if (d->bgColor >= 0 && ~d->flags & noBackground_WidgetFlag &&
1534 isFullyContainedByOther_Rect(*fullyMasked, bounds)) { 1534 isFullyContainedByOther_Rect(*fullyMasked, bounds)) {