Skip to content

Commit

Permalink
fix(moneymanagerex#4789): checkbox for including sub categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Whalley committed Jul 6, 2022
1 parent ce32dc8 commit 9abac30
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
38 changes: 32 additions & 6 deletions src/filtertransdialog.cpp
Expand Up @@ -282,6 +282,11 @@ void mmFilterTransactionsDialog::mmDoDataToControls(const wxString& json)
categoryComboBox_->Enable(categoryCheckBox_->IsChecked());
categoryComboBox_->SetLabelText(s_category);

// Sub Category inclusion
Value& j_categorySubCat = GetValueByPointerWithDefault(j_doc, "/SUBCATEGORYINCLUDE", "");
bool subCatCheck = j_categorySubCat.IsBool() ? j_categorySubCat.GetBool() : false;
categorySubCatCheckBox_->SetValue(subCatCheck);

//Status
Value& j_status = GetValueByPointerWithDefault(j_doc, "/STATUS", "");
const wxString& s_status = j_status.IsString() ? wxString::FromUTF8(j_status.GetString()) : "";
Expand Down Expand Up @@ -532,16 +537,19 @@ void mmFilterTransactionsDialog::mmDoCreateControls()
// Category
categoryCheckBox_ = new wxCheckBox(itemPanel, wxID_ANY, _("Category")
, wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);

wxFlexGridSizer* categSizer = new wxFlexGridSizer(0, 1, 0, 0);
categSizer->AddGrowableCol(0, 1);

itemPanelSizer->Add(categoryCheckBox_, g_flagsH);
itemPanelSizer->Add(categSizer, wxSizerFlags(g_flagsExpand).Border(0));

categoryComboBox_ = new mmComboBoxCategory(itemPanel, wxID_ANY);
categSizer->Add(categoryComboBox_, g_flagsExpand);
categoryComboBox_->Bind(wxEVT_COMBOBOX, &mmFilterTransactionsDialog::OnCategoryChange, this);
categoryComboBox_->Bind(wxEVT_KILL_FOCUS, &mmFilterTransactionsDialog::OnCategoryChange, this);
itemPanelSizer->Add(categoryComboBox_, g_flagsExpand);

// Category sub-category checkbox
categorySubCatCheckBox_ = new wxCheckBox(itemPanel, wxID_ANY, _("Include all sub-categories")
, wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);

itemPanelSizer->AddSpacer(1);
itemPanelSizer->Add(categorySubCatCheckBox_, g_flagsExpand);

// Status
statusCheckBox_ = new wxCheckBox(itemPanel, wxID_ANY, _("Status")
Expand Down Expand Up @@ -815,6 +823,8 @@ void mmFilterTransactionsDialog::OnCheckboxClick(wxCommandEvent& event)

cbPayee_->Enable(payeeCheckBox_->IsChecked());
categoryComboBox_->Enable(categoryCheckBox_->IsChecked());
categorySubCatCheckBox_->Enable(categoryCheckBox_->IsChecked()
&& (categoryComboBox_->mmGetCategoryId() != -1) && (categoryComboBox_->mmGetSubcategoryId() == -1));
choiceStatus_->Enable(statusCheckBox_->IsChecked());
cbTypeWithdrawal_->Enable(typeCheckBox_->IsChecked());
cbTypeDeposit_->Enable(typeCheckBox_->IsChecked());
Expand Down Expand Up @@ -1201,6 +1211,7 @@ bool mmFilterTransactionsDialog::mmIsCategoryMatches(const DATA& tran, const std
auto value = categoryComboBox_->mmGetPattern();

if (!value.empty()) {
if (mmIsCategorySubCatChecked()) value = value + ".*";
for (const auto& item : trx_categories)
{
wxRegEx pattern("^(" + value + ")$", wxRE_ICASE | wxRE_ADVANCED);
Expand Down Expand Up @@ -1460,6 +1471,14 @@ const wxString mmFilterTransactionsDialog::mmGetJsonSetings(bool i18n) const
}
}

// Sub Category inclusion
if (categoryCheckBox_->IsChecked()
&& (categoryComboBox_->mmGetCategoryId() != -1) && (categoryComboBox_->mmGetSubcategoryId() == -1))
{
json_writer.Key((i18n ? _("SubCategoryInclude") : "SUBCATEGORYINCLUDE").utf8_str());
json_writer.Bool(categoryCheckBox_->GetValue());
}

//Status
if (statusCheckBox_->IsChecked())
{
Expand Down Expand Up @@ -1576,6 +1595,13 @@ const wxString mmFilterTransactionsDialog::mmGetJsonSetings(bool i18n) const
return wxString::FromUTF8(json_buffer.GetString());
}

void mmFilterTransactionsDialog::OnCategoryChange(wxEvent& event)
{
categorySubCatCheckBox_->Enable(categoryCheckBox_->IsChecked()
&& (categoryComboBox_->mmGetCategoryId() != -1) && (categoryComboBox_->mmGetSubcategoryId() == -1));
event.Skip();
}

void mmFilterTransactionsDialog::OnDateChanged(wxDateEvent& event)
{
switch (event.GetId())
Expand Down
5 changes: 4 additions & 1 deletion src/filtertransdialog.h
Expand Up @@ -60,6 +60,7 @@ class mmFilterTransactionsDialog: public wxDialog
bool mmIsStatusChecked() const;
bool mmIsAccountChecked() const;
bool mmIsCategoryChecked() const;
bool mmIsCategorySubCatChecked() const;
bool mmIsRangeChecked() const;
bool mmIsDateRangeChecked() const;
bool mmIsHideColumnsChecked() const;
Expand Down Expand Up @@ -136,7 +137,7 @@ class mmFilterTransactionsDialog: public wxDialog

/// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_CHECKBOXACCOUNT
void OnCheckboxClick( wxCommandEvent& event );

void OnCategoryChange(wxEvent& event);
void OnButtonOkClick(wxCommandEvent& event);
void OnButtonCancelClick(wxCommandEvent& event);
void OnButtonClearClick(wxCommandEvent& event);
Expand Down Expand Up @@ -164,6 +165,7 @@ class mmFilterTransactionsDialog: public wxDialog
mmComboBoxPayee* cbPayee_;
wxCheckBox* categoryCheckBox_;
mmComboBoxCategory* categoryComboBox_;
wxCheckBox* categorySubCatCheckBox_;
wxCheckBox* statusCheckBox_;
private:
wxChoice* choiceStatus_;
Expand Down Expand Up @@ -237,6 +239,7 @@ inline bool mmFilterTransactionsDialog::mmIsNumberChecked() const { return trans
inline bool mmFilterTransactionsDialog::mmIsNotesChecked() const { return notesCheckBox_->IsChecked(); }
inline bool mmFilterTransactionsDialog::mmIsColorChecked() const { return colorCheckBox_->IsChecked(); }
inline bool mmFilterTransactionsDialog::mmIsCategoryChecked() const { return categoryCheckBox_->IsChecked(); }
inline bool mmFilterTransactionsDialog::mmIsCategorySubCatChecked() const { return categorySubCatCheckBox_->IsChecked(); }
inline bool mmFilterTransactionsDialog::mmIsStatusChecked() const { return statusCheckBox_->IsChecked(); }
inline const wxString mmFilterTransactionsDialog::mmGetLabelString() const { return m_setting_name->GetStringSelection(); }
inline const wxString mmFilterTransactionsDialog::mmGetCategoryPattern() const { return categoryComboBox_->GetValue(); }
Expand Down

0 comments on commit 9abac30

Please sign in to comment.