Skip to content

Commit

Permalink
Fix CategoryButton not showing menu or Categories window sometimes
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
humdingerb committed Jul 8, 2024
1 parent 750cf89 commit 15c9c0f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/CategoryButton.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "CategoryButton.h"
#include "Database.h"
#include "MainWindow.h"
#include "CategoryWindow.h"
#include "SplitView.h"

#include <Bitmap.h>
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit 15c9c0f

Please sign in to comment.