mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 10:58:31 -05:00
More cleanup and UI work
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,13 +48,13 @@ namespace FeedCenter.Options
|
||||
|
||||
var category = (Category) CategoryListBox.SelectedItem;
|
||||
|
||||
feed.Category = category;
|
||||
feed.CategoryId = category.Id;
|
||||
|
||||
var feedWindow = new FeedWindow();
|
||||
|
||||
var result = feedWindow.Display(feed, Window.GetWindow(this));
|
||||
|
||||
if (!result.HasValue || !result.Value)
|
||||
if (!result.HasValue || !result.Value)
|
||||
return;
|
||||
|
||||
Database.Entities.Feeds.Add(feed);
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user