Skip to content

Commit

Permalink
Fix split category update
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
humdingerb committed Jun 30, 2024
1 parent 897e22d commit 43095e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/AutoTextControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,9 @@ AutoTextControlFilter::SetMessenger(BMessenger* msgr)
delete fMessenger;
fMessenger = msgr;
}

BMessenger*
AutoTextControlFilter::GetMessenger()
{
return fMessenger;
}
1 change: 1 addition & 0 deletions src/AutoTextControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class AutoTextControlFilter : public BMessageFilter {

void SendMessage(BMessage* msg);
void SetMessenger(BMessenger* msgr);
BMessenger* GetMessenger();

private:
AutoTextControl* fBox;
Expand Down
3 changes: 2 additions & 1 deletion src/CategoryBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/CategoryButton.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "CategoryButton.h"
#include "Database.h"
#include "MainWindow.h"
#include "SplitView.h"

#include <Bitmap.h>
#include <Catalog.h>
Expand Down Expand Up @@ -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(&notice);
}
break;
}
default:
Expand Down

0 comments on commit 43095e3

Please sign in to comment.