private void OnAddCategory(object sender, ExecutedRoutedEventArgs e) { if (this.IsEditing) { return; } string name = this.Selected != null?Category.Combine(this.Selected.Name, "New Category") : "New Category"; CategoryDialog dialog = CategoryDialog.ShowDialogCategory(this.MyMoney, name); dialog.Owner = App.Current.MainWindow; dialog.Title = "Add Category"; dialog.Message = this.Selected != null ? "Please edit your new sub-category name or edit the whole string to add a new top level category" : "Please edit your new category name"; dialog.Select("New Category"); if (dialog.ShowDialog() == false) { return; } treeView.Items.Refresh(); this.Dispatcher.BeginInvoke(new Action(() => { // Now select the new subcategory and enter Rename mode this.Selected = dialog.Category; }), DispatcherPriority.ContextIdle); }
static public void ShowDetails(MyMoney money, Category c) { if (c != null) { CategoryDialog dialog = CategoryDialog.ShowDialogCategory(money, c.Name); dialog.Owner = App.Current.MainWindow; if (dialog.ShowDialog() == false) { // User clicked cancel return; } // todo: a bit ambiguous here what to do if they renamed the category... // for example, do we move all subcategories with it? } }
public void Delete() { if (this.IsEditing) { return; // ignore del key when editing. } Category c = this.Selected; if (c != null) { IList <Transaction> data = this.MyMoney.Transactions.GetTransactionsByCategory(c, null); Category nc = null; if (data.Count > 0) { CategoryDialog dialog = CategoryDialog.ShowDialogCategory(this.MyMoney, c.Name); dialog.Owner = App.Current.MainWindow; dialog.Title = "Delete Category"; dialog.Message = "Please select a new category for the transactions that are still using the category '" + c.Name + "'"; if (dialog.ShowDialog() == false) { return; } // the onmoneychanged event should have fired, and the list is now updated. nc = dialog.Category; Account account = dialog.Transfer; foreach (Transaction t in data) { if (t.Category == c) { if (account != null) { this.MyMoney.Transfer(t, account); this.MyMoney.Rebalance(account); } else { t.Category = nc; } } else if (t.IsSplit) { foreach (Split s in t.Splits.Items) { if (s.Category == c) { if (account != null) { this.MyMoney.Transfer(s, account); } else { s.Category = nc; } } } } } } Category category = this.Selected; category.OnDelete(); } }