More cleanup and UI work

This commit is contained in:
2023-04-12 13:44:15 -04:00
parent a81cf5e69f
commit 242663c3e5
19 changed files with 146 additions and 80 deletions

View File

@@ -193,7 +193,7 @@ public static class LegacyDatabase
foreach (var feed in feeds)
{
feed.Category = categories.FirstOrDefault(c => c.Id == feed.CategoryId);
feed.CategoryId = categories.First(c => c.Id == feed.CategoryId).Id;
}
foreach (var feedItem in feedItems)

View File

@@ -43,7 +43,7 @@ namespace FeedCenter
{
var feed = (Feed) e.Item;
e.Accepted = (feed.LastReadResult != FeedReadResult.Success);
e.Accepted = feed.LastReadResult != FeedReadResult.Success;
}
private void HandleEditFeedButtonClick(object sender, RoutedEventArgs e)
@@ -79,11 +79,11 @@ namespace FeedCenter
private void SetFeedButtonStates()
{
EditFeedButton.IsEnabled = (FeedDataGrid.SelectedItem != null);
DeleteFeedButton.IsEnabled = (FeedDataGrid.SelectedItem != null);
RefreshCurrent.IsEnabled = (FeedDataGrid.SelectedItem != null);
OpenPage.IsEnabled = (FeedDataGrid.SelectedItem != null);
OpenFeed.IsEnabled = (FeedDataGrid.SelectedItem != null);
EditFeedButton.IsEnabled = FeedDataGrid.SelectedItem != null;
DeleteFeedButton.IsEnabled = FeedDataGrid.SelectedItem != null;
RefreshCurrent.IsEnabled = FeedDataGrid.SelectedItem != null;
OpenPage.IsEnabled = FeedDataGrid.SelectedItem != null;
OpenFeed.IsEnabled = FeedDataGrid.SelectedItem != null;
}
private void HandleOpenPageButtonClick(object sender, RoutedEventArgs e)

View File

@@ -100,7 +100,7 @@ namespace FeedCenter.FeedParsers
if (childNode.Attributes != null)
{
var permaLinkNode = childNode.Attributes.GetNamedItem("isPermaLink");
permaLink = (permaLinkNode == null || permaLinkNode.Value == "true");
permaLink = permaLinkNode == null || permaLinkNode.Value == "true";
}
if (permaLink && Uri.IsWellFormedUriString(feedItem.Guid, UriKind.Absolute))

View File

@@ -93,8 +93,6 @@ namespace FeedCenter
set => MultipleOpenActionRaw = value.ToString();
}
public Category Category { get; set; }
[UsedImplicitly]
public IList<FeedItem> Items { get; }

View File

@@ -79,7 +79,7 @@ namespace FeedCenter
_currentCategory = category;
// Get the current feed list to match the category
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id);
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.CategoryId == _currentCategory.Id);
// Refresh the feed index
_feedIndex = -1;

View File

@@ -22,7 +22,7 @@ namespace FeedCenter
// Create and configure the new feed
var feed = Feed.Create();
feed.Source = feedUrl;
feed.Category = _database.DefaultCategory;
feed.CategoryId = _database.DefaultCategory.Id;
// Try to detect the feed type
var feedTypeResult = feed.DetectFeedType();

View File

@@ -53,7 +53,7 @@ namespace FeedCenter
LoadWindowSettings();
// Set the foreground color to something that can be seen
LinkTextList.Foreground = (System.Drawing.SystemColors.Desktop.GetBrightness() < 0.5)
LinkTextList.Foreground = System.Drawing.SystemColors.Desktop.GetBrightness() < 0.5
? Brushes.White
: Brushes.Black;
HeaderLabel.Foreground = LinkTextList.Foreground;
@@ -153,7 +153,7 @@ namespace FeedCenter
_feedList = _currentCategory == null
? _database.Feeds.ToList()
: _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id).ToList();
: _database.Feeds.Where(feed => feed.CategoryId == _currentCategory.Id).ToList();
UpdateToolbarButtonState();
@@ -178,9 +178,9 @@ namespace FeedCenter
_feedIndex = newIndex;
// Re-get the current feed
_currentFeed = (_feedIndex == -1
_currentFeed = _feedIndex == -1
? null
: _feedList.OrderBy(feed => feed.Name).AsEnumerable().ElementAt(_feedIndex));
: _feedList.OrderBy(feed => feed.Name).AsEnumerable().ElementAt(_feedIndex);
}
#endregion
@@ -215,7 +215,7 @@ namespace FeedCenter
// Get the current feed list to match the category
_feedList = _currentCategory == null
? _database.Feeds
: _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id);
: _database.Feeds.Where(feed => feed.CategoryId == _currentCategory.Id);
UpdateToolbarButtonState();
@@ -257,7 +257,7 @@ namespace FeedCenter
var found = false;
// Remember our starting position
var startIndex = (_feedIndex == -1 ? 0 : _feedIndex);
var startIndex = _feedIndex == -1 ? 0 : _feedIndex;
// Increment the index and adjust if we've gone around the end
_feedIndex = (_feedIndex + 1) % feedCount;
@@ -319,7 +319,7 @@ namespace FeedCenter
var found = false;
// Remember our starting position
var startIndex = (_feedIndex == -1 ? 0 : _feedIndex);
var startIndex = _feedIndex == -1 ? 0 : _feedIndex;
// Decrement the feed index
_feedIndex--;
@@ -392,7 +392,7 @@ namespace FeedCenter
}
// Set the header to the feed title
FeedLabel.Text = (_currentFeed.Name.Length > 0 ? _currentFeed.Name : _currentFeed.Title);
FeedLabel.Text = _currentFeed.Name.Length > 0 ? _currentFeed.Name : _currentFeed.Title;
FeedButton.Visibility = _feedList.Count() > 1 ? Visibility.Visible : Visibility.Hidden;
// Clear the current list

View File

@@ -161,7 +161,7 @@ namespace FeedCenter
private void HandleDeleteCurrentFeedMenuItemClick(object sender, RoutedEventArgs e)
{
// Confirm this delete since it is for real
if (MessageBox.Show(this, Properties.Resources.ConfirmDelete, string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
if (MessageBox.Show(this, Properties.Resources.ConfirmDeleteFeed, string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
return;
// Get the current feed

View File

@@ -1,15 +1,18 @@
using ChrisKaczor.ApplicationUpdate;
using System.Reflection;
using System.Reflection;
using System.Windows;
using ChrisKaczor.ApplicationUpdate;
namespace FeedCenter.Options;
public partial class AboutOptionsPanel
{
public AboutOptionsPanel()
public AboutOptionsPanel(Window parentWindow) : base(parentWindow)
{
InitializeComponent();
}
public override string CategoryName => Properties.Resources.optionCategoryAbout;
public override void LoadPanel()
{
base.LoadPanel();
@@ -21,6 +24,4 @@ public partial class AboutOptionsPanel
CompanyLabel.Text = ((AssemblyCompanyAttribute) Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0]).Company;
}
public override string CategoryName => Properties.Resources.optionCategoryAbout;
}

View File

@@ -1,16 +1,19 @@
using FeedCenter.Properties;
using System.Linq;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using FeedCenter.Properties;
namespace FeedCenter.Options;
public partial class DisplayOptionsPanel
{
public DisplayOptionsPanel()
public DisplayOptionsPanel(Window parentWindow) : base(parentWindow)
{
InitializeComponent();
}
public override string CategoryName => Properties.Resources.optionCategoryDisplay;
public override void LoadPanel()
{
base.LoadPanel();
@@ -23,8 +26,6 @@ public partial class DisplayOptionsPanel
MarkLoaded();
}
public override string CategoryName => Properties.Resources.optionCategoryDisplay;
private void LockWindowCheckBox_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (!HasLoaded) return;

View File

@@ -30,7 +30,7 @@
IsReadOnly="True"
HeadersVisibility="Column"
Background="{x:Null}"
PreviewMouseLeftButtonDown="HandleFeedListPreviewMouseLeftButtonDown">
PreviewMouseLeftButtonDown="HandleFeedListPreviewMouseLeftButtonDown" SelectionChanged="FeedListBox_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}"
Header="{x:Static properties:Resources.FeedNameColumnHeader}"
@@ -58,7 +58,7 @@
<DataGrid Name="CategoryListBox"
SelectionChanged="HandleCategoryListBoxSelectionChanged"
Grid.Row="0"
SelectionMode="Extended"
SelectionMode="Single"
Grid.Column="0"
AutoGenerateColumns="False"
GridLinesVisibility="None"

View File

@@ -1,5 +1,4 @@
using Microsoft.Win32;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
@@ -8,16 +7,21 @@ using System.Windows.Data;
using System.Windows.Input;
using System.Xml;
using FeedCenter.Data;
using Microsoft.Win32;
namespace FeedCenter.Options
{
public partial class FeedsOptionsPanel
{
public FeedsOptionsPanel()
private CollectionViewSource _collectionViewSource;
public FeedsOptionsPanel(Window parentWindow) : base(parentWindow)
{
InitializeComponent();
}
public override string CategoryName => Properties.Resources.optionCategoryFeeds;
public override void LoadPanel()
{
base.LoadPanel();
@@ -31,13 +35,11 @@ namespace FeedCenter.Options
CategoryListBox.SelectedIndex = 0;
}
public override string CategoryName => Properties.Resources.optionCategoryFeeds;
private void SetFeedButtonStates()
{
AddFeedButton.IsEnabled = true;
EditFeedButton.IsEnabled = FeedListBox.SelectedItem != null;
DeleteFeedButton.IsEnabled = FeedListBox.SelectedItem != null;
EditFeedButton.IsEnabled = FeedListBox.SelectedItems.Count == 1;
DeleteFeedButton.IsEnabled = FeedListBox.SelectedItems.Count > 0;
}
private void AddFeed()
@@ -46,7 +48,7 @@ namespace FeedCenter.Options
var category = (Category) CategoryListBox.SelectedItem;
feed.Category = category;
feed.CategoryId = category.Id;
var feedWindow = new FeedWindow();
@@ -74,11 +76,17 @@ namespace FeedCenter.Options
feedWindow.Display(feed, Window.GetWindow(this));
}
private void DeleteSelectedFeed()
private void DeleteSelectedFeeds()
{
var feed = (Feed) FeedListBox.SelectedItem;
if (MessageBox.Show(ParentWindow, Properties.Resources.ConfirmDeleteFeeds, Properties.Resources.ConfirmDeleteTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
return;
Database.Entities.Feeds.Remove(feed);
var selectedItems = new Feed[FeedListBox.SelectedItems.Count];
FeedListBox.SelectedItems.CopyTo(selectedItems, 0);
foreach (var feed in selectedItems)
Database.Entities.SaveChanges(() => Database.Entities.Feeds.Remove(feed));
SetFeedButtonStates();
}
@@ -95,7 +103,7 @@ namespace FeedCenter.Options
private void HandleDeleteFeedButtonClick(object sender, RoutedEventArgs e)
{
DeleteSelectedFeed();
DeleteSelectedFeeds();
}
private void HandleImportButtonClick(object sender, RoutedEventArgs e)
@@ -181,7 +189,7 @@ namespace FeedCenter.Options
while (xmlReader.NodeType != XmlNodeType.EndElement)
{
var feed = Feed.Create();
feed.Category = Database.Entities.Categories.First(c => c.IsDefault);
feed.CategoryId = Database.Entities.Categories.First(c => c.IsDefault).Id;
while (xmlReader.MoveToNextAttribute())
{
@@ -233,8 +241,10 @@ namespace FeedCenter.Options
var selectedId = ((Category) CategoryListBox.SelectedItem).Id;
EditCategoryButton.IsEnabled = CategoryListBox.SelectedItem != null && selectedId != Database.Entities.DefaultCategory.Id;
DeleteCategoryButton.IsEnabled = CategoryListBox.SelectedItem != null && selectedId != Database.Entities.DefaultCategory.Id;
EditCategoryButton.IsEnabled = CategoryListBox.SelectedItem != null &&
selectedId != Database.Entities.DefaultCategory.Id;
DeleteCategoryButton.IsEnabled = CategoryListBox.SelectedItem != null &&
selectedId != Database.Entities.DefaultCategory.Id;
}
private void AddCategory()
@@ -269,11 +279,15 @@ namespace FeedCenter.Options
private void DeleteSelectedCategory()
{
var defaultCategory = Database.Entities.DefaultCategory;
var category = (Category) CategoryListBox.SelectedItem;
category.Feeds?.ToList().ForEach(feed => feed.Category = defaultCategory);
if (MessageBox.Show(ParentWindow, string.Format(Properties.Resources.ConfirmDeleteCategory, category.Name), Properties.Resources.ConfirmDeleteTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
return;
var defaultCategory = Database.Entities.DefaultCategory;
foreach (var feed in Database.Entities.Feeds.Where(f => f.CategoryId == category.Id))
Database.Entities.SaveChanges(() => feed.CategoryId = defaultCategory.Id);
var index = CategoryListBox.SelectedIndex;
@@ -302,8 +316,6 @@ namespace FeedCenter.Options
DeleteSelectedCategory();
}
private CollectionViewSource _collectionViewSource;
private void HandleCategoryListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_collectionViewSource == null)
@@ -330,7 +342,7 @@ namespace FeedCenter.Options
var feed = (Feed) e.Item;
e.Accepted = feed.Category.Id == selectedCategory.Id;
e.Accepted = feed.CategoryId == selectedCategory.Id;
}
private void CategoryListBox_Drop(object sender, DragEventArgs e)
@@ -340,7 +352,7 @@ namespace FeedCenter.Options
var category = (Category) ((DataGridRow) sender).Item;
foreach (var feed in feedList!)
feed.Category = category;
Database.Entities.SaveChanges(() => feed.CategoryId = category.Id);
_collectionViewSource.View.Refresh();
@@ -404,5 +416,10 @@ namespace FeedCenter.Options
EditSelectedCategory();
}
private void FeedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetFeedButtonStates();
}
}
}

View File

@@ -1,5 +1,6 @@
using ChrisKaczor.InstalledBrowsers;
using ChrisKaczor.Wpf.Application;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@@ -7,7 +8,7 @@ namespace FeedCenter.Options;
public partial class GeneralOptionsPanel
{
public GeneralOptionsPanel()
public GeneralOptionsPanel(Window parentWindow) : base(parentWindow)
{
InitializeComponent();
}

View File

@@ -1,19 +1,27 @@
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls;
namespace FeedCenter.Options;
public class OptionsPanelBase : UserControl
{
public bool HasLoaded { get; private set; }
protected readonly Window ParentWindow;
protected OptionsPanelBase(Window parentWindow)
{
ParentWindow = parentWindow;
}
public virtual string CategoryName => null;
protected bool HasLoaded { get; private set; }
public virtual void LoadPanel()
{
}
public void MarkLoaded()
protected void MarkLoaded()
{
HasLoaded = true;
}
public virtual string CategoryName => null;
}

View File

@@ -1,5 +1,4 @@
using FeedCenter.Data;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Windows.Controls;
namespace FeedCenter.Options
@@ -21,11 +20,11 @@ namespace FeedCenter.Options
private void AddCategories()
{
_optionPanels.Add(new GeneralOptionsPanel());
_optionPanels.Add(new DisplayOptionsPanel());
_optionPanels.Add(new FeedsOptionsPanel());
_optionPanels.Add(new UpdateOptionsPanel());
_optionPanels.Add(new AboutOptionsPanel());
_optionPanels.Add(new GeneralOptionsPanel(this));
_optionPanels.Add(new DisplayOptionsPanel(this));
_optionPanels.Add(new FeedsOptionsPanel(this));
_optionPanels.Add(new UpdateOptionsPanel(this));
_optionPanels.Add(new AboutOptionsPanel(this));
}
private void LoadCategories()
@@ -61,13 +60,13 @@ namespace FeedCenter.Options
private class CategoryListItem
{
public OptionsPanelBase Panel { get; }
public CategoryListItem(OptionsPanelBase panel)
{
Panel = panel;
}
public OptionsPanelBase Panel { get; }
public override string ToString()
{
return Panel.CategoryName;

View File

@@ -1,14 +1,17 @@
using ChrisKaczor.ApplicationUpdate;
using System.Windows;
using ChrisKaczor.ApplicationUpdate;
namespace FeedCenter.Options;
public partial class UpdateOptionsPanel
{
public UpdateOptionsPanel()
public UpdateOptionsPanel(Window parentWindow) : base(parentWindow)
{
InitializeComponent();
}
public override string CategoryName => Properties.Resources.optionCategoryUpdate;
public override void LoadPanel()
{
base.LoadPanel();
@@ -18,8 +21,6 @@ public partial class UpdateOptionsPanel
MarkLoaded();
}
public override string CategoryName => Properties.Resources.optionCategoryUpdate;
private void HandleCheckVersionNowButtonClick(object sender, System.Windows.RoutedEventArgs e)
{
UpdateCheck.DisplayUpdateInformation(true);

View File

@@ -268,12 +268,41 @@ namespace FeedCenter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Are you sure you want to delete this category?
///
///All feeds currently in category &quot;{0}&quot; will be moved to the default category..
/// </summary>
public static string ConfirmDeleteCategory {
get {
return ResourceManager.GetString("ConfirmDeleteCategory", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Are you sure you want to delete this feed?.
/// </summary>
public static string ConfirmDelete {
public static string ConfirmDeleteFeed {
get {
return ResourceManager.GetString("ConfirmDelete", resourceCulture);
return ResourceManager.GetString("ConfirmDeleteFeed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Are you sure you want to delete the selected feeds?.
/// </summary>
public static string ConfirmDeleteFeeds {
get {
return ResourceManager.GetString("ConfirmDeleteFeeds", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Confirm Delete.
/// </summary>
public static string ConfirmDeleteTitle {
get {
return ResourceManager.GetString("ConfirmDeleteTitle", resourceCulture);
}
}

View File

@@ -400,7 +400,7 @@
<data name="EditMenu" xml:space="preserve">
<value>Edit...</value>
</data>
<data name="ConfirmDelete" xml:space="preserve">
<data name="ConfirmDeleteFeed" xml:space="preserve">
<value>Are you sure you want to delete this feed?</value>
</data>
<data name="optionCategoryReading" xml:space="preserve">
@@ -538,4 +538,15 @@
<data name="categoryNameLabel" xml:space="preserve">
<value>_Name:</value>
</data>
<data name="ConfirmDeleteCategory" xml:space="preserve">
<value>Are you sure you want to delete this category?
All feeds currently in category "{0}" will be moved to the default category.</value>
</data>
<data name="ConfirmDeleteTitle" xml:space="preserve">
<value>Confirm Delete</value>
</data>
<data name="ConfirmDeleteFeeds" xml:space="preserve">
<value>Are you sure you want to delete the selected feeds?</value>
</data>
</root>

View File

@@ -32,7 +32,7 @@
</application>
</compatibility>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
@@ -43,5 +43,5 @@
language="*"
/>
</dependentAssembly>
</dependency>-->
</dependency>
</asmv1:assembly>