From 15c9c0f7b7b31c9af9579baa056f7cadb9708e0e Mon Sep 17 00:00:00 2001 From: Humdinger Date: Mon, 8 Jul 2024 09:02:29 +0200 Subject: [PATCH] Fix CategoryButton not showing menu or Categories window sometimes * Initialize fShowingPopUpMenu variable fixes the menu sometimes not showing. * "Edit categories..." only worked when the CategoryButton was a child of the MainWindow, because it SetTarget to its window. Now we just SetTarget to the button itself and have it create the "Categories" window. --- src/CategoryButton.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/CategoryButton.cpp b/src/CategoryButton.cpp index 63dd662..65cfb8b 100644 --- a/src/CategoryButton.cpp +++ b/src/CategoryButton.cpp @@ -1,6 +1,6 @@ #include "CategoryButton.h" #include "Database.h" -#include "MainWindow.h" +#include "CategoryWindow.h" #include "SplitView.h" #include @@ -10,19 +10,21 @@ #undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "MainWindow" +#define B_TRANSLATION_CONTEXT "CategoryButton" enum { M_SHOW_POPUP, M_CLOSE_POPUP, - M_CATEGORY_CHOSEN + M_CATEGORY_CHOSEN, + M_OPEN_CATEGORY_WINDOW, }; CategoryButton::CategoryButton(CategoryBox* categorybox) : BButton("calenderbutton", "", new BMessage(M_SHOW_POPUP)), - fCategoryBox(categorybox) + fCategoryBox(categorybox), + fShowingPopUpMenu(false) { float height; fCategoryBox->GetPreferredSize(NULL, &height); @@ -68,6 +70,13 @@ CategoryButton::MessageReceived(BMessage* msg) } break; } + case M_OPEN_CATEGORY_WINDOW: + { + CategoryWindow* catwin = new CategoryWindow(BRect(100, 100, 600, 425)); + catwin->CenterIn(Frame()); + catwin->Show(); + break; + } default: { BButton::MessageReceived(msg); @@ -130,7 +139,7 @@ CategoryButton::ShowPopUpMenu() BMenu* incomeMenu = new BMenu(B_TRANSLATE_CONTEXT("Income", "CommonTerms")); BMenu* spendingMenu = new BMenu(B_TRANSLATE_CONTEXT("Spending", "CommonTerms")); BMenuItem* editCategories = new BMenuItem( - B_TRANSLATE("Edit categories" B_UTF8_ELLIPSIS), new BMessage(M_SHOW_CATEGORY_WINDOW)); + B_TRANSLATE("Edit categories" B_UTF8_ELLIPSIS), new BMessage(M_OPEN_CATEGORY_WINDOW)); CppSQLite3Query query = gDatabase.DBQuery( "SELECT * FROM categorylist ORDER BY name ASC", "CategoryView::CategoryView"); @@ -156,7 +165,7 @@ CategoryButton::ShowPopUpMenu() incomeMenu->SetTargetForItems(this); spendingMenu->SetTargetForItems(this); - editCategories->SetTarget(Window()); + editCategories->SetTarget(this); BPoint where = Bounds().LeftTop(); where.x += 10;