Disallow edit and delete of default category

This commit is contained in:
2016-05-31 14:19:38 -04:00
parent f7491dbbc5
commit c7dd9ccaa5

View File

@@ -290,8 +290,8 @@ namespace FeedCenter.Options
private void SetCategoryButtonStates()
{
AddCategoryButton.IsEnabled = true;
EditCategoryButton.IsEnabled = (CategoryListBox.SelectedItem != null);
DeleteCategoryButton.IsEnabled = (CategoryListBox.SelectedItem != null);
EditCategoryButton.IsEnabled = (CategoryListBox.SelectedItem != null && CategoryListBox.SelectedItem != Database.DefaultCategory);
DeleteCategoryButton.IsEnabled = (CategoryListBox.SelectedItem != null && CategoryListBox.SelectedItem != Database.DefaultCategory);
}
private void AddCategory()
@@ -326,8 +326,19 @@ namespace FeedCenter.Options
private void DeleteSelectedCategory()
{
var defaultCategory = Database.DefaultCategory;
var category = (Category) CategoryListBox.SelectedItem;
category.Feeds.ToList().ForEach(feed => feed.Category = defaultCategory);
var index = CategoryListBox.SelectedIndex;
if (index == CategoryListBox.Items.Count - 1)
CategoryListBox.SelectedIndex = index - 1;
else
CategoryListBox.SelectedIndex = index + 1;
Database.Categories.Remove(category);
SetCategoryButtonStates();
@@ -373,6 +384,7 @@ namespace FeedCenter.Options
FeedListBox.SelectedIndex = 0;
SetFeedButtonStates();
SetCategoryButtonStates();
}
private void HandleCollectionViewSourceFilter(object sender, FilterEventArgs e)