From 43095e36cbe8df781eea019e219fcff8b68bea50 Mon Sep 17 00:00:00 2001 From: Humdinger Date: Sat, 29 Jun 2024 06:47:23 +0200 Subject: [PATCH] Fix split category update * Before there was a CategoryButton that would insert a category in the CategoryBox, there was only the CategoryBox' AutoTextControl() that did autocomplete and informed the SplitView that the category was edited. The CategoryButton simply inserting the new category in the text control isn't enough. It has to notify the SplitView of that, so it can update a changed category in the the list of split transactions at the bottom of the window. After introducing GetMessenger() to the AutoTextControlFilter we can now send a M_SPLIT_CATEGORY_CHANGED to the CategoryBox's parent, i.e. the SplitView. * Split transactions get the category "Split transaction" by the app. Ignore those when checking against existing user-created categories. It won't be found there and would get added as new user-created category. --- src/AutoTextControl.cpp | 6 ++++++ src/AutoTextControl.h | 1 + src/CategoryBox.cpp | 3 ++- src/CategoryButton.cpp | 8 +++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/AutoTextControl.cpp b/src/AutoTextControl.cpp index c98da4c..d03d4c4 100644 --- a/src/AutoTextControl.cpp +++ b/src/AutoTextControl.cpp @@ -199,3 +199,9 @@ AutoTextControlFilter::SetMessenger(BMessenger* msgr) delete fMessenger; fMessenger = msgr; } + +BMessenger* +AutoTextControlFilter::GetMessenger() +{ + return fMessenger; +} \ No newline at end of file diff --git a/src/AutoTextControl.h b/src/AutoTextControl.h index 4991d3a..f573a24 100644 --- a/src/AutoTextControl.h +++ b/src/AutoTextControl.h @@ -74,6 +74,7 @@ class AutoTextControlFilter : public BMessageFilter { void SendMessage(BMessage* msg); void SetMessenger(BMessenger* msgr); + BMessenger* GetMessenger(); private: AutoTextControl* fBox; diff --git a/src/CategoryBox.cpp b/src/CategoryBox.cpp index cc82e07..bbbbdf1 100644 --- a/src/CategoryBox.cpp +++ b/src/CategoryBox.cpp @@ -140,7 +140,8 @@ CategoryBox::SetTypeFromCategory(BString category) } bool success = true; - if (!categoryExists) + if (!categoryExists + && category.ICompare(B_TRANSLATE_CONTEXT("Split transaction", "CommonTerms")) != 0) bool success = AddNewCategory(category); return success; diff --git a/src/CategoryButton.cpp b/src/CategoryButton.cpp index 8b0eee4..63dd662 100644 --- a/src/CategoryButton.cpp +++ b/src/CategoryButton.cpp @@ -1,6 +1,7 @@ #include "CategoryButton.h" #include "Database.h" #include "MainWindow.h" +#include "SplitView.h" #include #include @@ -58,8 +59,13 @@ CategoryButton::MessageReceived(BMessage* msg) BString category; msg->FindString("category", &category); fCategoryBox->SetText(category); - fCategoryBox->Validate(); + bool success = fCategoryBox->Validate(); + if (success) { + BMessenger* msgr(fCategoryBox->GetFilter()->GetMessenger()); + BMessage notice(M_SPLIT_CATEGORY_CHANGED); + msgr->SendMessage(¬ice); + } break; } default: